changeset 647:4da01934e46f

Added new validation rules for messung objects.
author Raimund Renkert <raimund.renkert@intevation.de>
date Tue, 05 May 2015 14:09:31 +0200
parents ac7f69201d4a
children 9f22f717719d
files src/main/java/de/intevation/lada/validation/rules/messung/Date.java src/main/java/de/intevation/lada/validation/rules/messung/HasPflichtmessgroessen.java src/main/java/de/intevation/lada/validation/rules/messung/MessgroesseToMessmethode.java
diffstat 3 files changed, 169 insertions(+), 0 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/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;
+
+@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;
+    }
+}
--- /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;
+
+@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;
+    }
+}
--- /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;
+
+@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;
+    }
+}
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)