[Lada-commits] [PATCH] Added validation to make sure a probe has only one 'entnahme ort'

Wald Commits scm-commit at wald.intevation.org
Wed Nov 9 12:40:46 CET 2016


# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1478691642 -3600
# Node ID 46db98d060ae8a9846db0a9db18200792b419aac
# Parent  84ff77bba9b0a215fa3e495bf57420f29c702de6
Added validation to make sure a probe has only one 'entnahme ort'.

diff -r 84ff77bba9b0 -r 46db98d060ae src/main/java/de/intevation/lada/validation/rules/ort/HasEntnahmeOrt.java
--- /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;
+
+ at 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;
+    }
+}


More information about the Lada-commits mailing list