[Lada-commits] [PATCH 06 of 10] Added first validation rules for probe objects

Wald Commits scm-commit at wald.intevation.org
Tue Feb 24 14:57:48 CET 2015


# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1424771886 -3600
# Node ID fd927b584c54ce737e3d74175981439efe117d34
# Parent  f44c9e59f08c174a688b7a9039dfd63af49a89e2
Added first validation rules for probe objects.

diff -r f44c9e59f08c -r fd927b584c54 src/main/java/de/intevation/lada/validation/rules/probe/HasEntnahmeOrt.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/validation/rules/probe/HasEntnahmeOrt.java	Tue Feb 24 10:58:06 2015 +0100
@@ -0,0 +1,50 @@
+package de.intevation.lada.validation.rules.probe;
+
+import java.util.List;
+
+import javax.inject.Inject;
+
+import de.intevation.lada.model.land.LOrt;
+import de.intevation.lada.model.land.LProbe;
+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("Probe")
+public class HasEntnahmeOrt implements Rule {
+
+    @Inject
+    @RepositoryConfig(type=RepositoryType.RO)
+    private Repository repo;
+
+    @Override
+    public Violation execute(Object object) {
+        LProbe probe = (LProbe)object;
+        Integer id = probe.getId();
+        if (id == null) {
+            Violation violation = new Violation();
+            violation.addWarning("entnahmeOrt", 631);
+            return violation;
+        }
+        QueryBuilder<LOrt> builder =
+            new QueryBuilder<LOrt>(repo.entityManager("land"), LOrt.class);
+        builder.and("probeId", id);
+        Response response = repo.filter(builder.getQuery(), "land");
+        @SuppressWarnings("unchecked")
+        List<LOrt> orte = (List<LOrt>)response.getData();
+        for (LOrt ort: orte) {
+            if (ort.getOrtsTyp().equals("E")) {
+                return null;
+            }
+        }
+        Violation violation = new Violation();
+        violation.addWarning("entnahmeOrt", 631);
+        return violation;
+    }
+
+}
diff -r f44c9e59f08c -r fd927b584c54 src/main/java/de/intevation/lada/validation/rules/probe/HasHauptprobenNr.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/validation/rules/probe/HasHauptprobenNr.java	Tue Feb 24 10:58:06 2015 +0100
@@ -0,0 +1,22 @@
+package de.intevation.lada.validation.rules.probe;
+
+import de.intevation.lada.model.land.LProbe;
+import de.intevation.lada.validation.Violation;
+import de.intevation.lada.validation.annotation.ValidationRule;
+import de.intevation.lada.validation.rules.Rule;
+
+ at ValidationRule("Probe")
+public class HasHauptprobenNr implements Rule {
+
+    @Override
+    public Violation execute(Object object) {
+        LProbe probe = (LProbe)object;
+        if (probe.getHauptprobenNr() == null ||
+            probe.getHauptprobenNr().equals("")) {
+            Violation violation = new Violation();
+            violation.addError("hauptprobenNr", 631);
+            return violation;
+        }
+        return null;
+    }
+}
diff -r f44c9e59f08c -r fd927b584c54 src/main/java/de/intevation/lada/validation/rules/probe/HasProbenahmeBegin.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/validation/rules/probe/HasProbenahmeBegin.java	Tue Feb 24 10:58:06 2015 +0100
@@ -0,0 +1,25 @@
+package de.intevation.lada.validation.rules.probe;
+
+import java.sql.Timestamp;
+
+import de.intevation.lada.model.land.LProbe;
+import de.intevation.lada.validation.Violation;
+import de.intevation.lada.validation.annotation.ValidationRule;
+import de.intevation.lada.validation.rules.Rule;
+
+ at ValidationRule("Probe")
+public class HasProbenahmeBegin implements Rule {
+
+    @Override
+    public Violation execute(Object object) {
+        LProbe probe = (LProbe)object;
+        Timestamp begin = probe.getProbeentnahmeBeginn();
+        if (begin == null) {
+            Violation violation = new Violation();
+            violation.addWarning("probeentnahmeBegin", 631);
+            return violation;
+        }
+        return null;
+    }
+
+}
diff -r f44c9e59f08c -r fd927b584c54 src/main/java/de/intevation/lada/validation/rules/probe/UniqueHauptprobenNr.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/validation/rules/probe/UniqueHauptprobenNr.java	Tue Feb 24 10:58:06 2015 +0100
@@ -0,0 +1,46 @@
+package de.intevation.lada.validation.rules.probe;
+
+import java.util.List;
+
+import javax.inject.Inject;
+
+import de.intevation.lada.model.land.LProbe;
+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("Probe")
+public class UniqueHauptprobenNr implements Rule {
+
+    @Inject
+    @RepositoryConfig(type=RepositoryType.RO)
+    private Repository repo;
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public Violation execute(Object object) {
+        LProbe probe = (LProbe)object;
+        QueryBuilder<LProbe> builder = new QueryBuilder<LProbe>(
+            repo.entityManager("land"),
+            LProbe.class);
+        builder.and("hauptprobenNr", probe.getHauptprobenNr());
+        Response response = repo.filter(builder.getQuery(), "land");
+        if (!((List<LProbe>)response.getData()).isEmpty()) {
+            LProbe found = ((List<LProbe>)response.getData()).get(0);
+            // The probe found in the db equals the new probe. (Update)
+            if (probe.getId() != null && probe.getId() == found.getId()) {
+                return null;
+            }
+            Violation violation = new Violation();
+            violation.addError("hauptprobenNr", 611);
+            return violation;
+        }
+        return null;
+    }
+
+}


More information about the Lada-commits mailing list