[Lada-commits] [PATCH 03 of 13] Validate imported Ort objects

Wald Commits scm-commit at wald.intevation.org
Fri May 29 11:48:13 CEST 2015


# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1432300300 -7200
# Node ID aeae6a81f28e953152a088eb39c0c3a20d0930f7
# Parent  12f859395c4a178cf2675604899a61a1cb46b93b
Validate imported Ort objects.

diff -r 12f859395c4a -r aeae6a81f28e src/main/java/de/intevation/lada/importer/laf/LafParser.java
--- a/src/main/java/de/intevation/lada/importer/laf/LafParser.java	Fri May 22 15:10:53 2015 +0200
+++ b/src/main/java/de/intevation/lada/importer/laf/LafParser.java	Fri May 22 15:11:40 2015 +0200
@@ -18,6 +18,7 @@
 
 import de.intevation.lada.importer.ReportItem;
 import de.intevation.lada.model.land.LMessung;
+import de.intevation.lada.model.land.LOrt;
 import de.intevation.lada.model.land.LProbe;
 import de.intevation.lada.util.auth.UserInfo;
 import de.intevation.lada.validation.Validator;
@@ -77,9 +78,9 @@
     //@ValidationConfig(type="Messwert")
     //private Validator messwertValidator;
 
-    //@Inject
-    //@ValidationConfig(type="Ort")
-    //private Validator ortValidator;
+    @Inject
+    @ValidationConfig(type="Ort")
+    private Validator ortValidator;
 
     /**
      * The warnings.
@@ -199,6 +200,7 @@
         }
         writer.writeProbenKommentare(userInfo, producer.getProbenKommentare());
         for (LMessung messung: producer.getMessungen().keySet()) {
+            messung.setProbeId(producer.getProbe().getId());
             Violation mViolation = messungValidator.validate(messung);
             if (mViolation.hasErrors()) {
                 ReportItem mErr = new ReportItem("validation", mViolation.getErrors(), null);
@@ -213,7 +215,17 @@
             }
         }
         writer.writeOrte(userInfo, producer.getOrte());
-        writer.writeLOrte(userInfo, producer.getLOrte());
+        for (LOrt ort: producer.getLOrte()) {
+            Violation oViolation = ortValidator.validate(ort);
+            if (oViolation.hasErrors()) {
+                ReportItem oErr = new ReportItem("validation", oViolation.getErrors(), null);
+                List<ReportItem> oErrs = new ArrayList<ReportItem>();
+                oErrs.add(oErr);
+                this.appendErrors(probeId, oErrs);
+                continue;
+            }
+            writer.writeLOrte(userInfo, ort);
+        }
         writer.writeMessungKommentare(userInfo, producer.getMessungsKommentare());
         writer.writeMesswerte(userInfo, producer.getMesswerte());
         Violation postViolation = validateProbe(producer.getProbe());
diff -r 12f859395c4a -r aeae6a81f28e src/main/java/de/intevation/lada/importer/laf/LafWriter.java
--- a/src/main/java/de/intevation/lada/importer/laf/LafWriter.java	Fri May 22 15:10:53 2015 +0200
+++ b/src/main/java/de/intevation/lada/importer/laf/LafWriter.java	Fri May 22 15:11:40 2015 +0200
@@ -148,11 +148,9 @@
      * @param orte  List of {@link LOrt} objects.
      * @return success
      */
-    public boolean writeLOrte(UserInfo userInfo, List<LOrt> orte) {
-        for(LOrt ort: orte) {
-            ort.setProbeId(this.currentProbeId);
-            repository.create(ort, "land");
-        }
+    public boolean writeLOrte(UserInfo userInfo, LOrt ort) {
+        ort.setProbeId(this.currentProbeId);
+        repository.create(ort, "land");
         return true;
     }
 


More information about the Lada-commits mailing list