Mercurial > lada > lada-server
changeset 360:f3c58d3c4bc7
Validate that lat/lon coordinates are within the geometry of verwaltungseinheit.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Thu, 05 Sep 2013 17:24:10 +0200 |
parents | 3df000288b45 |
children | c0357bd00666 |
files | src/main/java/de/intevation/lada/validation/LOrtValidator.java |
diffstat | 1 files changed, 63 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/validation/LOrtValidator.java Thu Sep 05 17:22:44 2013 +0200 +++ b/src/main/java/de/intevation/lada/validation/LOrtValidator.java Thu Sep 05 17:24:10 2013 +0200 @@ -1,18 +1,40 @@ package de.intevation.lada.validation; import java.util.HashMap; +import java.util.List; import java.util.Map; import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; import javax.inject.Named; +import com.vividsolutions.jts.geom.Coordinate; +import com.vividsolutions.jts.geom.CoordinateSequence; +import com.vividsolutions.jts.geom.GeometryFactory; +import com.vividsolutions.jts.geom.Point; +import com.vividsolutions.jts.geom.PrecisionModel; + +import de.intevation.lada.data.QueryBuilder; +import de.intevation.lada.data.Repository; +import de.intevation.lada.model.DeVg; import de.intevation.lada.model.LOrt; +import de.intevation.lada.model.Ort; +import de.intevation.lada.model.SVerwaltungseinheit; +import de.intevation.lada.rest.Response; @ApplicationScoped @Named("lortvalidator") public class LOrtValidator implements Validator { + @Inject + @Named("readonlyrepository") + private Repository readonlyRepo; + + @Inject + @Named("ortrepository") + private Repository ortRepo; + /** * Validate a LOrt object. * @@ -31,9 +53,49 @@ errors.put("lort", 610); throw new ValidationException(errors); } - + LOrt ort = (LOrt)object; + validateVerwaltungseinheit(ort, warnings); //TODO: more validation, see LSB: VI - Konsistenzregeln return warnings; } + private void validateVerwaltungseinheit(LOrt ort, Map<String, Integer> warnings) { + if (!ort.getOrtsTyp().equals("E")) { + return; + } + QueryBuilder<Ort> ortBuilder = + new QueryBuilder<Ort>(ortRepo.getEntityManager(), Ort.class); + ortBuilder.and("ortId", ort.getOrtId()); + Response response = ortRepo.filter(ortBuilder.getQuery()); + List<Ort> orte = (List<Ort>)response.getData(); + QueryBuilder<SVerwaltungseinheit> veBuilder = + new QueryBuilder<SVerwaltungseinheit>( + readonlyRepo.getEntityManager(), SVerwaltungseinheit.class); + veBuilder.and("gemId", orte.get(0).getGemId()); + Response ver = readonlyRepo.filter(veBuilder.getQuery()); + SVerwaltungseinheit ve = ((List<SVerwaltungseinheit>)ver.getData()).get(0); + QueryBuilder<DeVg> vg = + new QueryBuilder<DeVg>(readonlyRepo.getEntityManager(), DeVg.class); + vg.and("ags", ve.getGemId()); + Response rvg = readonlyRepo.filter(vg.getQuery()); + List<DeVg> vgs = (List<DeVg>)rvg.getData(); + if (vgs == null || vgs.isEmpty()) { + warnings.put("verwaltungseinheit", 653); + return; + } + double y = orte.get(0).getLatitude(); + double x = orte.get(0).getLongitude(); + Coordinate c = new Coordinate(x, y); + GeometryFactory gf = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING), 4326); + Point p = gf.createPoint(c); + boolean hit = false; + for (DeVg singlevg : vgs) { + if(singlevg.getGeom().contains(p)) { + hit = true; + } + } + if (!hit) { + warnings.put("verwaltungseinheit", 651); + } + } }