Mercurial > lada > lada-server
changeset 1063:7788a805a98d
Complement data model and validation of sub-intervalls.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Tue, 27 Sep 2016 16:16:31 +0200 |
parents | 0fbcaefc565b |
children | 8ec6a2a31171 |
files | db_schema/lada_schema.sql src/main/java/de/intevation/lada/validation/rules/messprogramm/SubIntervall.java |
diffstat | 2 files changed, 98 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- 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();
--- 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()