[Lada-commits] [PATCH 07 of 10] Complement data model and validation of sub-intervalls

Wald Commits scm-commit at wald.intevation.org
Thu Sep 29 16:54:48 CEST 2016


# HG changeset patch
# User Tom Gottfried <tom at intevation.de>
# Date 1474985791 -7200
# Node ID 7788a805a98df8214a96bc1d2fc0aa9a87bc6ecf
# Parent  0fbcaefc565b3b68f945ddc85b7dc09ec9420178
Complement data model and validation of sub-intervalls.

diff -r 0fbcaefc565b -r 7788a805a98d db_schema/lada_schema.sql
--- a/db_schema/lada_schema.sql	Tue Sep 27 12:18:15 2016 +0200
+++ b/db_schema/lada_schema.sql	Tue Sep 27 16:16:31 2016 +0200
@@ -588,6 +588,39 @@
     probe_nehmer_id integer,
     probe_kommentar character varying(80),
     letzte_aenderung timestamp without time zone DEFAULT now() NOT NULL,
+    CHECK (probenintervall = 'J'
+               AND teilintervall_von BETWEEN 1 AND 365
+               AND teilintervall_bis BETWEEN 1 AND 365
+               AND intervall_offset BETWEEN 0 AND 364
+           OR probenintervall = 'H'
+               AND teilintervall_von BETWEEN 1 AND 183
+               AND teilintervall_bis BETWEEN 1 AND 183
+               AND intervall_offset BETWEEN 0 AND 182
+           OR probenintervall = 'Q'
+               AND teilintervall_von BETWEEN 1 AND 91
+               AND teilintervall_bis BETWEEN 1 AND 91
+               AND intervall_offset BETWEEN 0 AND 90
+           OR probenintervall = 'M'
+               AND teilintervall_von BETWEEN 1 AND 31
+               AND teilintervall_bis BETWEEN 1 AND 31
+               AND intervall_offset BETWEEN 0 AND 30
+           OR probenintervall = 'W4'
+               AND teilintervall_von BETWEEN 1 AND 28
+               AND teilintervall_bis BETWEEN 1 AND 28
+               AND intervall_offset BETWEEN 0 AND 27
+           OR probenintervall = 'W2'
+               AND teilintervall_von BETWEEN 1 AND 14
+               AND teilintervall_bis BETWEEN 1 AND 14
+               AND intervall_offset BETWEEN 0 AND 13
+           OR probenintervall = 'W'
+               AND teilintervall_von BETWEEN 1 AND 7
+               AND teilintervall_bis BETWEEN 1 AND 7
+               AND intervall_offset BETWEEN 0 AND 6
+           OR probenintervall = 'T'
+               AND teilintervall_von = 1
+               AND teilintervall_bis = 1
+               AND intervall_offset = 0
+           ),
     CHECK (teilintervall_von <= teilintervall_bis)
 );
 CREATE TRIGGER letzte_aenderung_messprogramm BEFORE UPDATE ON messprogramm FOR EACH ROW EXECUTE PROCEDURE update_letzte_aenderung();
diff -r 0fbcaefc565b -r 7788a805a98d src/main/java/de/intevation/lada/validation/rules/messprogramm/SubIntervall.java
--- a/src/main/java/de/intevation/lada/validation/rules/messprogramm/SubIntervall.java	Tue Sep 27 12:18:15 2016 +0200
+++ b/src/main/java/de/intevation/lada/validation/rules/messprogramm/SubIntervall.java	Tue Sep 27 16:16:31 2016 +0200
@@ -7,6 +7,9 @@
  */
 package de.intevation.lada.validation.rules.messprogramm;
 
+import java.util.Hashtable;
+import java.util.Set;
+
 import de.intevation.lada.model.land.Messprogramm;
 import de.intevation.lada.validation.Violation;
 import de.intevation.lada.validation.annotation.ValidationRule;
@@ -19,17 +22,73 @@
 @ValidationRule("Messprogramm")
 public class SubIntervall implements Rule {
 
+    private Hashtable<String, Integer> intervallMax;
+
+    public SubIntervall() {
+        this.intervallMax = new Hashtable<String, Integer>();
+
+        this.intervallMax.put("J",  365);
+        this.intervallMax.put("H",  183);
+        this.intervallMax.put("Q",  91);
+        this.intervallMax.put("M",  31);
+        this.intervallMax.put("W4", 28);
+        this.intervallMax.put("W2", 14);
+        this.intervallMax.put("W",  7);
+        this.intervallMax.put("T",  1);
+    }
+
     @Override
     public Violation execute(Object object) {
         Messprogramm messprogramm = (Messprogramm)object;
         Violation violation = new Violation();
 
-        if (messprogramm.getTeilintervallBis() != null
-            && messprogramm.getTeilintervallVon() != null
-            && messprogramm.getTeilintervallVon()
-            > messprogramm.getTeilintervallBis()) {
-            violation.addError("teilintervallVon", 662);
-            violation.addError("teilintervallBis", 662);
+        String probenintervall = messprogramm.getProbenintervall();
+        Integer teilVon = messprogramm.getTeilintervallVon();
+        Integer teilBis = messprogramm.getTeilintervallBis();
+        Integer offset = messprogramm.getIntervallOffset();
+
+        // skip this validation if mandatory fields not given
+        if (probenintervall != null
+            && teilVon != null
+            && teilBis != null
+        ) {
+            // lower limits are independent of intervall type
+            if (teilVon < 1) {
+                violation.addError("teilintervallVon", 612);
+            }
+            if (teilBis < 1) {
+                violation.addError("teilintervallBis", 612);
+            }
+            if (offset != null && offset < 0) {
+                violation.addError("intervallOffset", 612);
+            }
+
+            // upper limits depend on (valid) intervall type
+            Set<String> probenintervallSet = intervallMax.keySet();
+            if (!probenintervallSet.contains(probenintervall)) {
+                violation.addError("probenintervall", 612);
+            } else {
+                for (String intervallKey : probenintervallSet) {
+                    if (intervallKey.equals(probenintervall)) {
+                        if (teilVon > intervallMax.get(intervallKey)) {
+                            violation.addError("teilintervallVon", 612);
+                        }
+                        if (teilBis > intervallMax.get(intervallKey)) {
+                            violation.addError("teilintervallBis", 612);
+                        }
+                        if (offset != null
+                            && offset > intervallMax.get(intervallKey) - 1) {
+                            violation.addError("intervallOffset", 612);
+                        }
+                    }
+                }
+            }
+
+            // lower limit has to be less than upper limit
+            if (teilVon > teilBis) {
+                violation.addError("teilintervallVon", 662);
+                violation.addError("teilintervallBis", 662);
+            }
         }
 
         return violation.hasErrors()


More information about the Lada-commits mailing list