[Lada-commits] [PATCH] Validate probe objects in 'findById' service

Wald Commits scm-commit at wald.intevation.org
Thu Sep 12 12:32:03 CEST 2013


# HG changeset patch
# User Raimund Renkert <rrenkert at intevation.de>
# Date 1378982088 -7200
# Node ID 8e335385ef95075ef87933b4ef007b50d732a081
# Parent  f3d0894d9bfc4748a4d24f159e9ae7eccf60683e
Validate probe objects in 'findById' service.

diff -r f3d0894d9bfc -r 8e335385ef95 src/main/java/de/intevation/lada/model/LProbeInfo.java
--- 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);
diff -r f3d0894d9bfc -r 8e335385ef95 src/main/java/de/intevation/lada/rest/LProbeService.java
--- 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) ||


More information about the Lada-commits mailing list