[Lada-commits] [PATCH 1 of 7] Added new rule for status validation

Wald Commits scm-commit at wald.intevation.org
Wed Nov 18 15:40:08 CET 2015


# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1447857122 -3600
# Node ID 4a5c493e46cec4ab4c168adcc7bc11aa5f05a384
# Parent  625c8ae7fc30f8ac048019a62c1cb5b670344553
Added new rule for status validation.

diff -r 625c8ae7fc30 -r 4a5c493e46ce src/main/java/de/intevation/lada/validation/rules/status/StatusFolge.java
--- /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 at intevation.de">Raimund Renkert</a>
+ */
+ at 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;
+    }
+}


More information about the Lada-commits mailing list