Mercurial > lada > lada-server
changeset 678:328865fa3db7
Validate messung, messwert and ort objects.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Fri, 22 May 2015 15:15:52 +0200 |
parents | de47b7193bdb |
children | 618d1b2f396f |
files | src/main/java/de/intevation/lada/rest/MessungService.java src/main/java/de/intevation/lada/rest/MesswertService.java src/main/java/de/intevation/lada/rest/OrtService.java |
diffstat | 3 files changed, 122 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/rest/MessungService.java Fri May 22 15:15:14 2015 +0200 +++ b/src/main/java/de/intevation/lada/rest/MessungService.java Fri May 22 15:15:52 2015 +0200 @@ -41,6 +41,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 Messung objects. @@ -105,6 +108,10 @@ @AuthorizationConfig(type=AuthorizationType.OPEN_ID) private Authorization authorization; + @Inject + @ValidationConfig(type="Messung") + private Validator validator; + /** * Get all Messung objects. * <p> @@ -156,9 +163,17 @@ @Context HttpServletRequest request, @PathParam("id") String id ) { + Response response = + defaultRepo.getById(LMessung.class, Integer.valueOf(id), "land"); + LMessung messung = (LMessung)response.getData(); + Violation violation = validator.validate(messung); + if (violation.hasErrors() || violation.hasWarnings()) { + response.setErrors(violation.getErrors()); + response.setWarnings(violation.getWarnings()); + } return authorization.filter( request, - defaultRepo.getById(LMessung.class, Integer.valueOf(id), "land"), + response, LMessung.class); } @@ -205,6 +220,14 @@ return new Response(false, 699, null); } + Violation violation = validator.validate(messung); + if (violation.hasErrors()) { + Response response = new Response(false, 604, messung); + response.setErrors(violation.getErrors()); + response.setWarnings(violation.getWarnings()); + return response; + } + /* Persist the new messung object*/ Response response = defaultRepo.create(messung, "land"); LMessung ret = (LMessung)response.getData(); @@ -215,9 +238,13 @@ /* Get and return the new probe object*/ Response created = defaultRepo.getById(LMessung.class, ret.getId(), "land"); + if(violation.hasWarnings()) { + created.setWarnings(violation.getWarnings()); + } + return authorization.filter( request, - new Response(true, 200, created.getData()), + created, LMessung.class); } @@ -266,11 +293,21 @@ if (lock.isLocked(messung)) { return new Response(false, 697, null); } + Violation violation = validator.validate(messung); + if (violation.hasErrors()) { + Response response = new Response(false, 604, messung); + response.setErrors(violation.getErrors()); + response.setWarnings(violation.getWarnings()); + return response; + } messung.setLetzteAenderung(new Timestamp(new Date().getTime())); Response response = defaultRepo.update(messung, "land"); Response updated = defaultRepo.getById( LMessung.class, ((LMessung)response.getData()).getId(), "land"); + if(violation.hasWarnings()) { + updated.setWarnings(violation.getWarnings()); + } return authorization.filter( request, updated,
--- a/src/main/java/de/intevation/lada/rest/MesswertService.java Fri May 22 15:15:14 2015 +0200 +++ b/src/main/java/de/intevation/lada/rest/MesswertService.java Fri May 22 15:15:52 2015 +0200 @@ -41,6 +41,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 Messwert objects. @@ -111,6 +114,10 @@ @AuthorizationConfig(type=AuthorizationType.OPEN_ID) private Authorization authorization; + @Inject + @ValidationConfig(type="Messwert") + private Validator validator; + /** * Get all Messwert objects. * <p> @@ -163,9 +170,17 @@ @Context HttpServletRequest request, @PathParam("id") String id ) { + Response response = + defaultRepo.getById(LMesswert.class, Integer.valueOf(id), "land"); + LMesswert messwert = (LMesswert)response.getData(); + Violation violation = validator.validate(messwert); + if (violation.hasErrors() || violation.hasWarnings()) { + response.setErrors(violation.getErrors()); + response.setWarnings(violation.getWarnings()); + } return authorization.filter( request, - defaultRepo.getById(LMesswert.class, Integer.valueOf(id), "land"), + response, LMesswert.class); } @@ -211,10 +226,22 @@ ) { return new Response(false, 699, null); } + Violation violation = validator.validate(messwert); + if (violation.hasErrors()) { + Response response = new Response(false, 604, messwert); + response.setErrors(violation.getErrors()); + response.setWarnings(violation.getWarnings()); + return response; + } + /* Persist the new messung object*/ + Response response = defaultRepo.create(messwert, "land"); + if(violation.hasWarnings()) { + response.setWarnings(violation.getWarnings()); + } return authorization.filter( request, - defaultRepo.create(messwert, "land"), + response, LMesswert.class); } @@ -263,11 +290,23 @@ if (lock.isLocked(messwert)) { return new Response(false, 697, null); } + Violation violation = validator.validate(messwert); + if (violation.hasErrors()) { + Response response = new Response(false, 604, messwert); + response.setErrors(violation.getErrors()); + response.setWarnings(violation.getWarnings()); + return response; + } + messwert.setLetzteAenderung(new Timestamp(new Date().getTime())); Response response = defaultRepo.update(messwert, "land"); Response updated = defaultRepo.getById( LMesswert.class, ((LMesswert)response.getData()).getId(), "land"); + if(violation.hasWarnings()) { + updated.setWarnings(violation.getWarnings()); + } + return authorization.filter( request, updated,
--- a/src/main/java/de/intevation/lada/rest/OrtService.java Fri May 22 15:15:14 2015 +0200 +++ b/src/main/java/de/intevation/lada/rest/OrtService.java Fri May 22 15:15:52 2015 +0200 @@ -41,6 +41,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 Ort objects. @@ -107,6 +110,10 @@ @AuthorizationConfig(type=AuthorizationType.OPEN_ID) private Authorization authorization; + @Inject + @ValidationConfig(type="Ort") + private Validator validator; + /** * Get all Ort objects. * <p> @@ -160,9 +167,17 @@ @Context HttpServletRequest request, @PathParam("id") String id ) { + Response response = + defaultRepo.getById(LOrt.class, Integer.valueOf(id), "land"); + LOrt ort = (LOrt)response.getData(); + Violation violation = validator.validate(ort); + if (violation.hasErrors() || violation.hasWarnings()) { + response.setErrors(violation.getErrors()); + response.setWarnings(violation.getWarnings()); + } return authorization.filter( request, - defaultRepo.getById(LOrt.class, Integer.valueOf(id), "land"), + response, LOrt.class); } @@ -203,10 +218,23 @@ LOrt.class)) { return new Response(false, 699, null); } + Violation violation = validator.validate(ort); + if (violation.hasErrors()) { + Response response = new Response(false, 604, ort); + response.setErrors(violation.getErrors()); + response.setWarnings(violation.getWarnings()); + return response; + } + /* Persist the new object*/ + Response response = defaultRepo.create(ort, "land"); + if(violation.hasWarnings()) { + response.setWarnings(violation.getWarnings()); + } + return authorization.filter( request, - defaultRepo.create(ort, "land"), + response, LOrt.class); } @@ -250,11 +278,23 @@ if (lock.isLocked(ort)) { return new Response(false, 697, null); } + Violation violation = validator.validate(ort); + if (violation.hasErrors()) { + Response response = new Response(false, 604, ort); + response.setErrors(violation.getErrors()); + response.setWarnings(violation.getWarnings()); + return response; + } + ort.setLetzteAenderung(new Timestamp(new Date().getTime())); Response response = defaultRepo.update(ort, "land"); Response updated = defaultRepo.getById( LOrt.class, ((LOrt)response.getData()).getId(), "land"); + if(violation.hasWarnings()) { + updated.setWarnings(violation.getWarnings()); + } + return authorization.filter( request, updated,