changeset 1165:46db98d060ae

Added validation to make sure a probe has only one 'entnahme ort'.
author Raimund Renkert <raimund.renkert@intevation.de>
date Wed, 09 Nov 2016 12:40:42 +0100
parents 84ff77bba9b0
children 8295d84fe003
files src/main/java/de/intevation/lada/validation/rules/ort/HasEntnahmeOrt.java
diffstat 1 files changed, 54 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/validation/rules/ort/HasEntnahmeOrt.java	Wed Nov 09 12:40:42 2016 +0100
@@ -0,0 +1,54 @@
+/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU GPL (v>=3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out
+ * the documentation coming with IMIS-Labordaten-Application for details.
+ */
+package de.intevation.lada.validation.rules.ort;
+
+import java.util.List;
+
+import javax.inject.Inject;
+
+import de.intevation.lada.model.land.Ortszuordnung;
+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;
+
+@ValidationRule("Ort")
+public class HasEntnahmeOrt implements Rule {
+
+    @Inject
+    @RepositoryConfig(type=RepositoryType.RO)
+    private Repository repository;
+
+    @Override
+    public Violation execute(Object object) {
+        Ortszuordnung ort = (Ortszuordnung)object;
+        if (!"E".equals(ort.getOrtszuordnungTyp())) {
+            return null;
+        }
+
+        QueryBuilder<Ortszuordnung> builder = new QueryBuilder<Ortszuordnung>(
+            repository.entityManager("land"),
+            Ortszuordnung.class);
+        builder.and("probeId", ort.getProbeId());
+        List<Ortszuordnung> orte = repository.filterPlain(
+            builder.getQuery(),
+            "land");
+        for (Ortszuordnung o : orte) {
+            if ("E".equals(o.getOrtszuordnungTyp())) {
+                Violation violation = new Violation();
+                violation.addError("ortszuordnungsTyp", 611);
+                return violation;
+            }
+        }
+
+        return null;
+    }
+}
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)