# HG changeset patch # User Raimund Renkert # Date 1485529972 -3600 # Node ID 3cdf75a9bf9245ac30febce87f0b0cc5c031dd0c # Parent 7ae0fa505abbcfcd90503484211de78d9fbb51c2 Check for entnahmeOrt in messprogramm and add error if missing. diff -r 7ae0fa505abb -r 3cdf75a9bf92 src/main/java/de/intevation/lada/validation/rules/messprogramm/HasAllMandatory.java --- a/src/main/java/de/intevation/lada/validation/rules/messprogramm/HasAllMandatory.java Fri Jan 27 15:55:08 2017 +0100 +++ b/src/main/java/de/intevation/lada/validation/rules/messprogramm/HasAllMandatory.java Fri Jan 27 16:12:52 2017 +0100 @@ -7,7 +7,16 @@ */ package de.intevation.lada.validation.rules.messprogramm; +import java.util.List; + +import javax.inject.Inject; + import de.intevation.lada.model.land.Messprogramm; +import de.intevation.lada.model.land.OrtszuordnungMp; +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.validation.Violation; import de.intevation.lada.validation.annotation.ValidationRule; import de.intevation.lada.validation.rules.Rule; @@ -19,6 +28,10 @@ @ValidationRule("Messprogramm") public class HasAllMandatory implements Rule { + @Inject + @RepositoryConfig(type=RepositoryType.RO) + Repository repository; + @Override public Violation execute(Object object) { Messprogramm messprogramm = (Messprogramm)object; @@ -54,6 +67,21 @@ if (messprogramm.getGueltigBis() == null) { violation.addError("gueltigBis", 631); } + QueryBuilder builder = + new QueryBuilder( + repository.entityManager("land"), + OrtszuordnungMp.class); + List orte = repository.filterPlain( + builder.getQuery(), "land"); + boolean found = false; + for (OrtszuordnungMp ort : orte) { + if ("E".equals(ort.getOrtszuordnungTyp())) { + found = true; + } + } + if (!found) { + violation.addError("entnahmeOrt", 631); + } return violation.hasErrors() ? violation