# HG changeset patch # User Ingo Weinzierl # Date 1304349424 0 # Node ID c21fb8de54f84699044ff9aaaf61baf037c7a4ab # Parent 20c3a5b36434c6cec2bcffc87c332f7bea2401b6 Enabled the FLYSArtifact to handle an array of inserted WQ values (without given ranges). flys-artifacts/trunk@1793 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 20c3a5b36434 -r c21fb8de54f8 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Mon May 02 13:42:02 2011 +0000 +++ b/flys-artifacts/ChangeLog Mon May 02 15:17:04 2011 +0000 @@ -1,3 +1,27 @@ +2011-05-02 Ingo Weinzierl + + * doc/conf/artifacts/winfo.xml: Added two further data items in the WQ + selection state. Those items are necessary to store the information + about the selected mode (range/single selection) and the values of the + single selection. + + * src/main/java/de/intevation/flys/artifacts/states/DefaultState.java: If + there is no value for a data item, this item is not written into the + static DESCRIBE part. + + * src/main/java/de/intevation/flys/artifacts/states/RangeState.java, + src/main/java/de/intevation/flys/artifacts/states/LocationDistanceSelect.java: + Renamed the method to validate upper and lower values. + + * src/main/java/de/intevation/flys/artifacts/states/WQSelect.java: This + state can now handle values inserted in the single selection. Therefore, + new validate methods has been added. + + * src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java: The + methods getWs() and getWs() take care on the values inserted in the + single insert mode of the client which enables the user to insert single + W and Q. + 2011-05-02 Sascha L. Teichmann * src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java: diff -r 20c3a5b36434 -r c21fb8de54f8 flys-artifacts/doc/conf/artifacts/winfo.xml --- a/flys-artifacts/doc/conf/artifacts/winfo.xml Mon May 02 13:42:02 2011 +0000 +++ b/flys-artifacts/doc/conf/artifacts/winfo.xml Mon May 02 15:17:04 2011 +0000 @@ -43,9 +43,11 @@ + + diff -r 20c3a5b36434 -r c21fb8de54f8 flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java Mon May 02 13:42:02 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java Mon May 02 15:17:04 2011 +0000 @@ -8,6 +8,8 @@ import javax.xml.xpath.XPathConstants; +import gnu.trove.TDoubleArrayList; + import org.apache.log4j.Logger; import org.w3c.dom.Document; @@ -534,12 +536,18 @@ * @return the selected Q values or null, if no Q values are selected. */ public double[] getQs() { - StateData dMode = getData("wq_mode"); + StateData dMode = getData("wq_mode"); + StateData dSingle = getData("wq_single"); String mode = dMode != null ? (String) dMode.getValue() : ""; if (mode.equals("Q")) { - return getWQTriple(); + if (dSingle != null) { + return getSingleWQValues(); + } + else { + return getWQTriple(); + } } else { logger.warn("You try to get Qs, but W has been inserted."); @@ -554,12 +562,18 @@ * @return the selected W values or null, if no W values are selected. */ public double[] getWs() { - StateData dMode = getData("wq_mode"); + StateData dMode = getData("wq_mode"); + StateData dSingle = getData("wq_single"); String mode = dMode != null ? (String) dMode.getValue() : ""; if (mode.equals("W")) { - return getWQTriple(); + if (dSingle != null) { + return getSingleWQValues(); + } + else { + return getWQTriple(); + } } else { logger.warn("You try to get Qs, but W has been inserted."); @@ -608,7 +622,7 @@ StateData dTo = getData("wq_to"); if (dFrom == null || dTo == null) { - logger.warn("Missing start or end value for Q range."); + logger.warn("Missing start or end value for range."); return null; } @@ -636,6 +650,40 @@ /** + * Returns an array of inserted WQ double values stored as whitespace + * separated list. + * + * @return an array of W or Q values. + */ + protected double[] getSingleWQValues() { + StateData dSingle = getData("wq_single"); + + if (dSingle == null) { + logger.warn("Cannot determine single WQ values. No data given."); + return null; + } + + String tmp = (String) dSingle.getValue(); + String[] strValues = tmp.split(" "); + + TDoubleArrayList values = new TDoubleArrayList(); + + for (String strValue: strValues) { + try { + values.add(Double.parseDouble(strValue)); + } + catch (NumberFormatException nfe) { + logger.warn(nfe, nfe); + } + } + + values.sort(); + + return values.toNativeArray(); + } + + + /** * Returns an array of double values. The values contained in this array * begin with the value from and end with the value to. The * number of values in the result array depends on the step width. diff -r 20c3a5b36434 -r c21fb8de54f8 flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DefaultState.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DefaultState.java Mon May 02 13:42:02 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DefaultState.java Mon May 02 15:17:04 2011 +0000 @@ -62,6 +62,10 @@ String name = data.getName(); String value = (String) data.getValue(); + if (value == null) { + continue; + } + logger.debug("Append element '" + name + "' (" + value + ")"); Element dataElement = creator.create("data"); diff -r 20c3a5b36434 -r c21fb8de54f8 flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/LocationDistanceSelect.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/LocationDistanceSelect.java Mon May 02 13:42:02 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/LocationDistanceSelect.java Mon May 02 15:17:04 2011 +0000 @@ -175,7 +175,7 @@ double[] minmaxDist = getMinMaxDistance(artifact); - return validateRange(minmaxDist[0], minmaxDist[1], from, to, step); + return validateBounds(minmaxDist[0], minmaxDist[1], from, to, step); } catch (NumberFormatException nfe) { throw new IllegalArgumentException("error_feed_number_format"); diff -r 20c3a5b36434 -r c21fb8de54f8 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 Mon May 02 13:42:02 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RangeState.java Mon May 02 15:17:04 2011 +0000 @@ -27,7 +27,7 @@ * * @return true, if everything was fine, otherwise an exception is thrown. */ - protected boolean validateRange( + protected boolean validateBounds( double fromValid, double toValid, double from, double to, double step) throws IllegalArgumentException diff -r 20c3a5b36434 -r c21fb8de54f8 flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java Mon May 02 13:42:02 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java Mon May 02 15:17:04 2011 +0000 @@ -2,6 +2,8 @@ import java.util.Map; +import gnu.trove.TDoubleArrayList; + import org.apache.log4j.Logger; import org.w3c.dom.Element; @@ -40,6 +42,9 @@ /** The name of the 'mode' field. */ public static final String WQ_MODE = "wq_mode"; + /** The name of the 'selection' field.*/ + public static final String WQ_SELECTION = "wq_selection"; + /** The name of the 'from' field. */ public static final String WQ_FROM = "wq_from"; @@ -49,6 +54,10 @@ /** The name of the 'step' field. */ public static final String WQ_STEP = "wq_step"; + /** The name of the 'single' field. */ + public static final String WQ_SINGLE = "wq_single"; + + /** * The default constructor that initializes an empty State object. */ @@ -196,6 +205,69 @@ Map data = getData(); + String selectionMode = (String) data.get(WQ_SELECTION).getValue(); + + if (selectionMode == null || selectionMode.equals("single")) { + return validateSingle(artifact, context); + } + else { + return validateRange(artifact, context); + } + } + + + protected boolean validateSingle(Artifact artifact, CallContext context) + throws IllegalArgumentException + { + logger.debug("WQSelect.validateSingle"); + + String tmp = (String) data.get(WQ_SINGLE).getValue(); + + if (tmp == null || tmp.length() == 0) { + throw new IllegalArgumentException("error_empty_state"); + } + + String[] strValues = tmp.split(" "); + TDoubleArrayList all = new TDoubleArrayList(); + + for (String strValue: strValues) { + try { + all.add(Double.parseDouble(strValue)); + } + catch (NumberFormatException nfe) { + logger.warn(nfe, nfe); + } + } + + all.sort(); + + String mode = (String) data.get(WQ_MODE).getValue(); + logger.debug("WQ Mode: " + mode); + + double[] minmax = null; + + if (mode != null && mode.trim().toLowerCase().equals("w")) { + minmax = determineMinMaxW(artifact); + } + else { + minmax = determineMinMaxQ(artifact); + } + + double min = all.get(0); + double max = all.get(all.size()-1); + + logger.debug("Inserted min value = " + min); + logger.debug("Inserted max value = " + max); + + return validateBounds(minmax[0], minmax[1], min, max, 0d); + } + + + protected boolean validateRange(Artifact artifact, CallContext context) + throws IllegalArgumentException + { + logger.debug("WQSelect.validateRange"); + String mode = (String) data.get(WQ_MODE).getValue(); logger.debug("WQ Mode: " + mode); @@ -251,7 +323,7 @@ double[] minmaxW = determineMinMaxW(artifact); - return validateRange(minmaxW[0], minmaxW[1], from, to, step); + return validateBounds(minmaxW[0], minmaxW[1], from, to, step); } @@ -278,7 +350,7 @@ double[] minmaxQ = determineMinMaxQ(artifact); - return validateRange(minmaxQ[0], minmaxQ[1], from, to, step); + return validateBounds(minmaxQ[0], minmaxQ[1], from, to, step); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :