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