[Lada-commits] [PATCH 3 of 3] Added validator and first rule for status

Wald Commits scm-commit at wald.intevation.org
Fri Nov 13 13:42:24 CET 2015


# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1447418545 -3600
# Node ID ec231b0c343dbbf855f7e4e8ac0afd4a2da46de0
# Parent  64adf06df02f21592c4ceaf6165c379374375c21
Added validator and first rule for status.

diff -r 64adf06df02f -r ec231b0c343d src/main/java/de/intevation/lada/validation/StatusValidator.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/validation/StatusValidator.java	Fri Nov 13 13:42:25 2015 +0100
@@ -0,0 +1,55 @@
+/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU GPL (v>=3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out
+ * the documentation coming with IMIS-Labordaten-Application for details.
+ */
+package de.intevation.lada.validation;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Instance;
+import javax.inject.Inject;
+
+import de.intevation.lada.model.land.LStatusProtokoll;
+import de.intevation.lada.validation.annotation.ValidationConfig;
+import de.intevation.lada.validation.annotation.ValidationRule;
+import de.intevation.lada.validation.rules.Rule;
+
+/**
+ * Validation for messung objects.
+ *
+ * Instantiates the set of rules for messung objects and uses these rules to
+ * validate the object.
+ *
+ * @author <a href="mailto:raimund.renkert at intevation.de">Raimund Renkert</a>
+ */
+ at ValidationConfig(type="Status")
+ at ApplicationScoped
+public class StatusValidator implements Validator {
+
+    @Inject
+    @ValidationRule("Status")
+    private Instance<Rule> rules;
+
+    @Override
+    public Violation validate(Object object) {
+        Violation violations = new Violation();
+        if (!(object instanceof LStatusProtokoll)) {
+            violations.addError("status", 602);
+            return violations;
+        }
+        for(Rule rule: rules) {
+            Violation result = rule.execute(object);
+            if (result != null) {
+                if (result.hasWarnings()) {
+                    violations.addWarnings(result.getWarnings());
+                }
+                if (result.hasErrors()) {
+                    violations.addErrors(result.getErrors());
+                }
+            }
+        }
+        return violations;
+    }
+}
diff -r 64adf06df02f -r ec231b0c343d src/main/java/de/intevation/lada/validation/rules/status/StatusKombination.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/validation/rules/status/StatusKombination.java	Fri Nov 13 13:42:25 2015 +0100
@@ -0,0 +1,52 @@
+/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz
+ * Software engineering by Intevation GmbH
+ *
+ * This file is Free Software under the GNU GPL (v>=3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out
+ * the documentation coming with IMIS-Labordaten-Application for details.
+ */
+package de.intevation.lada.validation.rules.status;
+
+import java.util.List;
+
+import javax.inject.Inject;
+
+import de.intevation.lada.model.land.LStatusProtokoll;
+import de.intevation.lada.model.stamm.StatusKombi;
+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.validation.Violation;
+import de.intevation.lada.validation.annotation.ValidationRule;
+import de.intevation.lada.validation.rules.Rule;
+
+/**
+ * Validation rule for status.
+ *
+ * @author <a href="mailto:rrenkert at intevation.de">Raimund Renkert</a>
+ */
+ at ValidationRule("Status")
+public class StatusKombination implements Rule {
+
+    @Inject
+    @RepositoryConfig(type=RepositoryType.RO)
+    private Repository repository;
+
+    @Override
+    public Violation execute(Object object) {
+        LStatusProtokoll status = (LStatusProtokoll)object;
+        QueryBuilder<StatusKombi> kombi = new QueryBuilder<StatusKombi>(
+            repository.entityManager("stamm"),
+            StatusKombi.class);
+        kombi.and("stufeId", status.getStatusStufe());
+        kombi.and("wertId", status.getStatusWert());
+        List<StatusKombi> result =
+            repository.filterPlain(kombi.getQuery(), "stamm");
+        if (result.isEmpty()) {
+            Violation violation = new Violation();
+            violation.addError("status", 632);
+        }
+        return null;
+    }
+}


More information about the Lada-commits mailing list