changeset 1269:3cdf75a9bf92

Check for entnahmeOrt in messprogramm and add error if missing.
author Raimund Renkert <raimund.renkert@intevation.de>
date Fri, 27 Jan 2017 16:12:52 +0100
parents 7ae0fa505abb
children 6b3a551236ba
files src/main/java/de/intevation/lada/validation/rules/messprogramm/HasAllMandatory.java
diffstat 1 files changed, 28 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/validation/rules/messprogramm/HasAllMandatory.java	Fri Jan 27 15:55:08 2017 +0100
+++ b/src/main/java/de/intevation/lada/validation/rules/messprogramm/HasAllMandatory.java	Fri Jan 27 16:12:52 2017 +0100
@@ -7,7 +7,16 @@
  */
 package de.intevation.lada.validation.rules.messprogramm;
 
+import java.util.List;
+
+import javax.inject.Inject;
+
 import de.intevation.lada.model.land.Messprogramm;
+import de.intevation.lada.model.land.OrtszuordnungMp;
+import de.intevation.lada.util.annotation.RepositoryConfig;
+import de.intevation.lada.util.data.QueryBuilder;
+import de.intevation.lada.util.data.Repository;
+import de.intevation.lada.util.data.RepositoryType;
 import de.intevation.lada.validation.Violation;
 import de.intevation.lada.validation.annotation.ValidationRule;
 import de.intevation.lada.validation.rules.Rule;
@@ -19,6 +28,10 @@
 @ValidationRule("Messprogramm")
 public class HasAllMandatory implements Rule {
 
+    @Inject
+    @RepositoryConfig(type=RepositoryType.RO)
+    Repository repository;
+
     @Override
     public Violation execute(Object object) {
         Messprogramm messprogramm = (Messprogramm)object;
@@ -54,6 +67,21 @@
         if (messprogramm.getGueltigBis() == null) {
             violation.addError("gueltigBis", 631);
         }
+        QueryBuilder<OrtszuordnungMp> builder =
+            new QueryBuilder<OrtszuordnungMp>(
+                repository.entityManager("land"),
+                OrtszuordnungMp.class);
+        List<OrtszuordnungMp> orte = repository.filterPlain(
+            builder.getQuery(), "land");
+        boolean found = false;
+        for (OrtszuordnungMp ort : orte) {
+            if ("E".equals(ort.getOrtszuordnungTyp())) {
+                found = true;
+            }
+        }
+        if (!found) {
+            violation.addError("entnahmeOrt", 631);
+        }
 
         return violation.hasErrors()
             ? violation
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)