changeset 651:0086dc4ac72e

Added validator for ort objects.
author Raimund Renkert <raimund.renkert@intevation.de>
date Tue, 05 May 2015 14:23:45 +0200
parents 55177afef263
children 881da3d5377b
files src/main/java/de/intevation/lada/validation/OrtValidator.java
diffstat 1 files changed, 41 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/OrtValidator.java	Tue May 05 14:23:45 2015 +0200
@@ -0,0 +1,41 @@
+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.LOrt;
+import de.intevation.lada.validation.annotation.ValidationConfig;
+import de.intevation.lada.validation.annotation.ValidationRule;
+import de.intevation.lada.validation.rules.Rule;
+
+@ValidationConfig(type="Ort")
+@ApplicationScoped
+public class OrtValidator implements Validator {
+
+    @Inject
+    @ValidationRule("Ort")
+    private Instance<Rule> rules;
+
+    @Override
+    public Violation validate(Object object) {
+        Violation violations = new Violation();
+        if (!(object instanceof LOrt)) {
+            violations.addError("ort", 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)