changeset 1251:3d0d401b9d9a

Its actually an property of an Ort that is validated here. The validation occured only in case the Ort had been associated to a Probe object. Now it occurs on creation or update of an Ort.
author Tom Gottfried <tom@intevation.de>
date Fri, 16 Dec 2016 16:23:32 +0100
parents 75692dc7077f
children f434ccd64864
files src/main/java/de/intevation/lada/validation/rules/ort/CoordinatesInVE.java src/main/java/de/intevation/lada/validation/rules/ortszuordnung/CoordinatesInVE.java
diffstat 2 files changed, 88 insertions(+), 84 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/CoordinatesInVE.java	Fri Dec 16 16:23:32 2016 +0100
@@ -0,0 +1,88 @@
+/* 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 com.vividsolutions.jts.geom.Point;
+
+import org.apache.log4j.Logger;
+
+import de.intevation.lada.model.stammdaten.Ort;
+import de.intevation.lada.model.stammdaten.Verwaltungseinheit;
+import de.intevation.lada.model.stammdaten.Verwaltungsgrenze;
+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;
+
+/**
+ * Validation rule for ort.
+ * Validates if the coordinates are in the specified "Verwaltungseinheit".
+ *
+ * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a>
+ */
+@ValidationRule("Ort")
+public class CoordinatesInVE implements Rule {
+
+    @Inject
+    private Logger logger;
+
+    @Inject
+    @RepositoryConfig(type=RepositoryType.RO)
+    private Repository repository;
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public Violation execute(Object object) {
+        Ort ort = (Ort)object;
+
+        String gemId = "".equals(ort.getGemId())
+            ? null
+            : ort.getGemId();
+
+        if (gemId != null) {
+
+            QueryBuilder<Verwaltungsgrenze> vg =
+                new QueryBuilder<Verwaltungsgrenze>(
+                    repository.entityManager("stamm"),
+                    Verwaltungsgrenze.class);
+            vg.and("gemId", gemId);
+            List<Verwaltungsgrenze> vgs = repository.filterPlain(
+                vg.getQuery(), "stamm");
+            if (vgs == null || vgs.isEmpty()) {
+                Violation violation = new Violation();
+                violation.addWarning("verwaltungsgrenze", 600);
+                return violation;
+            }
+
+            Point p = ort.getGeom();
+            if (p == null) {
+                logger.error("geom is null. "
+                    + "Probably OrtFactory.transformCoordinates() has not "
+                    + "been called on this ort.");
+            }
+            for (Verwaltungsgrenze singlevg : vgs) {
+                if(singlevg.getShape().contains(p)) {
+                    return null;
+                }
+            }
+            Violation violation = new Violation();
+            violation.addWarning("verwaltungsgrenze", 651);
+            return violation;
+        }
+
+        return null;
+    }
+
+}
--- a/src/main/java/de/intevation/lada/validation/rules/ortszuordnung/CoordinatesInVE.java	Fri Dec 16 16:20:19 2016 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,84 +0,0 @@
-/* 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 com.vividsolutions.jts.geom.Point;
-
-import de.intevation.lada.model.land.Ortszuordnung;
-import de.intevation.lada.model.stammdaten.Ort;
-import de.intevation.lada.model.stammdaten.Verwaltungseinheit;
-import de.intevation.lada.model.stammdaten.Verwaltungsgrenze;
-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;
-
-/**
- * Validation rule for ort.
- * Validates if the coordinates are in the specified "Verwaltungseinheit".
- *
- * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a>
- */
-@ValidationRule("Ortszuordnung")
-public class CoordinatesInVE implements Rule {
-
-    @Inject
-    @RepositoryConfig(type=RepositoryType.RO)
-    private Repository repository;
-
-    @SuppressWarnings("unchecked")
-    @Override
-    public Violation execute(Object object) {
-        Ortszuordnung oz = (Ortszuordnung)object;
-        if (!"E".equals(oz.getOrtszuordnungTyp())) {
-            return null;
-        }
-
-        Ort ort = repository.getByIdPlain(Ort.class, oz.getOrtId(), "stamm");
-        String gemId = ort.getGemId();
-        if (gemId == null) {
-            Violation violation = new Violation();
-            violation.addWarning("gemId", 631);
-            return violation;
-        }
-
-        QueryBuilder<Verwaltungsgrenze> vg =
-            new QueryBuilder<Verwaltungsgrenze>(
-                repository.entityManager("stamm"), Verwaltungsgrenze.class);
-        vg.and("gemId", gemId);
-        List<Verwaltungsgrenze> vgs = repository.filterPlain(
-            vg.getQuery(), "stamm");
-        if (vgs == null || vgs.isEmpty()) {
-            Violation violation = new Violation();
-            violation.addWarning("verwaltungsgrenze", 600);
-            return violation;
-        }
-
-        Point p = ort.getGeom();
-        boolean hit = false;
-        for (Verwaltungsgrenze singlevg : vgs) {
-            if(singlevg.getShape().contains(p)) {
-                hit = true;
-            }
-        }
-        if (!hit) {
-            Violation violation = new Violation();
-            violation.addWarning("verwaltungsgrenze", 651);
-            return violation;
-        }
-        return null;
-    }
-
-}
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)