[Lada-commits] [PATCH 08 of 13] Fixed validation rules

Wald Commits scm-commit at wald.intevation.org
Fri May 29 11:48:18 CEST 2015


# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1432300514 -7200
# Node ID de47b7193bdb24d57caebf794e18ee525144d6c1
# Parent  ab539e3f186d69323508dc820720f634046f143b
Fixed validation rules.

diff -r ab539e3f186d -r de47b7193bdb src/main/java/de/intevation/lada/validation/rules/messung/Date.java
--- a/src/main/java/de/intevation/lada/validation/rules/messung/Date.java	Fri May 22 15:14:54 2015 +0200
+++ b/src/main/java/de/intevation/lada/validation/rules/messung/Date.java	Fri May 22 15:15:14 2015 +0200
@@ -1,7 +1,6 @@
 package de.intevation.lada.validation.rules.messung;
 
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 
 import javax.inject.Inject;
@@ -28,17 +27,15 @@
         LMessung messung = (LMessung)object;
         Integer probeId = messung.getProbeId();
         Response response = repository.getById(LProbe.class, probeId, "land");
-        @SuppressWarnings("unchecked")
-        List<LProbe> list = (List<LProbe>) response.getData();
-        if (list.isEmpty()) {
+        LProbe probe = (LProbe) response.getData();
+        if (probe == null) {
             Map<String, Integer> errors = new HashMap<String, Integer>();
             errors.put("lprobe", 604);
         }
-        LProbe probe = list.get(0);
         if (probe.getProbeentnahmeEnde() == null ||
             probe.getProbeentnahmeEnde().after(messung.getMesszeitpunkt())) {
             Violation violation = new Violation();
-            violation.addWarning("messzeitpunkt", 661);
+            violation.addWarning("messzeitpunkt", 632);
             return violation;
         }
         return null;
diff -r ab539e3f186d -r de47b7193bdb src/main/java/de/intevation/lada/validation/rules/messung/HasPflichtmessgroessen.java
--- a/src/main/java/de/intevation/lada/validation/rules/messung/HasPflichtmessgroessen.java	Fri May 22 15:14:54 2015 +0200
+++ b/src/main/java/de/intevation/lada/validation/rules/messung/HasPflichtmessgroessen.java	Fri May 22 15:15:14 2015 +0200
@@ -38,8 +38,7 @@
         QueryBuilder<LMesswert> wertBuilder =
             new QueryBuilder<LMesswert>(
                 repository.entityManager("land"), LMesswert.class);
-        wertBuilder.and("messungsId", messung.getId())
-            .and("probeId", messung.getProbeId());
+        wertBuilder.and("messungsId", messung.getId());
         Response wertResponse =
             repository.filter(wertBuilder.getQuery(), "land");
         List<LMesswert> messwerte = (List<LMesswert>)wertResponse.getData();
diff -r ab539e3f186d -r de47b7193bdb src/main/java/de/intevation/lada/validation/rules/messung/MessgroesseToMessmethode.java
--- a/src/main/java/de/intevation/lada/validation/rules/messung/MessgroesseToMessmethode.java	Fri May 22 15:14:54 2015 +0200
+++ b/src/main/java/de/intevation/lada/validation/rules/messung/MessgroesseToMessmethode.java	Fri May 22 15:15:14 2015 +0200
@@ -1,9 +1,12 @@
 package de.intevation.lada.validation.rules.messung;
 
+import java.util.ArrayList;
 import java.util.List;
 
 import javax.inject.Inject;
 
+import org.apache.log4j.Logger;
+
 import de.intevation.lada.model.land.LMessung;
 import de.intevation.lada.model.land.LMesswert;
 import de.intevation.lada.model.stamm.MmtMessgroesse;
@@ -20,6 +23,9 @@
 public class MessgroesseToMessmethode implements Rule {
 
     @Inject
+    private Logger logger;
+
+    @Inject
     @RepositoryConfig(type=RepositoryType.RO)
     private Repository repository;
 
@@ -30,26 +36,32 @@
         QueryBuilder<LMesswert> builder =
             new QueryBuilder<LMesswert>(
                 repository.entityManager("land"), LMesswert.class);
-        builder.and("messungsId", messung.getId())
-            .and("probeId", messung.getProbeId());
+        builder.and("messungsId", messung.getId());
         Response response = repository.filter(builder.getQuery(), "land");
         List<LMesswert> messwerte = (List<LMesswert>)response.getData();
 
         QueryBuilder<MmtMessgroesse> mmtBuilder =
             new QueryBuilder<MmtMessgroesse>(
                     repository.entityManager("stamm"), MmtMessgroesse.class);
-        builder.and("mmtId", mmt);
 
         Response results =
             repository.filter(mmtBuilder.getQuery(), "stamm");
         List<MmtMessgroesse> messgroessen =
             (List<MmtMessgroesse>)results.getData();
+        List<MmtMessgroesse> found = new ArrayList<MmtMessgroesse>();
+        for (MmtMessgroesse mg: messgroessen) {
+            if (mmt.equals(mg.getMmtMessgroessePK().getMmtId())) {
+                logger.debug("found: " + mg.getMmtMessgroessePK().getMmtId() + " for " + mmt);
+                found.add(mg);
+            }
+        }
         Violation violation = new Violation();
         for(LMesswert messwert: messwerte) {
             boolean hit = false;
-            for (MmtMessgroesse messgroesse: messgroessen) {
+            for (MmtMessgroesse messgroesse: found) {
+                logger.debug("###### mmt: " + messwert.getMessgroesseId() + " mmtmg: " + messgroesse.getMmtMessgroessePK().getMessgroessengruppeId());
                 if (messwert.getMessgroesseId().equals(
-                        messgroesse.getMmtMessgroessePK().getMmtId().toString())) {
+                        messgroesse.getMmtMessgroessePK().getMessgroessengruppeId())) {
                     hit = true;
                 }
             }
diff -r ab539e3f186d -r de47b7193bdb src/main/java/de/intevation/lada/validation/rules/ort/CoordinatesInVE.java
--- a/src/main/java/de/intevation/lada/validation/rules/ort/CoordinatesInVE.java	Fri May 22 15:14:54 2015 +0200
+++ b/src/main/java/de/intevation/lada/validation/rules/ort/CoordinatesInVE.java	Fri May 22 15:15:14 2015 +0200
@@ -1,5 +1,23 @@
 package de.intevation.lada.validation.rules.ort;
 
+import java.util.List;
+
+import javax.inject.Inject;
+
+import com.vividsolutions.jts.geom.Coordinate;
+import com.vividsolutions.jts.geom.GeometryFactory;
+import com.vividsolutions.jts.geom.Point;
+import com.vividsolutions.jts.geom.PrecisionModel;
+
+import de.intevation.lada.model.land.LOrt;
+import de.intevation.lada.model.stamm.DeVg;
+import de.intevation.lada.model.stamm.SOrt;
+import de.intevation.lada.model.stamm.Verwaltungseinheit;
+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.util.rest.Response;
 import de.intevation.lada.validation.Violation;
 import de.intevation.lada.validation.annotation.ValidationRule;
 import de.intevation.lada.validation.rules.Rule;
@@ -7,9 +25,58 @@
 @ValidationRule("Ort")
 public class CoordinatesInVE implements Rule {
 
+    @Inject
+    @RepositoryConfig(type=RepositoryType.RO)
+    private Repository repository;
+
     @Override
     public Violation execute(Object object) {
-        // TODO
+        LOrt ort = (LOrt)object;
+        if (!"E".equals(ort.getOrtsTyp())) {
+            return null;
+        }
+        QueryBuilder<SOrt> ortBuilder =
+            new QueryBuilder<SOrt>(repository.entityManager("stamm"), SOrt.class);
+        ortBuilder.and("id", ort.getOrt());
+        Response response = repository.filter(ortBuilder.getQuery(), "stamm");
+        List<SOrt> orte = (List<SOrt>)response.getData();
+        QueryBuilder<Verwaltungseinheit> veBuilder =
+            new QueryBuilder<Verwaltungseinheit>(
+                repository.entityManager("stamm"), Verwaltungseinheit.class);
+        veBuilder.and("id", orte.get(0).getVerwaltungseinheitId());
+        Response ver = repository.filter(veBuilder.getQuery(), "stamm");
+        if (((List<Verwaltungseinheit>)ver.getData()).isEmpty()) {
+            Violation violation = new Violation();
+            violation.addWarning("verwaltungseinheit", 653);
+            return violation;
+        }
+        Verwaltungseinheit ve = ((List<Verwaltungseinheit>)ver.getData()).get(0);
+        QueryBuilder<DeVg> vg =
+            new QueryBuilder<DeVg>(repository.entityManager("stamm"), DeVg.class);
+        vg.and("ags", ve.getId());
+        Response rvg = repository.filter(vg.getQuery(), "stamm");
+        List<DeVg> vgs = (List<DeVg>)rvg.getData();
+        if (vgs == null || vgs.isEmpty()) {
+            Violation violation = new Violation();
+            violation.addWarning("verwaltungseinheit", 653);
+            return violation;
+        }
+        double y = orte.get(0).getLatitude();
+        double x = orte.get(0).getLongitude();
+        Coordinate c = new Coordinate(x, y);
+        GeometryFactory gf = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING), 4326);
+        Point p = gf.createPoint(c);
+        boolean hit = false;
+        for (DeVg singlevg : vgs) {
+            if(singlevg.getGeom().contains(p)) {
+                hit = true;
+            }
+        }
+        if (!hit) {
+            Violation violation = new Violation();
+            violation.addWarning("verwaltungseinheit", 651);
+            return violation;
+        }
         return null;
     }
 
diff -r ab539e3f186d -r de47b7193bdb src/main/java/de/intevation/lada/validation/rules/probe/HasEntnahmeOrt.java
--- a/src/main/java/de/intevation/lada/validation/rules/probe/HasEntnahmeOrt.java	Fri May 22 15:14:54 2015 +0200
+++ b/src/main/java/de/intevation/lada/validation/rules/probe/HasEntnahmeOrt.java	Fri May 22 15:15:14 2015 +0200
@@ -38,7 +38,7 @@
         @SuppressWarnings("unchecked")
         List<LOrt> orte = (List<LOrt>)response.getData();
         for (LOrt ort: orte) {
-            if (ort.getOrtsTyp().equals("E")) {
+            if ("E".equals(ort.getOrtsTyp())) {
                 return null;
             }
         }


More information about the Lada-commits mailing list