[Lada-commits] [PATCH 1 of 3] Added new validation rules for messung objects

Wald Commits scm-commit at wald.intevation.org
Tue May 5 14:09:17 CEST 2015


# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1430827771 -7200
# Node ID 4da01934e46f699a586ef05bee596d580f2477e5
# Parent  ac7f69201d4af653451e481aa9fda0d50396112d
Added new validation rules for messung objects.

diff -r ac7f69201d4a -r 4da01934e46f src/main/java/de/intevation/lada/validation/rules/messung/Date.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/validation/rules/messung/Date.java	Tue May 05 14:09:31 2015 +0200
@@ -0,0 +1,46 @@
+package de.intevation.lada.validation.rules.messung;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.inject.Inject;
+
+import de.intevation.lada.model.land.LMessung;
+import de.intevation.lada.model.land.LProbe;
+import de.intevation.lada.util.annotation.RepositoryConfig;
+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;
+
+ at ValidationRule("Messung")
+public class Date implements Rule {
+
+    @Inject
+    @RepositoryConfig(type=RepositoryType.RO)
+    private Repository repository;
+
+    @Override
+    public Violation execute(Object object) {
+        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()) {
+            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);
+            return violation;
+        }
+        return null;
+    }
+}
diff -r ac7f69201d4a -r 4da01934e46f src/main/java/de/intevation/lada/validation/rules/messung/HasPflichtmessgroessen.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/validation/rules/messung/HasPflichtmessgroessen.java	Tue May 05 14:09:31 2015 +0200
@@ -0,0 +1,61 @@
+package de.intevation.lada.validation.rules.messung;
+
+import java.util.List;
+
+import javax.inject.Inject;
+
+import de.intevation.lada.model.land.LMessung;
+import de.intevation.lada.model.land.LMesswert;
+import de.intevation.lada.model.stamm.PflichtMessgroesse;
+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;
+
+ at ValidationRule("Messung")
+public class HasPflichtmessgroessen implements Rule {
+
+    @Inject
+    @RepositoryConfig(type=RepositoryType.RO)
+    private Repository repository;
+
+    @Override
+    public Violation execute(Object object) {
+        LMessung messung = (LMessung)object;
+        QueryBuilder<PflichtMessgroesse> builder =
+            new QueryBuilder<PflichtMessgroesse>(
+                repository.entityManager("stamm"),
+                PflichtMessgroesse.class);
+        builder.and("mmtId", messung.getMmtId());
+        Response response = repository.filter(builder.getQuery(), "stamm");
+        List<PflichtMessgroesse> pflicht =
+            (List<PflichtMessgroesse>)response.getData();
+
+        QueryBuilder<LMesswert> wertBuilder =
+            new QueryBuilder<LMesswert>(
+                repository.entityManager("land"), LMesswert.class);
+        wertBuilder.and("messungsId", messung.getId())
+            .and("probeId", messung.getProbeId());
+        Response wertResponse =
+            repository.filter(wertBuilder.getQuery(), "land");
+        List<LMesswert> messwerte = (List<LMesswert>)wertResponse.getData();
+        Violation violation = new Violation();
+        boolean hit = false;
+        for (PflichtMessgroesse p : pflicht) {
+            hit = false;
+            for (LMesswert wert : messwerte) {
+                if (p.getMessgroesseId().equals(wert.getMessgroesseId())) {
+                    hit = true;
+                }
+            }
+            if (!hit) {
+                violation.addWarning("pflichtmessgroesse", 631);
+            }
+        }
+        return violation.hasWarnings() ? violation : null;
+    }
+}
diff -r ac7f69201d4a -r 4da01934e46f src/main/java/de/intevation/lada/validation/rules/messung/MessgroesseToMessmethode.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/validation/rules/messung/MessgroesseToMessmethode.java	Tue May 05 14:09:31 2015 +0200
@@ -0,0 +1,62 @@
+package de.intevation.lada.validation.rules.messung;
+
+import java.util.List;
+
+import javax.inject.Inject;
+
+import de.intevation.lada.model.land.LMessung;
+import de.intevation.lada.model.land.LMesswert;
+import de.intevation.lada.model.stamm.MmtMessgroesse;
+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;
+
+ at ValidationRule("Messung")
+public class MessgroesseToMessmethode implements Rule {
+
+    @Inject
+    @RepositoryConfig(type=RepositoryType.RO)
+    private Repository repository;
+
+    @Override
+    public Violation execute(Object object) {
+        LMessung messung = (LMessung)object;
+        String mmt = messung.getMmtId();
+        QueryBuilder<LMesswert> builder =
+            new QueryBuilder<LMesswert>(
+                repository.entityManager("land"), LMesswert.class);
+        builder.and("messungsId", messung.getId())
+            .and("probeId", messung.getProbeId());
+        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();
+        Violation violation = new Violation();
+        for(LMesswert messwert: messwerte) {
+            boolean hit = false;
+            for (MmtMessgroesse messgroesse: messgroessen) {
+                if (messwert.getMessgroesseId().equals(
+                        messgroesse.getMmtMessgroessePK().getMmtId().toString())) {
+                    hit = true;
+                }
+            }
+            if (!hit) {
+                violation.addWarning("messgroesse", 632);
+            }
+        }
+        return violation.hasWarnings() ? violation : null;
+    }
+}


More information about the Lada-commits mailing list