[Lada-commits] [PATCH 2 of 3] Added validator for messwert objects

Wald Commits scm-commit at wald.intevation.org
Tue May 5 14:09:18 CEST 2015


# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1430827790 -7200
# Node ID 9f22f717719d54c2e37694eba9bdd1d181cb525a
# Parent  4da01934e46f699a586ef05bee596d580f2477e5
Added validator for messwert objects.

diff -r 4da01934e46f -r 9f22f717719d src/main/java/de/intevation/lada/validation/MesswertValidator.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/validation/MesswertValidator.java	Tue May 05 14:09:50 2015 +0200
@@ -0,0 +1,40 @@
+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.LMesswert;
+import de.intevation.lada.validation.annotation.ValidationConfig;
+import de.intevation.lada.validation.annotation.ValidationRule;
+import de.intevation.lada.validation.rules.Rule;
+
+ at ValidationConfig(type="Messwert")
+ at ApplicationScoped
+public class MesswertValidator implements Validator {
+
+    @Inject
+    @ValidationRule("Messwert")
+    private Instance<Rule> rules;
+
+    @Override
+    public Violation validate(Object object) {
+        Violation violations = new Violation();
+        if (!(object instanceof LMesswert)) {
+            violations.addError("messwert", 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;
+    }
+}


More information about the Lada-commits mailing list