Mercurial > lada > lada-server
changeset 787:7033810468d9
Validate status objects.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Wed, 18 Nov 2015 15:37:32 +0100 |
parents | 9a2dcb355d89 |
children | 7133f6114920 |
files | src/main/java/de/intevation/lada/rest/StatusService.java |
diffstat | 1 files changed, 41 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/rest/StatusService.java Wed Nov 18 15:32:24 2015 +0100 +++ b/src/main/java/de/intevation/lada/rest/StatusService.java Wed Nov 18 15:37:32 2015 +0100 @@ -7,6 +7,8 @@ */ package de.intevation.lada.rest; +import java.util.List; + import javax.enterprise.context.RequestScoped; import javax.inject.Inject; import javax.servlet.http.HttpServletRequest; @@ -23,6 +25,8 @@ import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.UriInfo; +import org.apache.log4j.Logger; + import de.intevation.lada.lock.LockConfig; import de.intevation.lada.lock.LockType; import de.intevation.lada.lock.ObjectLocker; @@ -38,6 +42,9 @@ import de.intevation.lada.util.data.RepositoryType; import de.intevation.lada.util.rest.RequestMethod; import de.intevation.lada.util.rest.Response; +import de.intevation.lada.validation.Validator; +import de.intevation.lada.validation.Violation; +import de.intevation.lada.validation.annotation.ValidationConfig; /** * REST service for Status objects. @@ -77,6 +84,9 @@ @RequestScoped public class StatusService { + @Inject + private Logger logger = Logger.getLogger(StatusService.class); + /** * The data repository granting read/write access. */ @@ -98,6 +108,10 @@ @AuthorizationConfig(type=AuthorizationType.HEADER) private Authorization authorization; + @Inject + @ValidationConfig(type="Status") + private Validator validator; + /** * Get all Status objects. * <p> @@ -149,9 +163,20 @@ @Context HttpServletRequest request, @PathParam("id") String id ) { + Response response = defaultRepo.getById( + LStatusProtokoll.class, + Integer.valueOf(id), + "land"); + LStatusProtokoll status = (LStatusProtokoll)response.getData(); + Violation violation = validator.validate(status); + if (violation.hasErrors() || violation.hasWarnings()) { + response.setErrors(violation.getErrors()); + response.setWarnings(violation.getWarnings()); + } + return authorization.filter( request, - defaultRepo.getById(LStatusProtokoll.class, Integer.valueOf(id), "land"), + response, LStatusProtokoll.class); } @@ -227,6 +252,13 @@ return new Response(false, 699, null); } } + Violation violation = validator.validate(status); + if (violation.hasErrors()) { + Response response = new Response(false, 604, status); + response.setErrors(violation.getErrors()); + response.setWarnings(violation.getWarnings()); + return response; + } Response response = defaultRepo.create(status, "land"); LStatusProtokoll created = (LStatusProtokoll)response.getData(); messung.setStatus(created.getId()); @@ -285,6 +317,14 @@ statusNew.setStatusStufe(status.getStatusStufe()); statusNew.setStatusWert(status.getStatusWert()); statusNew.setText(status.getText()); + Violation violation = validator.validate(statusNew); + if (violation.hasErrors()) { + Response response = new Response(false, 604, statusNew); + response.setErrors(violation.getErrors()); + response.setWarnings(violation.getWarnings()); + return response; + } + Response response = defaultRepo.create(statusNew, "land"); LStatusProtokoll created = (LStatusProtokoll)response.getData(); messung.setStatus(created.getId());