Mercurial > lada > lada-server
changeset 1224:73ad827faa81
Rename validation of Ortszuordnung.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Fri, 09 Dec 2016 15:34:15 +0100 |
parents | 9b8b18c00804 |
children | 2bc06e7f6fb5 |
files | src/main/java/de/intevation/lada/rest/OrtService.java src/main/java/de/intevation/lada/validation/OrtValidator.java src/main/java/de/intevation/lada/validation/OrtszuordnungValidator.java src/main/java/de/intevation/lada/validation/rules/ort/CoordinatesInVE.java src/main/java/de/intevation/lada/validation/rules/ort/EntnahmeortToVE.java src/main/java/de/intevation/lada/validation/rules/ort/HasEntnahmeOrt.java src/main/java/de/intevation/lada/validation/rules/ortszuordnung/CoordinatesInVE.java src/main/java/de/intevation/lada/validation/rules/ortszuordnung/EntnahmeortToVE.java src/main/java/de/intevation/lada/validation/rules/ortszuordnung/HasEntnahmeOrt.java |
diffstat | 9 files changed, 220 insertions(+), 220 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/rest/OrtService.java Fri Dec 09 14:57:17 2016 +0100 +++ b/src/main/java/de/intevation/lada/rest/OrtService.java Fri Dec 09 15:34:15 2016 +0100 @@ -108,7 +108,7 @@ private Authorization authorization; @Inject - @ValidationConfig(type="Ort") + @ValidationConfig(type="Ortszuordnung") private Validator validator; /**
--- a/src/main/java/de/intevation/lada/validation/OrtValidator.java Fri Dec 09 14:57:17 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz - * Software engineering by Intevation GmbH - * - * This file is Free Software under the GNU GPL (v>=3) - * and comes with ABSOLUTELY NO WARRANTY! Check out - * the documentation coming with IMIS-Labordaten-Application for details. - */ -package de.intevation.lada.validation; - -import javax.enterprise.context.ApplicationScoped; -import javax.enterprise.inject.Instance; -import javax.inject.Inject; - -import de.intevation.lada.model.land.Ortszuordnung; -import de.intevation.lada.validation.annotation.ValidationConfig; -import de.intevation.lada.validation.annotation.ValidationRule; -import de.intevation.lada.validation.rules.Rule; - -/** - * Validation for ort objects. - * - * Instantiates the set of rules for ort objects and uses these rules to - * validate the object. - * - * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> - */ -@ValidationConfig(type="Ort") -@ApplicationScoped -public class OrtValidator implements Validator { - - @Inject - @ValidationRule("Ort") - private Instance<Rule> rules; - - @Override - public Violation validate(Object object) { - Violation violations = new Violation(); - if (!(object instanceof Ortszuordnung)) { - violations.addError("ort", 602); - return violations; - } - for(Rule rule: rules) { - Violation result = rule.execute(object); - if (result != null) { - if (result.hasWarnings()) { - violations.addWarnings(result.getWarnings()); - } - if (result.hasErrors()) { - violations.addErrors(result.getErrors()); - } - } - } - return violations; - } - -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/validation/OrtszuordnungValidator.java Fri Dec 09 15:34:15 2016 +0100 @@ -0,0 +1,56 @@ +/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU GPL (v>=3) + * and comes with ABSOLUTELY NO WARRANTY! Check out + * the documentation coming with IMIS-Labordaten-Application for details. + */ +package de.intevation.lada.validation; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Instance; +import javax.inject.Inject; + +import de.intevation.lada.model.land.Ortszuordnung; +import de.intevation.lada.validation.annotation.ValidationConfig; +import de.intevation.lada.validation.annotation.ValidationRule; +import de.intevation.lada.validation.rules.Rule; + +/** + * Validation for ort objects. + * + * Instantiates the set of rules for ort objects and uses these rules to + * validate the object. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +@ValidationConfig(type="Ortszuordnung") +@ApplicationScoped +public class OrtszuordnungValidator implements Validator { + + @Inject + @ValidationRule("Ortszuordnung") + private Instance<Rule> rules; + + @Override + public Violation validate(Object object) { + Violation violations = new Violation(); + if (!(object instanceof Ortszuordnung)) { + violations.addError("ortszuordnung", 602); + return violations; + } + for(Rule rule: rules) { + Violation result = rule.execute(object); + if (result != null) { + if (result.hasWarnings()) { + violations.addWarnings(result.getWarnings()); + } + if (result.hasErrors()) { + violations.addErrors(result.getErrors()); + } + } + } + return violations; + } + +}
--- a/src/main/java/de/intevation/lada/validation/rules/ort/CoordinatesInVE.java Fri Dec 09 14:57:17 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,84 +0,0 @@ -/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz - * Software engineering by Intevation GmbH - * - * This file is Free Software under the GNU GPL (v>=3) - * and comes with ABSOLUTELY NO WARRANTY! Check out - * the documentation coming with IMIS-Labordaten-Application for details. - */ -package de.intevation.lada.validation.rules.ort; - -import java.util.List; - -import javax.inject.Inject; - -import com.vividsolutions.jts.geom.Point; - -import de.intevation.lada.model.land.Ortszuordnung; -import de.intevation.lada.model.stammdaten.Ort; -import de.intevation.lada.model.stammdaten.Verwaltungseinheit; -import de.intevation.lada.model.stammdaten.Verwaltungsgrenze; -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; - -/** - * Validation rule for ort. - * Validates if the coordinates are in the specified "Verwaltungseinheit". - * - * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> - */ -@ValidationRule("Ort") -public class CoordinatesInVE implements Rule { - - @Inject - @RepositoryConfig(type=RepositoryType.RO) - private Repository repository; - - @SuppressWarnings("unchecked") - @Override - public Violation execute(Object object) { - Ortszuordnung oz = (Ortszuordnung)object; - if (!"E".equals(oz.getOrtszuordnungTyp())) { - return null; - } - - Ort ort = repository.getByIdPlain(Ort.class, oz.getOrtId(), "stamm"); - String gemId = ort.getGemId(); - if (gemId == null) { - Violation violation = new Violation(); - violation.addWarning("gemId", 631); - return violation; - } - - QueryBuilder<Verwaltungsgrenze> vg = - new QueryBuilder<Verwaltungsgrenze>( - repository.entityManager("stamm"), Verwaltungsgrenze.class); - vg.and("gemId", gemId); - List<Verwaltungsgrenze> vgs = repository.filterPlain( - vg.getQuery(), "stamm"); - if (vgs == null || vgs.isEmpty()) { - Violation violation = new Violation(); - violation.addWarning("verwaltungsgrenze", 600); - return violation; - } - - Point p = ort.getGeom(); - boolean hit = false; - for (Verwaltungsgrenze singlevg : vgs) { - if(singlevg.getShape().contains(p)) { - hit = true; - } - } - if (!hit) { - Violation violation = new Violation(); - violation.addWarning("verwaltungsgrenze", 651); - return violation; - } - return null; - } - -}
--- a/src/main/java/de/intevation/lada/validation/rules/ort/EntnahmeortToVE.java Fri Dec 09 14:57:17 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz - * Software engineering by Intevation GmbH - * - * This file is Free Software under the GNU GPL (v>=3) - * and comes with ABSOLUTELY NO WARRANTY! Check out - * the documentation coming with IMIS-Labordaten-Application for details. - */ -package de.intevation.lada.validation.rules.ort; - -import de.intevation.lada.validation.Violation; -import de.intevation.lada.validation.annotation.ValidationRule; -import de.intevation.lada.validation.rules.Rule; - -@ValidationRule("Ort") -public class EntnahmeortToVE implements Rule { - - @Override - public Violation execute(Object object) { - // TODO - return null; - } - -}
--- a/src/main/java/de/intevation/lada/validation/rules/ort/HasEntnahmeOrt.java Fri Dec 09 14:57:17 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz - * Software engineering by Intevation GmbH - * - * This file is Free Software under the GNU GPL (v>=3) - * and comes with ABSOLUTELY NO WARRANTY! Check out - * the documentation coming with IMIS-Labordaten-Application for details. - */ -package de.intevation.lada.validation.rules.ort; - -import java.util.List; - -import javax.inject.Inject; - -import de.intevation.lada.model.land.Ortszuordnung; -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; - -@ValidationRule("Ort") -public class HasEntnahmeOrt implements Rule { - - @Inject - @RepositoryConfig(type=RepositoryType.RO) - private Repository repository; - - @Override - public Violation execute(Object object) { - Ortszuordnung ort = (Ortszuordnung)object; - if (!"E".equals(ort.getOrtszuordnungTyp())) { - return null; - } - - QueryBuilder<Ortszuordnung> builder = new QueryBuilder<Ortszuordnung>( - repository.entityManager("land"), - Ortszuordnung.class); - builder.and("probeId", ort.getProbeId()); - List<Ortszuordnung> orte = repository.filterPlain( - builder.getQuery(), - "land"); - for (Ortszuordnung o : orte) { - if ("E".equals(o.getOrtszuordnungTyp()) && - !o.getId().equals(ort.getId()) - ) { - Violation violation = new Violation(); - violation.addError("ortszuordnungsTyp", 611); - return violation; - } - } - - return null; - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/validation/rules/ortszuordnung/CoordinatesInVE.java Fri Dec 09 15:34:15 2016 +0100 @@ -0,0 +1,84 @@ +/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU GPL (v>=3) + * and comes with ABSOLUTELY NO WARRANTY! Check out + * the documentation coming with IMIS-Labordaten-Application for details. + */ +package de.intevation.lada.validation.rules.ort; + +import java.util.List; + +import javax.inject.Inject; + +import com.vividsolutions.jts.geom.Point; + +import de.intevation.lada.model.land.Ortszuordnung; +import de.intevation.lada.model.stammdaten.Ort; +import de.intevation.lada.model.stammdaten.Verwaltungseinheit; +import de.intevation.lada.model.stammdaten.Verwaltungsgrenze; +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; + +/** + * Validation rule for ort. + * Validates if the coordinates are in the specified "Verwaltungseinheit". + * + * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> + */ +@ValidationRule("Ortszuordnung") +public class CoordinatesInVE implements Rule { + + @Inject + @RepositoryConfig(type=RepositoryType.RO) + private Repository repository; + + @SuppressWarnings("unchecked") + @Override + public Violation execute(Object object) { + Ortszuordnung oz = (Ortszuordnung)object; + if (!"E".equals(oz.getOrtszuordnungTyp())) { + return null; + } + + Ort ort = repository.getByIdPlain(Ort.class, oz.getOrtId(), "stamm"); + String gemId = ort.getGemId(); + if (gemId == null) { + Violation violation = new Violation(); + violation.addWarning("gemId", 631); + return violation; + } + + QueryBuilder<Verwaltungsgrenze> vg = + new QueryBuilder<Verwaltungsgrenze>( + repository.entityManager("stamm"), Verwaltungsgrenze.class); + vg.and("gemId", gemId); + List<Verwaltungsgrenze> vgs = repository.filterPlain( + vg.getQuery(), "stamm"); + if (vgs == null || vgs.isEmpty()) { + Violation violation = new Violation(); + violation.addWarning("verwaltungsgrenze", 600); + return violation; + } + + Point p = ort.getGeom(); + boolean hit = false; + for (Verwaltungsgrenze singlevg : vgs) { + if(singlevg.getShape().contains(p)) { + hit = true; + } + } + if (!hit) { + Violation violation = new Violation(); + violation.addWarning("verwaltungsgrenze", 651); + return violation; + } + return null; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/validation/rules/ortszuordnung/EntnahmeortToVE.java Fri Dec 09 15:34:15 2016 +0100 @@ -0,0 +1,23 @@ +/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU GPL (v>=3) + * and comes with ABSOLUTELY NO WARRANTY! Check out + * the documentation coming with IMIS-Labordaten-Application for details. + */ +package de.intevation.lada.validation.rules.ort; + +import de.intevation.lada.validation.Violation; +import de.intevation.lada.validation.annotation.ValidationRule; +import de.intevation.lada.validation.rules.Rule; + +@ValidationRule("Ortszuordnung") +public class EntnahmeortToVE implements Rule { + + @Override + public Violation execute(Object object) { + // TODO + return null; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/validation/rules/ortszuordnung/HasEntnahmeOrt.java Fri Dec 09 15:34:15 2016 +0100 @@ -0,0 +1,56 @@ +/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU GPL (v>=3) + * and comes with ABSOLUTELY NO WARRANTY! Check out + * the documentation coming with IMIS-Labordaten-Application for details. + */ +package de.intevation.lada.validation.rules.ort; + +import java.util.List; + +import javax.inject.Inject; + +import de.intevation.lada.model.land.Ortszuordnung; +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; + +@ValidationRule("Ortszuordnung") +public class HasEntnahmeOrt implements Rule { + + @Inject + @RepositoryConfig(type=RepositoryType.RO) + private Repository repository; + + @Override + public Violation execute(Object object) { + Ortszuordnung ort = (Ortszuordnung)object; + if (!"E".equals(ort.getOrtszuordnungTyp())) { + return null; + } + + QueryBuilder<Ortszuordnung> builder = new QueryBuilder<Ortszuordnung>( + repository.entityManager("land"), + Ortszuordnung.class); + builder.and("probeId", ort.getProbeId()); + List<Ortszuordnung> orte = repository.filterPlain( + builder.getQuery(), + "land"); + for (Ortszuordnung o : orte) { + if ("E".equals(o.getOrtszuordnungTyp()) && + !o.getId().equals(ort.getId()) + ) { + Violation violation = new Violation(); + violation.addError("ortszuordnungsTyp", 611); + return violation; + } + } + + return null; + } +}