Mercurial > lada > lada-server
changeset 565:f3f8b8a26afa
Added messung validator and rules.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Fri, 13 Mar 2015 16:50:20 +0100 |
parents | 7a10b1e85c79 |
children | 044810451b02 |
files | src/main/java/de/intevation/lada/validation/MessungValidator.java src/main/java/de/intevation/lada/validation/rules/messung/HasMesswert.java src/main/java/de/intevation/lada/validation/rules/messung/HasNebenprobenNr.java src/main/java/de/intevation/lada/validation/rules/messung/UniqueNebenprobenNr.java |
diffstat | 3 files changed, 112 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/messung/HasMesswert.java Fri Mar 13 16:50:20 2015 +0100 @@ -0,0 +1,42 @@ +package de.intevation.lada.validation.rules.messung; + +import java.util.List; + +import javax.inject.Inject; + +import de.intevation.lada.model.land.LMessung; +import de.intevation.lada.model.land.LMesswert; +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("Messung") +public class HasMesswert implements Rule { + + @Inject + @RepositoryConfig(type=RepositoryType.RO) + private Repository repo; + + @Override + public Violation execute(Object object) { + LMessung messung = (LMessung)object; + QueryBuilder<LMesswert> builder = + new QueryBuilder<LMesswert>( + repo.entityManager("land"), LMesswert.class); + builder.and("messungsId", messung.getId()); + Response response = repo.filter(builder.getQuery(), "land"); + @SuppressWarnings("unchecked") + List<LMesswert> messwerte = (List<LMesswert>)response.getData(); + if (messwerte == null || messwerte.isEmpty()) { + Violation violation = new Violation(); + violation.addWarning("messwert", 631); + return violation; + } + return null; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/validation/rules/messung/HasNebenprobenNr.java Fri Mar 13 16:50:20 2015 +0100 @@ -0,0 +1,23 @@ +package de.intevation.lada.validation.rules.messung; + +import de.intevation.lada.model.land.LMessung; +import de.intevation.lada.validation.Violation; +import de.intevation.lada.validation.annotation.ValidationRule; +import de.intevation.lada.validation.rules.Rule; + +@ValidationRule("Messung") +public class HasNebenprobenNr implements Rule { + + @Override + public Violation execute(Object object) { + LMessung messung = (LMessung)object; + if (messung.getNebenprobenNr() == null || + messung.getNebenprobenNr().equals("")) { + Violation violation = new Violation(); + violation.addWarning("nebenprobenNr", 631); + return violation; + } + return null; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/validation/rules/messung/UniqueNebenprobenNr.java Fri Mar 13 16:50:20 2015 +0100 @@ -0,0 +1,47 @@ +package de.intevation.lada.validation.rules.messung; + +import java.util.List; + +import javax.inject.Inject; + +import de.intevation.lada.model.land.LMessung; +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("Messung") +public class UniqueNebenprobenNr implements Rule { + + @Inject + @RepositoryConfig(type=RepositoryType.RO) + private Repository repo; + + @SuppressWarnings("unchecked") + @Override + public Violation execute(Object object) { + LMessung messung= (LMessung)object; + QueryBuilder<LMessung> builder = new QueryBuilder<LMessung>( + repo.entityManager("land"), + LMessung.class); + builder.and("nebenprobenNr", messung.getNebenprobenNr()); + builder.and("probeId", messung.getProbeId()); + Response response = repo.filter(builder.getQuery(), "land"); + if (!((List<LMessung>)response.getData()).isEmpty()) { + LMessung found = ((List<LMessung>)response.getData()).get(0); + // The messung found in the db equals the new messung. (Update) + if (messung.getId() != null && messung.getId() == found.getId()) { + return null; + } + Violation violation = new Violation(); + violation.addError("nebenprobenNr", 611); + return violation; + } + return null; + } + +}