changeset 780:ec231b0c343d

Added validator and first rule for status.
author Raimund Renkert <raimund.renkert@intevation.de>
date Fri, 13 Nov 2015 13:42:25 +0100
parents 64adf06df02f
children 625c8ae7fc30
files src/main/java/de/intevation/lada/validation/StatusValidator.java src/main/java/de/intevation/lada/validation/rules/status/StatusKombination.java
diffstat 2 files changed, 107 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/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@intevation.de">Raimund Renkert</a>
+ */
+@ValidationConfig(type="Status")
+@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;
+    }
+}
--- /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@intevation.de">Raimund Renkert</a>
+ */
+@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;
+    }
+}
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)