[Lada-commits] [PATCH 3 of 3] Its actually an property of an Ort that is validated here
Wald Commits
scm-commit at wald.intevation.org
Fri Dec 16 16:25:47 CET 2016
# HG changeset patch
# User Tom Gottfried <tom at intevation.de>
# Date 1481901812 -3600
# Node ID 3d0d401b9d9aa4a089b41d80d33b8b612de3e2b8
# Parent 75692dc7077f04f10a9c8744518b0c92a523df1d
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.
diff -r 75692dc7077f -r 3d0d401b9d9a src/main/java/de/intevation/lada/validation/rules/ort/CoordinatesInVE.java
--- /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 at intevation.de">Raimund Renkert</a>
+ */
+ at 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;
+ }
+
+}
diff -r 75692dc7077f -r 3d0d401b9d9a src/main/java/de/intevation/lada/validation/rules/ortszuordnung/CoordinatesInVE.java
--- 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 at intevation.de">Raimund Renkert</a>
- */
- at 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;
- }
-
-}
More information about the Lada-commits
mailing list