Mercurial > lada > lada-server
changeset 785:4a5c493e46ce
Added new rule for status validation.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Wed, 18 Nov 2015 15:32:02 +0100 (2015-11-18) |
parents | 625c8ae7fc30 |
children | 9a2dcb355d89 |
files | src/main/java/de/intevation/lada/validation/rules/status/StatusFolge.java |
diffstat | 1 files changed, 90 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/status/StatusFolge.java Wed Nov 18 15:32:02 2015 +0100 @@ -0,0 +1,90 @@ +/* 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.status; + +import java.util.List; + +import javax.inject.Inject; + +import de.intevation.lada.model.land.LStatusProtokoll; +import de.intevation.lada.model.stamm.StatusKombi; +import de.intevation.lada.model.stamm.StatusReihenfolge; +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 status. + * + * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> + */ +@ValidationRule("Status") +public class StatusFolge implements Rule { + + @Inject + @RepositoryConfig(type=RepositoryType.RO) + private Repository repository; + + @Override + public Violation execute(Object object) { + LStatusProtokoll status = (LStatusProtokoll)object; + QueryBuilder<StatusKombi> kombi = new QueryBuilder<StatusKombi>( + repository.entityManager("stamm"), + StatusKombi.class); + kombi.and("stufeId", status.getStatusStufe()); + kombi.and("wertId", status.getStatusWert()); + List<StatusKombi> result = + repository.filterPlain(kombi.getQuery(), "stamm"); + if (result.isEmpty()) { + Violation violation = new Violation(); + violation.addError("status", 632); + return violation; + } + + // Get the previous status + QueryBuilder<LStatusProtokoll> lastFilter = + new QueryBuilder<LStatusProtokoll>( + repository.entityManager("land"), + LStatusProtokoll.class); + + lastFilter.and("messungsId", status.getMessungsId()); + lastFilter.orderBy("datum", true); + List<LStatusProtokoll> protos = + repository.filterPlain(lastFilter.getQuery(), "land"); + LStatusProtokoll last = protos.get(protos.size() - 1); + QueryBuilder<StatusKombi> kombi2 = kombi.getEmptyBuilder(); + kombi2.and("stufeId", last.getStatusStufe()); + kombi2.and("wertId", last.getStatusWert()); + List<StatusKombi> result2 = + repository.filterPlain(kombi.getQuery(), "stamm"); + if (result2.isEmpty()) { + Violation violation = new Violation(); + violation.addError("status", 632); + return violation; + } + QueryBuilder<StatusReihenfolge> folgeFilter = + new QueryBuilder<StatusReihenfolge>( + repository.entityManager("stamm"), + StatusReihenfolge.class); + folgeFilter.and("von", result2.get(0).getId()); + folgeFilter.and("zu", result.get(0).getId()); + List<StatusReihenfolge> reihenfolge = + repository.filterPlain(folgeFilter.getQuery(), "stamm"); + if (reihenfolge.isEmpty()) { + Violation violation = new Violation(); + violation.addError("status", 632); + return violation; + } + + return null; + } +}