[Lada-commits] [PATCH] Validate type of an Ort object

Wald Commits scm-commit at wald.intevation.org
Thu Feb 2 15:01:17 CET 2017


# HG changeset patch
# User Tom Gottfried <tom at intevation.de>
# Date 1486044072 -3600
# Node ID efa50b39c7cc29deb5f5e7782b1fdd96db798c47
# Parent  a356b818389ae4bb747d3cba0d79ba076bc263ad
Validate type of an Ort object.

diff -r a356b818389a -r efa50b39c7cc src/main/java/de/intevation/lada/validation/rules/ort/OrtTypExists.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/validation/rules/ort/OrtTypExists.java	Thu Feb 02 15:01:12 2017 +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.stammdaten.Ort;
+import de.intevation.lada.model.stammdaten.OrtTyp;
+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 a given OrtTyp exists.
+ *
+ */
+ at ValidationRule("Ort")
+public class OrtTypExists implements Rule {
+
+    @Inject
+    @RepositoryConfig(type=RepositoryType.RO)
+    private Repository repository;
+
+    @Override
+    public Violation execute(Object object) {
+        Ort ort = (Ort)object;
+
+        QueryBuilder<OrtTyp> builder =
+            new QueryBuilder<OrtTyp>(
+                repository.entityManager("stamm"),
+                OrtTyp.class);
+        builder.and("id", ort.getOrtTyp());
+        List<OrtTyp> ots = repository.filterPlain(
+            builder.getQuery(), "stamm");
+        if (ots == null || ots.isEmpty()) {
+            Violation violation = new Violation();
+            violation.addError("ortTyp", 612);
+            return violation;
+        }
+
+        return null;
+    }
+
+}


More information about the Lada-commits mailing list