Mercurial > lada > lada-server
annotate 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 |
rev | line source |
---|---|
982
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
1 /* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
2 * Software engineering by Intevation GmbH |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
3 * |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
4 * This file is Free Software under the GNU GPL (v>=3) |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
6 * the documentation coming with IMIS-Labordaten-Application for details. |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
7 */ |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
8 package de.intevation.lada.validation; |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
9 |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
10 import javax.enterprise.context.ApplicationScoped; |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
11 import javax.enterprise.inject.Instance; |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
12 import javax.inject.Inject; |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
13 |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
14 import de.intevation.lada.model.land.Messprogramm; |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
15 import de.intevation.lada.validation.annotation.ValidationConfig; |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
16 import de.intevation.lada.validation.annotation.ValidationRule; |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
17 import de.intevation.lada.validation.rules.Rule; |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
18 |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
19 /** |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
20 * Validation for Messprogramm objects. |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
21 * |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
22 * Instantiates the set of rules for Messprogramm objects |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
23 * and uses these rules to validate the object. |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
24 * |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
25 */ |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
26 @ValidationConfig(type="Messprogramm") |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
27 @ApplicationScoped |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
28 public class MessprogrammValidator implements Validator { |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
29 |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
30 @Inject |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
31 @ValidationRule("Messprogramm") |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
32 private Instance<Rule> rules; |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
33 |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
34 @Override |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
35 public Violation validate(Object object) { |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
36 Violation violations = new Violation(); |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
37 if (!(object instanceof Messprogramm)) { |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
38 violations.addError("messprogramm", 602); |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
39 return violations; |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
40 } |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
41 for(Rule rule: rules) { |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
42 Violation result = rule.execute(object); |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
43 if (result != null) { |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
44 if (result.hasWarnings()) { |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
45 violations.addWarnings(result.getWarnings()); |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
46 } |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
47 if (result.hasErrors()) { |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
48 violations.addErrors(result.getErrors()); |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
49 } |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
50 } |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
51 } |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
52 return violations; |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
53 } |
962439442e48
Check mandatory fields before saving a Messprogramm.
Tom Gottfried <tom@intevation.de>
parents:
diff
changeset
|
54 } |