changeset 379:c21fb8de54f8

Enabled the FLYSArtifact to handle an array of inserted WQ values (without given ranges). flys-artifacts/trunk@1793 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 02 May 2011 15:17:04 +0000
parents 20c3a5b36434
children 5f55047a17e8
files flys-artifacts/ChangeLog flys-artifacts/doc/conf/artifacts/winfo.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DefaultState.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/LocationDistanceSelect.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RangeState.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java
diffstat 7 files changed, 159 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- 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 <ingo@intevation.de>
+
+	* 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	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/model/DischargeTables.java:
--- 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 @@
 
         <state id="state.winfo.wq" description="state.winfo.wq" state="de.intevation.flys.artifacts.states.WQSelect">
             <data name="wq_mode" type="String" />
+            <data name="wq_selection" type="String" />
             <data name="wq_from" type="Double" />
             <data name="wq_to" type="Double" />
             <data name="wq_step" type="Double" />
+            <data name="wq_single" type="Double[]" />
         </state>
 
         <transition transition="de.intevation.flys.artifacts.transitions.ValueCompareTransition">
--- 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 <i>from</i> and end with the value <i>to</i>. The
      * number of values in the result array depends on the <i>step</i> width.
--- 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");
--- 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");
--- 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
--- 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<String, StateData> 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 :

http://dive4elements.wald.intevation.org