Mercurial > lada > lada-server
comparison src/main/java/de/intevation/lada/validation/rules/ort/OrtTypExists.java @ 1276:efa50b39c7cc
Validate type of an Ort object.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 02 Feb 2017 15:01:12 +0100 |
parents | |
children | 15700d7c00eb |
comparison
equal
deleted
inserted
replaced
1275:a356b818389a | 1276:efa50b39c7cc |
---|---|
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.rules.ort; | |
9 | |
10 import java.util.List; | |
11 | |
12 import javax.inject.Inject; | |
13 | |
14 import de.intevation.lada.model.stammdaten.Ort; | |
15 import de.intevation.lada.model.stammdaten.OrtTyp; | |
16 import de.intevation.lada.util.annotation.RepositoryConfig; | |
17 import de.intevation.lada.util.data.QueryBuilder; | |
18 import de.intevation.lada.util.data.Repository; | |
19 import de.intevation.lada.util.data.RepositoryType; | |
20 import de.intevation.lada.validation.Violation; | |
21 import de.intevation.lada.validation.annotation.ValidationRule; | |
22 import de.intevation.lada.validation.rules.Rule; | |
23 | |
24 /** | |
25 * Validation rule for ort. | |
26 * Validates if the a given OrtTyp exists. | |
27 * | |
28 */ | |
29 @ValidationRule("Ort") | |
30 public class OrtTypExists implements Rule { | |
31 | |
32 @Inject | |
33 @RepositoryConfig(type=RepositoryType.RO) | |
34 private Repository repository; | |
35 | |
36 @Override | |
37 public Violation execute(Object object) { | |
38 Ort ort = (Ort)object; | |
39 | |
40 QueryBuilder<OrtTyp> builder = | |
41 new QueryBuilder<OrtTyp>( | |
42 repository.entityManager("stamm"), | |
43 OrtTyp.class); | |
44 builder.and("id", ort.getOrtTyp()); | |
45 List<OrtTyp> ots = repository.filterPlain( | |
46 builder.getQuery(), "stamm"); | |
47 if (ots == null || ots.isEmpty()) { | |
48 Violation violation = new Violation(); | |
49 violation.addError("ortTyp", 612); | |
50 return violation; | |
51 } | |
52 | |
53 return null; | |
54 } | |
55 | |
56 } |