Mercurial > lada > lada-server
comparison src/main/java/de/intevation/lada/validation/MessprogrammValidator.java @ 982:962439442e48
Check mandatory fields before saving a Messprogramm.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Mon, 27 Jun 2016 17:04:02 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
981:84f17f460969 | 982:962439442e48 |
---|---|
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.Messprogramm; | |
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 Messprogramm objects. | |
21 * | |
22 * Instantiates the set of rules for Messprogramm objects | |
23 * and uses these rules to validate the object. | |
24 * | |
25 */ | |
26 @ValidationConfig(type="Messprogramm") | |
27 @ApplicationScoped | |
28 public class MessprogrammValidator implements Validator { | |
29 | |
30 @Inject | |
31 @ValidationRule("Messprogramm") | |
32 private Instance<Rule> rules; | |
33 | |
34 @Override | |
35 public Violation validate(Object object) { | |
36 Violation violations = new Violation(); | |
37 if (!(object instanceof Messprogramm)) { | |
38 violations.addError("messprogramm", 602); | |
39 return violations; | |
40 } | |
41 for(Rule rule: rules) { | |
42 Violation result = rule.execute(object); | |
43 if (result != null) { | |
44 if (result.hasWarnings()) { | |
45 violations.addWarnings(result.getWarnings()); | |
46 } | |
47 if (result.hasErrors()) { | |
48 violations.addErrors(result.getErrors()); | |
49 } | |
50 } | |
51 } | |
52 return violations; | |
53 } | |
54 } |