Mercurial > lada > lada-server
changeset 369:8e335385ef95
Validate probe objects in 'findById' service.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Thu, 12 Sep 2013 12:34:48 +0200 |
parents | f3d0894d9bfc |
children | 9c3b3d34b260 d878ff29e521 |
files | src/main/java/de/intevation/lada/model/LProbeInfo.java src/main/java/de/intevation/lada/rest/LProbeService.java |
diffstat | 2 files changed, 19 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/model/LProbeInfo.java Wed Sep 11 12:16:08 2013 +0200 +++ b/src/main/java/de/intevation/lada/model/LProbeInfo.java Thu Sep 12 12:34:48 2013 +0200 @@ -308,6 +308,7 @@ public LProbe toLProbe() { LProbe probe = new LProbe(); + probe.setProbeId(probeId); probe.setMstId(mstId); probe.setUmwId(umwId); probe.setTest(test);
--- a/src/main/java/de/intevation/lada/rest/LProbeService.java Wed Sep 11 12:16:08 2013 +0200 +++ b/src/main/java/de/intevation/lada/rest/LProbeService.java Thu Sep 12 12:34:48 2013 +0200 @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.logging.Logger; import javax.enterprise.context.RequestScoped; @@ -33,6 +34,8 @@ import de.intevation.lada.model.LProbe; import de.intevation.lada.model.LProbeInfo; import de.intevation.lada.utils.QueryTools; +import de.intevation.lada.validation.ValidationException; +import de.intevation.lada.validation.Validator; /** * This class produces a RESTful service to read, write and update @@ -66,6 +69,10 @@ @Named("dataauthorization") private Authorization authorization; + @Inject + @Named("lprobevalidator") + private Validator validator; + /** * The logger for this class. */ @@ -96,6 +103,17 @@ if (probe.isEmpty()) { return new Response(false, 601, new ArrayList<LProbeInfo>()); } + LProbeInfo p = probe.get(0); + try { + Map<String, Integer> warn = + validator.validate(p.toLProbe(), false); + response.setWarnings(warn); + } + catch (ValidationException e) { + response.setErrors(e.getErrors()); + response.setWarnings(e.getWarnings()); + } + String nbId = probe.get(0).getNetzbetreiberId(); String mstId = probe.get(0).getMstId(); if (auth.getNetzbetreiber().contains(nbId) ||