# HG changeset patch # User Ingo Weinzierl # Date 1316678304 0 # Node ID cafd8af6734a7a6aa5a6bc1f195a19fc59608689 # Parent 4aec853a2f859a16183cbb1a82c9c2c34d8d545c Improved bounds validation for distance only states. flys-artifacts/trunk@2806 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 4aec853a2f85 -r cafd8af6734a flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Wed Sep 21 14:28:39 2011 +0000 +++ b/flys-artifacts/ChangeLog Thu Sep 22 07:58:24 2011 +0000 @@ -1,3 +1,13 @@ +2011-09-22 Ingo Weinzierl + + * src/main/java/de/intevation/flys/artifacts/states/DistanceOnlySelect.java: + Override validate() of parent classes to suppress "step" validation + which is not present in this state. + + * src/main/java/de/intevation/flys/artifacts/states/RangeState.java: Added + new method validateBounds() which really just validates a boundary + without "step" parameter. + 2011-09-21 Felix Wolfsteller Added WaterlevelArtifact to accompany WDifferencesPlots. diff -r 4aec853a2f85 -r cafd8af6734a flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DistanceOnlySelect.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DistanceOnlySelect.java Wed Sep 21 14:28:39 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DistanceOnlySelect.java Thu Sep 22 07:58:24 2011 +0000 @@ -2,6 +2,12 @@ import org.apache.log4j.Logger; +import de.intevation.artifacts.Artifact; + +import de.intevation.artifactdatabase.data.StateData; + +import de.intevation.flys.artifacts.FLYSArtifact; + public class DistanceOnlySelect extends DistanceSelect { @@ -11,5 +17,35 @@ protected String getUIProvider() { return "distance_only_panel"; } + + + @Override + public boolean validate(Artifact artifact) + throws IllegalArgumentException + { + FLYSArtifact flys = (FLYSArtifact) artifact; + + StateData dFrom = getData(flys, getLowerField()); + StateData dTo = getData(flys, getUpperField()); + + String fromStr = dFrom != null ? (String) dFrom.getValue() : null; + String toStr = dTo != null ? (String) dTo.getValue() : null; + + if (fromStr == null || toStr == null) { + throw new IllegalArgumentException("error_empty_state"); + } + + try { + double from = Double.parseDouble(fromStr); + double to = Double.parseDouble(toStr); + + double[] minmax = getMinMax(flys); + + return validateBounds(minmax[0], minmax[1], from, to); + } + catch (NumberFormatException nfe) { + throw new IllegalArgumentException("error_invalid_double_value"); + } + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : diff -r 4aec853a2f85 -r cafd8af6734a flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RangeState.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RangeState.java Wed Sep 21 14:28:39 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RangeState.java Thu Sep 22 07:58:24 2011 +0000 @@ -28,6 +28,26 @@ protected abstract double[] getMinMax(Artifact artifact); + protected boolean validateBounds( + double fromValid, double toValid, + double from, double to) + throws IllegalArgumentException + { + if (from < fromValid) { + logger.error( + "Invalid 'from'. " + from + " is smaller than " + fromValid); + throw new IllegalArgumentException("error_feed_from_out_of_range"); + } + else if (to > toValid) { + logger.error( + "Invalid 'to'. " + to + " is bigger than " + toValid); + throw new IllegalArgumentException("error_feed_to_out_of_range"); + } + + return true; + } + + /** * Validates a given range with a given valid range. * @@ -46,18 +66,8 @@ { logger.debug("RangeState.validateRange"); - if (from < fromValid) { - logger.error( - "Invalid 'from'. " + from + " is smaller than " + fromValid); - throw new IllegalArgumentException("error_feed_from_out_of_range"); - } - else if (to > toValid) { - logger.error( - "Invalid 'to'. " + to + " is bigger than " + toValid); - throw new IllegalArgumentException("error_feed_to_out_of_range"); - } - - return true; + // XXX The step width is not validated at the moment! + return validateBounds(fromValid, toValid, from, to); }