[Lada-commits] [PATCH 10 of 11] Added messung validator and rules
Wald Commits
scm-commit at wald.intevation.org
Fri Mar 13 16:50:49 CET 2015
# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1426261820 -3600
# Node ID f3f8b8a26afadd0dcb27084a2b439659740b2f78
# Parent 7a10b1e85c7953e87a95eb813d98fee4a43e5565
Added messung validator and rules.
diff -r 7a10b1e85c79 -r f3f8b8a26afa src/main/java/de/intevation/lada/validation/rules/messung/HasMesswert.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/validation/rules/messung/HasMesswert.java Fri Mar 13 16:50:20 2015 +0100
@@ -0,0 +1,42 @@
+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.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 HasMesswert implements Rule {
+
+ @Inject
+ @RepositoryConfig(type=RepositoryType.RO)
+ private Repository repo;
+
+ @Override
+ public Violation execute(Object object) {
+ LMessung messung = (LMessung)object;
+ QueryBuilder<LMesswert> builder =
+ new QueryBuilder<LMesswert>(
+ repo.entityManager("land"), LMesswert.class);
+ builder.and("messungsId", messung.getId());
+ Response response = repo.filter(builder.getQuery(), "land");
+ @SuppressWarnings("unchecked")
+ List<LMesswert> messwerte = (List<LMesswert>)response.getData();
+ if (messwerte == null || messwerte.isEmpty()) {
+ Violation violation = new Violation();
+ violation.addWarning("messwert", 631);
+ return violation;
+ }
+ return null;
+ }
+}
diff -r 7a10b1e85c79 -r f3f8b8a26afa src/main/java/de/intevation/lada/validation/rules/messung/HasNebenprobenNr.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/validation/rules/messung/HasNebenprobenNr.java Fri Mar 13 16:50:20 2015 +0100
@@ -0,0 +1,23 @@
+package de.intevation.lada.validation.rules.messung;
+
+import de.intevation.lada.model.land.LMessung;
+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 HasNebenprobenNr implements Rule {
+
+ @Override
+ public Violation execute(Object object) {
+ LMessung messung = (LMessung)object;
+ if (messung.getNebenprobenNr() == null ||
+ messung.getNebenprobenNr().equals("")) {
+ Violation violation = new Violation();
+ violation.addWarning("nebenprobenNr", 631);
+ return violation;
+ }
+ return null;
+ }
+
+}
diff -r 7a10b1e85c79 -r f3f8b8a26afa src/main/java/de/intevation/lada/validation/rules/messung/UniqueNebenprobenNr.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/validation/rules/messung/UniqueNebenprobenNr.java Fri Mar 13 16:50:20 2015 +0100
@@ -0,0 +1,47 @@
+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.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 UniqueNebenprobenNr implements Rule {
+
+ @Inject
+ @RepositoryConfig(type=RepositoryType.RO)
+ private Repository repo;
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Violation execute(Object object) {
+ LMessung messung= (LMessung)object;
+ QueryBuilder<LMessung> builder = new QueryBuilder<LMessung>(
+ repo.entityManager("land"),
+ LMessung.class);
+ builder.and("nebenprobenNr", messung.getNebenprobenNr());
+ builder.and("probeId", messung.getProbeId());
+ Response response = repo.filter(builder.getQuery(), "land");
+ if (!((List<LMessung>)response.getData()).isEmpty()) {
+ LMessung found = ((List<LMessung>)response.getData()).get(0);
+ // The messung found in the db equals the new messung. (Update)
+ if (messung.getId() != null && messung.getId() == found.getId()) {
+ return null;
+ }
+ Violation violation = new Violation();
+ violation.addError("nebenprobenNr", 611);
+ return violation;
+ }
+ return null;
+ }
+
+}
More information about the Lada-commits
mailing list