Mercurial > lada > lada-server
comparison src/main/java/de/intevation/lada/validation/rules/probe/UniqueHauptprobenNr.java @ 538:fd927b584c54
Added first validation rules for probe objects.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Tue, 24 Feb 2015 10:58:06 +0100 |
parents | |
children | 7a97e4b1cc18 |
comparison
equal
deleted
inserted
replaced
537:f44c9e59f08c | 538:fd927b584c54 |
---|---|
1 package de.intevation.lada.validation.rules.probe; | |
2 | |
3 import java.util.List; | |
4 | |
5 import javax.inject.Inject; | |
6 | |
7 import de.intevation.lada.model.land.LProbe; | |
8 import de.intevation.lada.util.annotation.RepositoryConfig; | |
9 import de.intevation.lada.util.data.QueryBuilder; | |
10 import de.intevation.lada.util.data.Repository; | |
11 import de.intevation.lada.util.data.RepositoryType; | |
12 import de.intevation.lada.util.rest.Response; | |
13 import de.intevation.lada.validation.Violation; | |
14 import de.intevation.lada.validation.annotation.ValidationRule; | |
15 import de.intevation.lada.validation.rules.Rule; | |
16 | |
17 @ValidationRule("Probe") | |
18 public class UniqueHauptprobenNr implements Rule { | |
19 | |
20 @Inject | |
21 @RepositoryConfig(type=RepositoryType.RO) | |
22 private Repository repo; | |
23 | |
24 @SuppressWarnings("unchecked") | |
25 @Override | |
26 public Violation execute(Object object) { | |
27 LProbe probe = (LProbe)object; | |
28 QueryBuilder<LProbe> builder = new QueryBuilder<LProbe>( | |
29 repo.entityManager("land"), | |
30 LProbe.class); | |
31 builder.and("hauptprobenNr", probe.getHauptprobenNr()); | |
32 Response response = repo.filter(builder.getQuery(), "land"); | |
33 if (!((List<LProbe>)response.getData()).isEmpty()) { | |
34 LProbe found = ((List<LProbe>)response.getData()).get(0); | |
35 // The probe found in the db equals the new probe. (Update) | |
36 if (probe.getId() != null && probe.getId() == found.getId()) { | |
37 return null; | |
38 } | |
39 Violation violation = new Violation(); | |
40 violation.addError("hauptprobenNr", 611); | |
41 return violation; | |
42 } | |
43 return null; | |
44 } | |
45 | |
46 } |