changeset 648:9f22f717719d

Added validator for messwert objects.
author Raimund Renkert <raimund.renkert@intevation.de>
date Tue, 05 May 2015 14:09:50 +0200
parents 4da01934e46f
children 53816b76753a
files src/main/java/de/intevation/lada/validation/MesswertValidator.java
diffstat 1 files changed, 40 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/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;
+
+@ValidationConfig(type="Messwert")
+@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;
+    }
+}
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)