Mercurial > lada > lada-server
changeset 677:de47b7193bdb
Fixed validation rules.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Fri, 22 May 2015 15:15:14 +0200 |
parents | ab539e3f186d |
children | 328865fa3db7 |
files | src/main/java/de/intevation/lada/validation/rules/messung/Date.java src/main/java/de/intevation/lada/validation/rules/messung/HasPflichtmessgroessen.java src/main/java/de/intevation/lada/validation/rules/messung/MessgroesseToMessmethode.java src/main/java/de/intevation/lada/validation/rules/ort/CoordinatesInVE.java src/main/java/de/intevation/lada/validation/rules/probe/HasEntnahmeOrt.java |
diffstat | 5 files changed, 90 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/validation/rules/messung/Date.java Fri May 22 15:14:54 2015 +0200 +++ b/src/main/java/de/intevation/lada/validation/rules/messung/Date.java Fri May 22 15:15:14 2015 +0200 @@ -1,7 +1,6 @@ package de.intevation.lada.validation.rules.messung; import java.util.HashMap; -import java.util.List; import java.util.Map; import javax.inject.Inject; @@ -28,17 +27,15 @@ LMessung messung = (LMessung)object; Integer probeId = messung.getProbeId(); Response response = repository.getById(LProbe.class, probeId, "land"); - @SuppressWarnings("unchecked") - List<LProbe> list = (List<LProbe>) response.getData(); - if (list.isEmpty()) { + LProbe probe = (LProbe) response.getData(); + if (probe == null) { Map<String, Integer> errors = new HashMap<String, Integer>(); errors.put("lprobe", 604); } - LProbe probe = list.get(0); if (probe.getProbeentnahmeEnde() == null || probe.getProbeentnahmeEnde().after(messung.getMesszeitpunkt())) { Violation violation = new Violation(); - violation.addWarning("messzeitpunkt", 661); + violation.addWarning("messzeitpunkt", 632); return violation; } return null;
--- a/src/main/java/de/intevation/lada/validation/rules/messung/HasPflichtmessgroessen.java Fri May 22 15:14:54 2015 +0200 +++ b/src/main/java/de/intevation/lada/validation/rules/messung/HasPflichtmessgroessen.java Fri May 22 15:15:14 2015 +0200 @@ -38,8 +38,7 @@ QueryBuilder<LMesswert> wertBuilder = new QueryBuilder<LMesswert>( repository.entityManager("land"), LMesswert.class); - wertBuilder.and("messungsId", messung.getId()) - .and("probeId", messung.getProbeId()); + wertBuilder.and("messungsId", messung.getId()); Response wertResponse = repository.filter(wertBuilder.getQuery(), "land"); List<LMesswert> messwerte = (List<LMesswert>)wertResponse.getData();
--- a/src/main/java/de/intevation/lada/validation/rules/messung/MessgroesseToMessmethode.java Fri May 22 15:14:54 2015 +0200 +++ b/src/main/java/de/intevation/lada/validation/rules/messung/MessgroesseToMessmethode.java Fri May 22 15:15:14 2015 +0200 @@ -1,9 +1,12 @@ package de.intevation.lada.validation.rules.messung; +import java.util.ArrayList; import java.util.List; import javax.inject.Inject; +import org.apache.log4j.Logger; + import de.intevation.lada.model.land.LMessung; import de.intevation.lada.model.land.LMesswert; import de.intevation.lada.model.stamm.MmtMessgroesse; @@ -20,6 +23,9 @@ public class MessgroesseToMessmethode implements Rule { @Inject + private Logger logger; + + @Inject @RepositoryConfig(type=RepositoryType.RO) private Repository repository; @@ -30,26 +36,32 @@ QueryBuilder<LMesswert> builder = new QueryBuilder<LMesswert>( repository.entityManager("land"), LMesswert.class); - builder.and("messungsId", messung.getId()) - .and("probeId", messung.getProbeId()); + builder.and("messungsId", messung.getId()); Response response = repository.filter(builder.getQuery(), "land"); List<LMesswert> messwerte = (List<LMesswert>)response.getData(); QueryBuilder<MmtMessgroesse> mmtBuilder = new QueryBuilder<MmtMessgroesse>( repository.entityManager("stamm"), MmtMessgroesse.class); - builder.and("mmtId", mmt); Response results = repository.filter(mmtBuilder.getQuery(), "stamm"); List<MmtMessgroesse> messgroessen = (List<MmtMessgroesse>)results.getData(); + List<MmtMessgroesse> found = new ArrayList<MmtMessgroesse>(); + for (MmtMessgroesse mg: messgroessen) { + if (mmt.equals(mg.getMmtMessgroessePK().getMmtId())) { + logger.debug("found: " + mg.getMmtMessgroessePK().getMmtId() + " for " + mmt); + found.add(mg); + } + } Violation violation = new Violation(); for(LMesswert messwert: messwerte) { boolean hit = false; - for (MmtMessgroesse messgroesse: messgroessen) { + for (MmtMessgroesse messgroesse: found) { + logger.debug("###### mmt: " + messwert.getMessgroesseId() + " mmtmg: " + messgroesse.getMmtMessgroessePK().getMessgroessengruppeId()); if (messwert.getMessgroesseId().equals( - messgroesse.getMmtMessgroessePK().getMmtId().toString())) { + messgroesse.getMmtMessgroessePK().getMessgroessengruppeId())) { hit = true; } }
--- a/src/main/java/de/intevation/lada/validation/rules/ort/CoordinatesInVE.java Fri May 22 15:14:54 2015 +0200 +++ b/src/main/java/de/intevation/lada/validation/rules/ort/CoordinatesInVE.java Fri May 22 15:15:14 2015 +0200 @@ -1,5 +1,23 @@ package de.intevation.lada.validation.rules.ort; +import java.util.List; + +import javax.inject.Inject; + +import com.vividsolutions.jts.geom.Coordinate; +import com.vividsolutions.jts.geom.GeometryFactory; +import com.vividsolutions.jts.geom.Point; +import com.vividsolutions.jts.geom.PrecisionModel; + +import de.intevation.lada.model.land.LOrt; +import de.intevation.lada.model.stamm.DeVg; +import de.intevation.lada.model.stamm.SOrt; +import de.intevation.lada.model.stamm.Verwaltungseinheit; +import de.intevation.lada.util.annotation.RepositoryConfig; +import de.intevation.lada.util.data.QueryBuilder; +import de.intevation.lada.util.data.Repository; +import de.intevation.lada.util.data.RepositoryType; +import de.intevation.lada.util.rest.Response; import de.intevation.lada.validation.Violation; import de.intevation.lada.validation.annotation.ValidationRule; import de.intevation.lada.validation.rules.Rule; @@ -7,9 +25,58 @@ @ValidationRule("Ort") public class CoordinatesInVE implements Rule { + @Inject + @RepositoryConfig(type=RepositoryType.RO) + private Repository repository; + @Override public Violation execute(Object object) { - // TODO + LOrt ort = (LOrt)object; + if (!"E".equals(ort.getOrtsTyp())) { + return null; + } + QueryBuilder<SOrt> ortBuilder = + new QueryBuilder<SOrt>(repository.entityManager("stamm"), SOrt.class); + ortBuilder.and("id", ort.getOrt()); + Response response = repository.filter(ortBuilder.getQuery(), "stamm"); + List<SOrt> orte = (List<SOrt>)response.getData(); + QueryBuilder<Verwaltungseinheit> veBuilder = + new QueryBuilder<Verwaltungseinheit>( + repository.entityManager("stamm"), Verwaltungseinheit.class); + veBuilder.and("id", orte.get(0).getVerwaltungseinheitId()); + Response ver = repository.filter(veBuilder.getQuery(), "stamm"); + if (((List<Verwaltungseinheit>)ver.getData()).isEmpty()) { + Violation violation = new Violation(); + violation.addWarning("verwaltungseinheit", 653); + return violation; + } + Verwaltungseinheit ve = ((List<Verwaltungseinheit>)ver.getData()).get(0); + QueryBuilder<DeVg> vg = + new QueryBuilder<DeVg>(repository.entityManager("stamm"), DeVg.class); + vg.and("ags", ve.getId()); + Response rvg = repository.filter(vg.getQuery(), "stamm"); + List<DeVg> vgs = (List<DeVg>)rvg.getData(); + if (vgs == null || vgs.isEmpty()) { + Violation violation = new Violation(); + violation.addWarning("verwaltungseinheit", 653); + return violation; + } + 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) { + Violation violation = new Violation(); + violation.addWarning("verwaltungseinheit", 651); + return violation; + } return null; }
--- a/src/main/java/de/intevation/lada/validation/rules/probe/HasEntnahmeOrt.java Fri May 22 15:14:54 2015 +0200 +++ b/src/main/java/de/intevation/lada/validation/rules/probe/HasEntnahmeOrt.java Fri May 22 15:15:14 2015 +0200 @@ -38,7 +38,7 @@ @SuppressWarnings("unchecked") List<LOrt> orte = (List<LOrt>)response.getData(); for (LOrt ort: orte) { - if (ort.getOrtsTyp().equals("E")) { + if ("E".equals(ort.getOrtsTyp())) { return null; } }