annotate src/main/java/de/intevation/lada/validation/ProbeValidator.java @ 537:f44c9e59f08c

Added validator for probe objects.
author Raimund Renkert <raimund.renkert@intevation.de>
date Tue, 24 Feb 2015 10:56:47 +0100
parents
children 7925f5eda6c4
rev   line source
537
f44c9e59f08c Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
1 package de.intevation.lada.validation;
f44c9e59f08c Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
2
f44c9e59f08c Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
3 import javax.enterprise.context.ApplicationScoped;
f44c9e59f08c Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
4 import javax.enterprise.inject.Instance;
f44c9e59f08c Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
5 import javax.inject.Inject;
f44c9e59f08c Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
6
f44c9e59f08c Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
7 import de.intevation.lada.validation.annotation.ValidationRule;
f44c9e59f08c Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
8 import de.intevation.lada.validation.annotation.ValidationConfig;
f44c9e59f08c Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
9 import de.intevation.lada.validation.rules.Rule;
f44c9e59f08c Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
10
f44c9e59f08c Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
11 @ValidationConfig(type="Probe")
f44c9e59f08c Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
12 @ApplicationScoped
f44c9e59f08c Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
13 public class ProbeValidator implements Validator {
f44c9e59f08c Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
14
f44c9e59f08c Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
15 @Inject
f44c9e59f08c Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
16 @ValidationRule("Probe")
f44c9e59f08c Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
17 private Instance<Rule> rules;
f44c9e59f08c Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
18
f44c9e59f08c Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
19 @Override
f44c9e59f08c Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
20 public Violation validate(Object object) {
f44c9e59f08c Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
21 Violation violations = new Violation();
f44c9e59f08c Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
22 for(Rule rule: rules) {
f44c9e59f08c Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
23 Violation result = rule.execute(object);
f44c9e59f08c Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
24 if (result != null) {
f44c9e59f08c Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
25 if (result.hasWarnings()) {
f44c9e59f08c Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
26 violations.addWarnings(result.getWarnings());
f44c9e59f08c Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
27 }
f44c9e59f08c Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
28 if (result.hasErrors()) {
f44c9e59f08c Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
29 violations.addErrors(result.getErrors());
f44c9e59f08c Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
30 }
f44c9e59f08c Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
31 }
f44c9e59f08c Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
32 }
f44c9e59f08c Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
33 return violations;
f44c9e59f08c Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
34 }
f44c9e59f08c Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
35 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)