Mercurial > dive4elements > river
changeset 627:833290f16f09
ISSUE-85 (part I/III) Added further fields for the location/range state.
flys-artifacts/trunk@1992 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 24 May 2011 11:27:37 +0000 |
parents | e3ee131d5dd3 |
children | 51b69bca4560 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/LocationDistanceSelect.java |
diffstat | 3 files changed, 113 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Tue May 24 11:23:57 2011 +0000 +++ b/flys-artifacts/ChangeLog Tue May 24 11:27:37 2011 +0000 @@ -15,6 +15,20 @@ 2011-05-23 Ingo Weinzierl <ingo@intevation.de> + ISSUE-85 (part I/III) + + * doc/conf/artifacts/winfo.xml: Added two further field 'ld_mode' and + 'ld_locations' to the range/locations state to track the selected mode + and locations. + + * src/main/java/de/intevation/flys/artifacts/states/LocationDistanceSelect.java: + Added methods to validate the user inserted locations. + + * src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java: Added a + method to determine of a range or locations have been inserted. + +2011-05-23 Ingo Weinzierl <ingo@intevation.de> + ISSUE-62 (part II/II) * src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java: Dump the
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java Tue May 24 11:23:57 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java Tue May 24 11:27:37 2011 +0000 @@ -461,6 +461,25 @@ /** + * Determines the selected mode of distance/range input. + * + * @return true, if the range mode is selected otherwise false. + */ + public boolean isRange() { + StateData mode = getData("ld_mode"); + + if (mode == null) { + logger.warn("No mode location/range chosen. Defaults to range."); + return true; + } + + String value = (String) mode.getValue(); + + return value.equals("range"); + } + + + /** * This method returns the given distance * * @return an array with lower and upper kilometer range for each
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/LocationDistanceSelect.java Tue May 24 11:23:57 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/LocationDistanceSelect.java Tue May 24 11:27:37 2011 +0000 @@ -30,6 +30,12 @@ /** The default step width.*/ public static final String DEFAULT_STEP = "100"; + /** The name of the 'mode' field. */ + public static final String MODE = "ld_mode"; + + /** The name of the 'locations' field.*/ + public static final String LOCATIONS = "ld_locations"; + /** The name of the 'from' field. */ public static final String FROM = "ld_from"; @@ -158,6 +164,43 @@ FLYSArtifact flys = (FLYSArtifact) artifact; + if (flys.isRange()) { + return validateRange(flys, context); + } + else { + return validateLocations(flys, context); + } + } + + + protected boolean validateLocations(FLYSArtifact flys, CallContext context) + throws IllegalArgumentException + { + StateData dValues = getData(flys, LOCATIONS); + String values = dValues != null ? (String)dValues.getValue() : null; + + if (values == null || values.length() == 0) { + throw new IllegalArgumentException("error_empty_state"); + } + + double[] absMinMax = getMinMaxDistance(flys); + double[] relMinMax = getMinMaxFromString(values); + + if (relMinMax[0] < absMinMax[0] || relMinMax[0] > absMinMax[1]) { + throw new IllegalArgumentException("error_feed_from_out_of_range"); + } + + if (relMinMax[1] > absMinMax[1] || relMinMax[1] < absMinMax[0]) { + throw new IllegalArgumentException("error_feed_to_out_of_range"); + } + + return true; + } + + + protected boolean validateRange(FLYSArtifact flys, CallContext context) + throws IllegalArgumentException + { StateData dFrom = getData(flys, FROM); StateData dTo = getData(flys, TO); StateData dStep = getData(flys, STEP); @@ -175,13 +218,48 @@ double to = Double.parseDouble(toStr); double step = Double.parseDouble(stepStr); - double[] minmaxDist = getMinMaxDistance(artifact); + double[] minmaxDist = getMinMaxDistance(flys); return validateBounds(minmaxDist[0], minmaxDist[1], from, to, step); } catch (NumberFormatException nfe) { - throw new IllegalArgumentException("error_feed_number_format"); + throw new IllegalArgumentException("error_invalid_double_value"); } } + + + /** + * Extracts the min/max values from String <i>s</i>. An + * IllegalArgumentException is thrown if there is a value that throws a + * NumberFormatException. + * + * @param s String that contains whitespace separated double values. + * + * @return a 2dmin array [min,max]. + */ + public static double[] getMinMaxFromString(String s) + throws IllegalArgumentException + { + String[] values = s.split(" "); + + double[] minmax = new double[] { + Double.MAX_VALUE, + -Double.MAX_VALUE }; + + for (String v: values) { + try { + double value = Double.valueOf(v); + + minmax[0] = minmax[0] < value ? minmax[0] : value; + minmax[1] = minmax[1] > value ? minmax[1] : value; + } + catch (NumberFormatException nfe) { + throw new IllegalArgumentException( + "error_invalid_double_value"); + } + } + + return minmax; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :