Mercurial > lada > lada-server
annotate src/main/java/de/intevation/lada/validation/ProbeValidator.java @ 540:7925f5eda6c4
Validate the object is a probe.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Tue, 24 Feb 2015 14:57:24 +0100 |
parents | f44c9e59f08c |
children | 3ec358698b4d |
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 |
540
7925f5eda6c4
Validate the object is a probe.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
537
diff
changeset
|
7 import de.intevation.lada.model.land.LProbe; |
7925f5eda6c4
Validate the object is a probe.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
537
diff
changeset
|
8 import de.intevation.lada.validation.annotation.ValidationConfig; |
537
f44c9e59f08c
Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
9 import de.intevation.lada.validation.annotation.ValidationRule; |
f44c9e59f08c
Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
10 import de.intevation.lada.validation.rules.Rule; |
f44c9e59f08c
Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
11 |
f44c9e59f08c
Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
12 @ValidationConfig(type="Probe") |
f44c9e59f08c
Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
13 @ApplicationScoped |
f44c9e59f08c
Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
14 public class ProbeValidator implements Validator { |
f44c9e59f08c
Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
15 |
f44c9e59f08c
Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
16 @Inject |
f44c9e59f08c
Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
17 @ValidationRule("Probe") |
f44c9e59f08c
Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
18 private Instance<Rule> rules; |
f44c9e59f08c
Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
19 |
f44c9e59f08c
Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
20 @Override |
f44c9e59f08c
Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
21 public Violation validate(Object object) { |
f44c9e59f08c
Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
22 Violation violations = new Violation(); |
540
7925f5eda6c4
Validate the object is a probe.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
537
diff
changeset
|
23 if (!(object instanceof LProbe)) { |
7925f5eda6c4
Validate the object is a probe.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
537
diff
changeset
|
24 violations.addError("probe", 602); |
7925f5eda6c4
Validate the object is a probe.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
537
diff
changeset
|
25 return violations; |
7925f5eda6c4
Validate the object is a probe.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
537
diff
changeset
|
26 } |
537
f44c9e59f08c
Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
27 for(Rule rule: rules) { |
f44c9e59f08c
Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
28 Violation result = rule.execute(object); |
f44c9e59f08c
Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
29 if (result != null) { |
f44c9e59f08c
Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
30 if (result.hasWarnings()) { |
f44c9e59f08c
Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
31 violations.addWarnings(result.getWarnings()); |
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 if (result.hasErrors()) { |
f44c9e59f08c
Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
34 violations.addErrors(result.getErrors()); |
f44c9e59f08c
Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
35 } |
f44c9e59f08c
Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
36 } |
f44c9e59f08c
Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
37 } |
f44c9e59f08c
Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
38 return violations; |
f44c9e59f08c
Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
39 } |
f44c9e59f08c
Added validator for probe objects.
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
40 } |