changeset 672:aeae6a81f28e

Validate imported Ort objects.
author Raimund Renkert <raimund.renkert@intevation.de>
date Fri, 22 May 2015 15:11:40 +0200
parents 12f859395c4a
children e6564d5fdc7a
files src/main/java/de/intevation/lada/importer/laf/LafParser.java src/main/java/de/intevation/lada/importer/laf/LafWriter.java
diffstat 2 files changed, 19 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- 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());
--- 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;
     }
 
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)