[Lada-commits] [PATCH 1 of 2] A period with end before start is not meaningful

Wald Commits scm-commit at wald.intevation.org
Thu Sep 8 12:04:38 CEST 2016


# HG changeset patch
# User Tom Gottfried <tom at intevation.de>
# Date 1473265068 -7200
# Node ID a796e68da1cfc9b200fbf659afae76a2eba53609
# Parent  e192feaf916f30fb500340c4a93aae93cb25e9c8
A period with end before start is not meaningful.

diff -r e192feaf916f -r a796e68da1cf db_schema/lada_schema.sql
--- a/db_schema/lada_schema.sql	Tue Jul 05 18:24:55 2016 +0200
+++ b/db_schema/lada_schema.sql	Wed Sep 07 18:17:48 2016 +0200
@@ -587,7 +587,8 @@
     gueltig_bis integer NOT NULL,
     probe_nehmer_id integer,
     probe_kommentar character varying(80),
-    letzte_aenderung timestamp without time zone DEFAULT now() NOT NULL
+    letzte_aenderung timestamp without time zone DEFAULT now() NOT NULL,
+    CHECK (gueltig_von <= gueltig_bis)
 );
 CREATE TRIGGER letzte_aenderung_messprogramm BEFORE UPDATE ON messprogramm FOR EACH ROW EXECUTE PROCEDURE update_letzte_aenderung();
 
diff -r e192feaf916f -r a796e68da1cf src/main/java/de/intevation/lada/validation/rules/messprogramm/HasAllMandatory.java
--- a/src/main/java/de/intevation/lada/validation/rules/messprogramm/HasAllMandatory.java	Tue Jul 05 18:24:55 2016 +0200
+++ b/src/main/java/de/intevation/lada/validation/rules/messprogramm/HasAllMandatory.java	Wed Sep 07 18:17:48 2016 +0200
@@ -14,7 +14,7 @@
 
 /**
  * Validation rule for Messprogramm.
- * Validates if the Messprogramm has Datenbasis.
+ * Validates if the Messprogramm has all mandatory fields set.
  */
 @ValidationRule("Messprogramm")
 public class HasAllMandatory implements Rule {
diff -r e192feaf916f -r a796e68da1cf src/main/java/de/intevation/lada/validation/rules/messprogramm/ValidFromTo.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/de/intevation/lada/validation/rules/messprogramm/ValidFromTo.java	Wed Sep 07 18:17:48 2016 +0200
@@ -0,0 +1,36 @@
+/* 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.messprogramm;
+
+import de.intevation.lada.model.land.Messprogramm;
+import de.intevation.lada.validation.Violation;
+import de.intevation.lada.validation.annotation.ValidationRule;
+import de.intevation.lada.validation.rules.Rule;
+
+/**
+ * Validation rule for Messprogramm.
+ * Validates if the validity period is meaningful.
+ */
+ at ValidationRule("Messprogramm")
+public class ValidFromTo implements Rule {
+
+    @Override
+    public Violation execute(Object object) {
+        Messprogramm messprogramm = (Messprogramm)object;
+        Violation violation = new Violation();
+
+        if (messprogramm.getGueltigVon() > messprogramm.getGueltigBis()) {
+            violation.addError("gueltigVon", 662);
+            violation.addError("gueltigBis", 662);
+        }
+
+        return violation.hasErrors()
+            ? violation
+            :null;
+    }
+}


More information about the Lada-commits mailing list