[PATCH 2 of 5] (issue1755) Validate selected periods and ranges

Wald Commits scm-commit at wald.intevation.org
Fri Mar 27 17:31:21 CET 2015


# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1427471758 -3600
# Node ID 5a5331dd3e8dda8e0119716178d15b2ea9447590
# Parent  7d1a32a543cb5d9b988980efaa8d93ec8fadb9d5
(issue1755) Validate selected periods and ranges.

diff -r 7d1a32a543cb -r 5a5331dd3e8d artifacts/src/main/java/org/dive4elements/river/artifacts/access/BedQualityAccess.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/access/BedQualityAccess.java	Fri Mar 27 16:54:56 2015 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/access/BedQualityAccess.java	Fri Mar 27 16:55:58 2015 +0100
@@ -68,6 +68,9 @@
 
     private List<DateRange> extractRanges(String dateString) {
         List<DateRange> list = new LinkedList<DateRange>();
+        if (dateString == null) {
+            return list;
+        }
         String[] dates = dateString.split(";");
         for (String s : dates) {
             String[] pair = s.split(",");
diff -r 7d1a32a543cb -r 5a5331dd3e8d artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/BedQualityPeriodsSelect.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/BedQualityPeriodsSelect.java	Fri Mar 27 16:54:56 2015 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/BedQualityPeriodsSelect.java	Fri Mar 27 16:55:58 2015 +0100
@@ -11,6 +11,7 @@
 import java.util.List;
 import java.util.Date;
 import java.util.TreeSet;
+import java.text.DateFormat;
 
 import org.apache.log4j.Logger;
 
@@ -19,12 +20,16 @@
 import org.w3c.dom.Element;
 
 import org.dive4elements.river.artifacts.access.RangeAccess;
+import org.dive4elements.river.artifacts.access.BedQualityAccess;
 import org.dive4elements.river.artifacts.D4EArtifact;
 import org.dive4elements.river.artifacts.model.minfo.BedOverview;
 import org.dive4elements.river.artifacts.model.minfo.BedOverviewFactory;
 import org.dive4elements.river.artifacts.model.minfo.BedloadOverview;
 import org.dive4elements.river.artifacts.model.minfo.BedloadOverviewFactory;
+import org.dive4elements.river.artifacts.model.DateRange;
+import org.dive4elements.river.artifacts.resources.Resources;
 
+import org.dive4elements.river.utils.Formatter;
 import org.dive4elements.river.utils.KMIndex;
 
 import org.dive4elements.artifacts.common.utils.XMLUtils;
@@ -39,6 +44,11 @@
     /** The log used in this class. */
     private static Logger log = Logger.getLogger(BedQualityPeriodsSelect.class);
 
+    private static final String I18N_NO_DATA =
+        "state.minfo.bed.error.no_data";
+
+    private static final String I18N_NO_DATA_FOR_PERIOD =
+        "state.minfo.bed.error.no_data_for_period";
 
     /**
      * The default constructor that initializes an empty State object.
@@ -108,6 +118,36 @@
     }
 
     @Override
+    public void validate(Artifact artifact, CallContext context)
+    throws IllegalArgumentException {
+        D4EArtifact arti = (D4EArtifact) artifact;
+        BedQualityAccess access = new BedQualityAccess(arti, context);
+
+        Long[] minMax = getDataMinMaxDate(artifact);
+        if (minMax == null) {
+            throw new IllegalArgumentException(Resources.getMsg(context.getMeta(),
+                         I18N_NO_DATA,
+                         I18N_NO_DATA));
+        }
+
+        long min = minMax[0];
+        long max = minMax[1];
+        for (DateRange range: access.getDateRanges()) {
+            long a = range.getFrom().getTime();
+            long b = range.getFrom().getTime();
+            if ((a < min || a > max) &&
+                ( b < min || b > max)) {
+                DateFormat df = Formatter.getDateFormatter(context.getMeta(), "dd.MM.yyyy");
+                throw new IllegalArgumentException(Resources.getMsg(context.getMeta(),
+                             I18N_NO_DATA_FOR_PERIOD,
+                             I18N_NO_DATA_FOR_PERIOD,
+                             new Object[] {df.format(range.getFrom()),
+                                           df.format(range.getTo())}));
+            }
+        }
+    }
+
+    @Override
     protected String getUIProvider() {
         return "bedquality_periods_select";
     }
diff -r 7d1a32a543cb -r 5a5331dd3e8d artifacts/src/main/resources/messages.properties
--- a/artifacts/src/main/resources/messages.properties	Fri Mar 27 16:54:56 2015 +0100
+++ b/artifacts/src/main/resources/messages.properties	Fri Mar 27 16:55:58 2015 +0100
@@ -55,9 +55,12 @@
 state.minfo.bed.difference_select=Differences
 state.minfo.year=Year
 state.minfo.epoch=Epoch
+state.minfo.bed.distance = Range selection
 state.minfo.bed.location = Location/Distance
 state.minfo.bed.periods = Periods
 state.minfo.bed.char_diameter = Characteristic Diameter
+state.minfo.bed.error.no_data = No data found for selected range.
+state.minfo.bed.error.no_data_for_period = No data found for period: {0} - {1}.
 state.minfo.soundings = Choose Soundings
 state.minfo.sediment.load.location = Range
 state.minfo.sediment.load.year_epoch = Year/Epoch
diff -r 7d1a32a543cb -r 5a5331dd3e8d artifacts/src/main/resources/messages_de.properties
--- a/artifacts/src/main/resources/messages_de.properties	Fri Mar 27 16:54:56 2015 +0100
+++ b/artifacts/src/main/resources/messages_de.properties	Fri Mar 27 16:55:58 2015 +0100
@@ -55,9 +55,12 @@
 state.minfo.bed.difference_select=Differenzen
 state.minfo.year=Jahr
 state.minfo.epoch=Epoche
+state.minfo.bed.distance = Wahl der Berechnungsstrecke
 state.minfo.bed.location = Ort(e)/Strecke
 state.minfo.bed.periods = Zeitraum/Zeitr\u00e4ume
 state.minfo.bed.char_diameter = Charakteristischer Durchmesser
+state.minfo.bed.error.no_data = F\u00fcr die gew\u00e4hlte Strecke liegen keine Daten vor.
+state.minfo.bed.error.no_data_for_period = F\u00fcr den Zeitraum {0} - {1} liegen keine Daten vor.
 state.minfo.soundings = Wahl der Peilungen
 state.minfo.sediment.load.location = Berechnungsstrecke
 state.minfo.sediment.load.year_epoch = Jahr/Zeitraum
diff -r 7d1a32a543cb -r 5a5331dd3e8d artifacts/src/main/resources/messages_de_DE.properties
--- a/artifacts/src/main/resources/messages_de_DE.properties	Fri Mar 27 16:54:56 2015 +0100
+++ b/artifacts/src/main/resources/messages_de_DE.properties	Fri Mar 27 16:55:58 2015 +0100
@@ -56,8 +56,11 @@
 state.minfo.year=Jahr
 state.minfo.epoch=Epoche
 state.minfo.bed.location = Ort(e)/Strecke
+state.minfo.bed.distance = Wahl der Berechnungsstrecke
 state.minfo.bed.periods = Zeitraum/Zeitr\u00e4ume
 state.minfo.bed.char_diameter = Charakteristischer Durchmesser
+state.minfo.bed.error.no_data = F\u00fcr die gew\u00e4hlte Strecke liegen keine Daten vor.
+state.minfo.bed.error.no_data_for_period = F\u00fcr den Zeitraum {0} - {1} liegen keine Daten vor.
 state.minfo.soundings = Wahl der Peilungen
 state.minfo.sediment.load.location = Berechnungsstrecke
 state.minfo.sediment.load.year_epoch = Jahr/Zeitraum
diff -r 7d1a32a543cb -r 5a5331dd3e8d artifacts/src/main/resources/messages_en.properties
--- a/artifacts/src/main/resources/messages_en.properties	Fri Mar 27 16:54:56 2015 +0100
+++ b/artifacts/src/main/resources/messages_en.properties	Fri Mar 27 16:55:58 2015 +0100
@@ -56,8 +56,11 @@
 state.minfo.year=Year
 state.minfo.epoch=Epoch
 state.minfo.bed.location = Location/Distance
+state.minfo.bed.distance = Range selection
 state.minfo.bed.periods = Periods
 state.minfo.bed.char_diameter = Characteristic Diameter
+state.minfo.bed.error.no_data = No data found for selected range.
+state.minfo.bed.error.no_data_for_period = No data found for period: {0} - {1}.
 state.minfo.soundings = Choose Soundings
 state.minfo.sediment.load.location = Range
 state.minfo.sediment.load.year_epoch = Year/Epoch


More information about the Dive4Elements-commits mailing list