# HG changeset patch # User Tom Gottfried # Date 1476113019 -7200 # Node ID 6499f2410c420b6bd3f30cf7845bdd4c349f1326 # Parent b782a10c5b28fb128bc5614d6c9f125d0434bc6d Fix validation of subintervall for yearly samples. Validity and subintervall are actually redundant for yearly samples. Giving a subintervall wider than validity will never result in generation of samples because the start will never match validity. diff -r b782a10c5b28 -r 6499f2410c42 db_schema/lada_schema.sql --- a/db_schema/lada_schema.sql Mon Oct 10 16:25:12 2016 +0200 +++ b/db_schema/lada_schema.sql Mon Oct 10 17:23:39 2016 +0200 @@ -589,8 +589,8 @@ 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 teilintervall_von BETWEEN gueltig_von AND gueltig_bis + AND teilintervall_bis BETWEEN gueltig_von AND gueltig_bis AND intervall_offset BETWEEN 0 AND 364 OR probenintervall = 'H' AND teilintervall_von BETWEEN 1 AND 184 diff -r b782a10c5b28 -r 6499f2410c42 src/main/java/de/intevation/lada/validation/rules/messprogramm/SubIntervall.java --- a/src/main/java/de/intevation/lada/validation/rules/messprogramm/SubIntervall.java Mon Oct 10 16:25:12 2016 +0200 +++ b/src/main/java/de/intevation/lada/validation/rules/messprogramm/SubIntervall.java Mon Oct 10 17:23:39 2016 +0200 @@ -46,45 +46,64 @@ Integer teilVon = messprogramm.getTeilintervallVon(); Integer teilBis = messprogramm.getTeilintervallBis(); Integer offset = messprogramm.getIntervallOffset(); + Integer gueltigVon = messprogramm.getGueltigVon(); + Integer gueltigBis = messprogramm.getGueltigBis(); - // skip this validation if mandatory fields not given + // skip this validation if relevant 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 ("J".equals(probenintervall)) { + if (gueltigVon != null && gueltigBis != null) { + if (teilVon < gueltigVon || teilVon > gueltigBis) { + violation.addError("teilintervallVon", 612); + } + if (teilBis < gueltigVon || teilBis > gueltigBis) { + violation.addError("teilintervallBis", 612); + } + if (offset != null + && offset > intervallMax.get("J") - 1) { + violation.addError("intervallOffset", 612); + } + } } - if (teilBis < 1) { - violation.addError("teilintervallBis", 612); - } - if (offset != null && offset < 0) { - violation.addError("intervallOffset", 612); - } + else { + // 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 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); + // upper limits depend on (valid) intervall type + Set 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 + // lower limit has to be less than or equal to upper limit if (teilVon > teilBis) { violation.addError("teilintervallVon", 662); violation.addError("teilintervallBis", 662);