changeset 1054:3c9616e5439f

Remove wrong period check. The validity period can be e.g. from November till February, thus spanning over turn of the year and allowing a from value greater than to value (in terms of day of year).
author Tom Gottfried <tom@intevation.de>
date Fri, 23 Sep 2016 17:56:22 +0200
parents a7404bf577fd
children 37952c111f71
files db_schema/lada_schema.sql src/main/java/de/intevation/lada/validation/rules/messprogramm/ValidFromTo.java
diffstat 2 files changed, 18 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/db_schema/lada_schema.sql	Thu Sep 22 16:14:57 2016 +0200
+++ b/db_schema/lada_schema.sql	Fri Sep 23 17:56:22 2016 +0200
@@ -583,13 +583,12 @@
     teilintervall_von integer NOT NULL,
     teilintervall_bis integer NOT NULL,
     intervall_offset integer,
-    gueltig_von integer NOT NULL,
-    gueltig_bis integer NOT NULL,
+    gueltig_von integer NOT NULL CHECK(gueltig_von BETWEEN 0 AND 364),
+    gueltig_bis integer NOT NULL CHECK(gueltig_bis BETWEEN 0 AND 364),
     probe_nehmer_id integer,
     probe_kommentar character varying(80),
     letzte_aenderung timestamp without time zone DEFAULT now() NOT NULL,
-    CHECK (teilintervall_von <= teilintervall_bis),
-    CHECK (gueltig_von <= gueltig_bis)
+    CHECK (teilintervall_von <= teilintervall_bis)
 );
 CREATE TRIGGER letzte_aenderung_messprogramm BEFORE UPDATE ON messprogramm FOR EACH ROW EXECUTE PROCEDURE update_letzte_aenderung();
 
--- a/src/main/java/de/intevation/lada/validation/rules/messprogramm/ValidFromTo.java	Thu Sep 22 16:14:57 2016 +0200
+++ b/src/main/java/de/intevation/lada/validation/rules/messprogramm/ValidFromTo.java	Fri Sep 23 17:56:22 2016 +0200
@@ -19,17 +19,27 @@
 @ValidationRule("Messprogramm")
 public class ValidFromTo implements Rule {
 
+    private static final int DOY_MIN = 0;
+
+    // Leap years should be handled in generation of Probe objects
+    private static final int DOY_MAX = 364;
+
     @Override
     public Violation execute(Object object) {
         Messprogramm messprogramm = (Messprogramm)object;
         Violation violation = new Violation();
 
         if (messprogramm.getGueltigVon() != null
-            && messprogramm.getGueltigBis() != null
-            && messprogramm.getGueltigVon() > messprogramm.getGueltigBis()) {
-            violation.addError("gueltigVon", 662);
-            violation.addError("gueltigBis", 662);
-        }
+            && (messprogramm.getGueltigVon() < DOY_MIN
+                || messprogramm.getGueltigVon() > DOY_MAX)) {
+                violation.addError("gueltigVon", 612);
+            }
+
+        if (messprogramm.getGueltigBis() != null
+            && (messprogramm.getGueltigBis() < DOY_MIN
+                || messprogramm.getGueltigBis() > DOY_MAX)) {
+                violation.addError("gueltigBis", 612);
+            }
 
         return violation.hasErrors()
             ? violation
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)