Mercurial > lada > lada-server
changeset 538:fd927b584c54
Added first validation rules for probe objects.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Tue, 24 Feb 2015 10:58:06 +0100 |
parents | f44c9e59f08c |
children | deb3fec601ed |
files | src/main/java/de/intevation/lada/validation/rules/probe/HasEntnahmeOrt.java src/main/java/de/intevation/lada/validation/rules/probe/HasHauptprobenNr.java src/main/java/de/intevation/lada/validation/rules/probe/HasProbenahmeBegin.java src/main/java/de/intevation/lada/validation/rules/probe/UniqueHauptprobenNr.java |
diffstat | 4 files changed, 143 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/validation/rules/probe/HasEntnahmeOrt.java Tue Feb 24 10:58:06 2015 +0100 @@ -0,0 +1,50 @@ +package de.intevation.lada.validation.rules.probe; + +import java.util.List; + +import javax.inject.Inject; + +import de.intevation.lada.model.land.LOrt; +import de.intevation.lada.model.land.LProbe; +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; + +@ValidationRule("Probe") +public class HasEntnahmeOrt implements Rule { + + @Inject + @RepositoryConfig(type=RepositoryType.RO) + private Repository repo; + + @Override + public Violation execute(Object object) { + LProbe probe = (LProbe)object; + Integer id = probe.getId(); + if (id == null) { + Violation violation = new Violation(); + violation.addWarning("entnahmeOrt", 631); + return violation; + } + QueryBuilder<LOrt> builder = + new QueryBuilder<LOrt>(repo.entityManager("land"), LOrt.class); + builder.and("probeId", id); + Response response = repo.filter(builder.getQuery(), "land"); + @SuppressWarnings("unchecked") + List<LOrt> orte = (List<LOrt>)response.getData(); + for (LOrt ort: orte) { + if (ort.getOrtsTyp().equals("E")) { + return null; + } + } + Violation violation = new Violation(); + violation.addWarning("entnahmeOrt", 631); + return violation; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/validation/rules/probe/HasHauptprobenNr.java Tue Feb 24 10:58:06 2015 +0100 @@ -0,0 +1,22 @@ +package de.intevation.lada.validation.rules.probe; + +import de.intevation.lada.model.land.LProbe; +import de.intevation.lada.validation.Violation; +import de.intevation.lada.validation.annotation.ValidationRule; +import de.intevation.lada.validation.rules.Rule; + +@ValidationRule("Probe") +public class HasHauptprobenNr implements Rule { + + @Override + public Violation execute(Object object) { + LProbe probe = (LProbe)object; + if (probe.getHauptprobenNr() == null || + probe.getHauptprobenNr().equals("")) { + Violation violation = new Violation(); + violation.addError("hauptprobenNr", 631); + return violation; + } + return null; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/validation/rules/probe/HasProbenahmeBegin.java Tue Feb 24 10:58:06 2015 +0100 @@ -0,0 +1,25 @@ +package de.intevation.lada.validation.rules.probe; + +import java.sql.Timestamp; + +import de.intevation.lada.model.land.LProbe; +import de.intevation.lada.validation.Violation; +import de.intevation.lada.validation.annotation.ValidationRule; +import de.intevation.lada.validation.rules.Rule; + +@ValidationRule("Probe") +public class HasProbenahmeBegin implements Rule { + + @Override + public Violation execute(Object object) { + LProbe probe = (LProbe)object; + Timestamp begin = probe.getProbeentnahmeBeginn(); + if (begin == null) { + Violation violation = new Violation(); + violation.addWarning("probeentnahmeBegin", 631); + return violation; + } + return null; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/validation/rules/probe/UniqueHauptprobenNr.java Tue Feb 24 10:58:06 2015 +0100 @@ -0,0 +1,46 @@ +package de.intevation.lada.validation.rules.probe; + +import java.util.List; + +import javax.inject.Inject; + +import de.intevation.lada.model.land.LProbe; +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; + +@ValidationRule("Probe") +public class UniqueHauptprobenNr implements Rule { + + @Inject + @RepositoryConfig(type=RepositoryType.RO) + private Repository repo; + + @SuppressWarnings("unchecked") + @Override + public Violation execute(Object object) { + LProbe probe = (LProbe)object; + QueryBuilder<LProbe> builder = new QueryBuilder<LProbe>( + repo.entityManager("land"), + LProbe.class); + builder.and("hauptprobenNr", probe.getHauptprobenNr()); + Response response = repo.filter(builder.getQuery(), "land"); + if (!((List<LProbe>)response.getData()).isEmpty()) { + LProbe found = ((List<LProbe>)response.getData()).get(0); + // The probe found in the db equals the new probe. (Update) + if (probe.getId() != null && probe.getId() == found.getId()) { + return null; + } + Violation violation = new Violation(); + violation.addError("hauptprobenNr", 611); + return violation; + } + return null; + } + +}