Mercurial > lada > lada-server
comparison src/main/java/de/intevation/lada/validation/rules/ortszuordnung/CoordinatesInVE.java @ 1224:73ad827faa81
Rename validation of Ortszuordnung.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Fri, 09 Dec 2016 15:34:15 +0100 |
parents | src/main/java/de/intevation/lada/validation/rules/ort/CoordinatesInVE.java@b3331bc71f30 |
children |
comparison
equal
deleted
inserted
replaced
1223:9b8b18c00804 | 1224:73ad827faa81 |
---|---|
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 com.vividsolutions.jts.geom.Point; | |
15 | |
16 import de.intevation.lada.model.land.Ortszuordnung; | |
17 import de.intevation.lada.model.stammdaten.Ort; | |
18 import de.intevation.lada.model.stammdaten.Verwaltungseinheit; | |
19 import de.intevation.lada.model.stammdaten.Verwaltungsgrenze; | |
20 import de.intevation.lada.util.annotation.RepositoryConfig; | |
21 import de.intevation.lada.util.data.QueryBuilder; | |
22 import de.intevation.lada.util.data.Repository; | |
23 import de.intevation.lada.util.data.RepositoryType; | |
24 import de.intevation.lada.validation.Violation; | |
25 import de.intevation.lada.validation.annotation.ValidationRule; | |
26 import de.intevation.lada.validation.rules.Rule; | |
27 | |
28 /** | |
29 * Validation rule for ort. | |
30 * Validates if the coordinates are in the specified "Verwaltungseinheit". | |
31 * | |
32 * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> | |
33 */ | |
34 @ValidationRule("Ortszuordnung") | |
35 public class CoordinatesInVE implements Rule { | |
36 | |
37 @Inject | |
38 @RepositoryConfig(type=RepositoryType.RO) | |
39 private Repository repository; | |
40 | |
41 @SuppressWarnings("unchecked") | |
42 @Override | |
43 public Violation execute(Object object) { | |
44 Ortszuordnung oz = (Ortszuordnung)object; | |
45 if (!"E".equals(oz.getOrtszuordnungTyp())) { | |
46 return null; | |
47 } | |
48 | |
49 Ort ort = repository.getByIdPlain(Ort.class, oz.getOrtId(), "stamm"); | |
50 String gemId = ort.getGemId(); | |
51 if (gemId == null) { | |
52 Violation violation = new Violation(); | |
53 violation.addWarning("gemId", 631); | |
54 return violation; | |
55 } | |
56 | |
57 QueryBuilder<Verwaltungsgrenze> vg = | |
58 new QueryBuilder<Verwaltungsgrenze>( | |
59 repository.entityManager("stamm"), Verwaltungsgrenze.class); | |
60 vg.and("gemId", gemId); | |
61 List<Verwaltungsgrenze> vgs = repository.filterPlain( | |
62 vg.getQuery(), "stamm"); | |
63 if (vgs == null || vgs.isEmpty()) { | |
64 Violation violation = new Violation(); | |
65 violation.addWarning("verwaltungsgrenze", 600); | |
66 return violation; | |
67 } | |
68 | |
69 Point p = ort.getGeom(); | |
70 boolean hit = false; | |
71 for (Verwaltungsgrenze singlevg : vgs) { | |
72 if(singlevg.getShape().contains(p)) { | |
73 hit = true; | |
74 } | |
75 } | |
76 if (!hit) { | |
77 Violation violation = new Violation(); | |
78 violation.addWarning("verwaltungsgrenze", 651); | |
79 return violation; | |
80 } | |
81 return null; | |
82 } | |
83 | |
84 } |