Mercurial > lada > lada-server
comparison src/main/java/de/intevation/lada/validation/StatusValidator.java @ 780:ec231b0c343d
Added validator and first rule for status.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Fri, 13 Nov 2015 13:42:25 +0100 |
parents | |
children | 1c41c7b8f7c2 |
comparison
equal
deleted
inserted
replaced
779:64adf06df02f | 780:ec231b0c343d |
---|---|
1 /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz | |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU GPL (v>=3) | |
5 * and comes with ABSOLUTELY NO WARRANTY! Check out | |
6 * the documentation coming with IMIS-Labordaten-Application for details. | |
7 */ | |
8 package de.intevation.lada.validation; | |
9 | |
10 import javax.enterprise.context.ApplicationScoped; | |
11 import javax.enterprise.inject.Instance; | |
12 import javax.inject.Inject; | |
13 | |
14 import de.intevation.lada.model.land.LStatusProtokoll; | |
15 import de.intevation.lada.validation.annotation.ValidationConfig; | |
16 import de.intevation.lada.validation.annotation.ValidationRule; | |
17 import de.intevation.lada.validation.rules.Rule; | |
18 | |
19 /** | |
20 * Validation for messung objects. | |
21 * | |
22 * Instantiates the set of rules for messung objects and uses these rules to | |
23 * validate the object. | |
24 * | |
25 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | |
26 */ | |
27 @ValidationConfig(type="Status") | |
28 @ApplicationScoped | |
29 public class StatusValidator implements Validator { | |
30 | |
31 @Inject | |
32 @ValidationRule("Status") | |
33 private Instance<Rule> rules; | |
34 | |
35 @Override | |
36 public Violation validate(Object object) { | |
37 Violation violations = new Violation(); | |
38 if (!(object instanceof LStatusProtokoll)) { | |
39 violations.addError("status", 602); | |
40 return violations; | |
41 } | |
42 for(Rule rule: rules) { | |
43 Violation result = rule.execute(object); | |
44 if (result != null) { | |
45 if (result.hasWarnings()) { | |
46 violations.addWarnings(result.getWarnings()); | |
47 } | |
48 if (result.hasErrors()) { | |
49 violations.addErrors(result.getErrors()); | |
50 } | |
51 } | |
52 } | |
53 return violations; | |
54 } | |
55 } |