changeset 2617:71086a3a1c5f

Issue 499. Added validation for 'W free'. flys-artifacts/trunk@4201 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Thu, 05 Apr 2012 08:51:53 +0000
parents 27cc95e65f18
children 3a93bbbe2ec7
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java
diffstat 3 files changed, 135 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Thu Apr 05 07:21:58 2012 +0000
+++ b/flys-artifacts/ChangeLog	Thu Apr 05 08:51:53 2012 +0000
@@ -1,3 +1,13 @@
+2012-04-05  Raimund Renkert <raimund.renkert@intevation.de>
+
+	Issue 499.
+
+	* src/main/java/de/intevation/flys/artifacts/states/WQSelect.java:
+	  Added validation for 'W free' using WstValueTable min/max values.
+
+	* src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java:
+	  Added getter for WstValueTable.
+
 2012-04-05  Ingo Weinzierl <ingo@intevation.de>
 
 	* doc/conf/themes.xml: Defined a theme for WSPLGEN layers.
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Thu Apr 05 07:21:58 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Thu Apr 05 08:51:53 2012 +0000
@@ -1336,5 +1336,14 @@
                ? 0
                : 1;
     }
+
+
+    /**
+     * Returns the WstValueTable.
+     */
+    public WstValueTable getWstValueTable() {
+        River r = FLYSUtils.getRiver(this);
+        return WstValueTableFactory.getTable(r);
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java	Thu Apr 05 07:21:58 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java	Thu Apr 05 08:51:53 2012 +0000
@@ -25,6 +25,7 @@
 import de.intevation.flys.artifacts.WINFOArtifact;
 
 import de.intevation.flys.artifacts.model.WstFactory;
+import de.intevation.flys.artifacts.model.WstValueTable;
 import de.intevation.flys.artifacts.resources.Resources;
 
 import de.intevation.flys.utils.FLYSUtils;
@@ -238,6 +239,7 @@
         CallContext context)
     {
         double[] minmaxW     = determineMinMaxW(artifact);
+        double[] minmaxWFree = determineMinMaxWFree(artifact);
         double[] minmaxQ     = determineMinMaxQAtGauge(artifact);
         double[] minmaxQFree = determineMinMaxQ(artifact);
 
@@ -254,7 +256,11 @@
                 "minQFree",
                 String.valueOf(minmaxQFree[0])});
 
-            return new Element[] { minW, minQ, minQFree };
+            Element minWFree = createItem(cr, new String[] {
+                "minWFree",
+                String.valueOf(minmaxWFree[0])});
+
+            return new Element[] { minW, minQ, minQFree, minWFree };
         }
         else if (name.equals("wq_to")) {
             Element maxW = createItem(cr, new String[] {
@@ -269,7 +275,11 @@
                 "maxQFree",
                 String.valueOf(minmaxQFree[1])});
 
-            return new Element[] { maxW, maxQ, maxQFree };
+            Element maxWFree = createItem(cr, new String[] {
+                "maxWFree",
+                String.valueOf(minmaxWFree[1])});
+
+            return new Element[] { maxW, maxQ, maxQFree, maxWFree };
         }
         else {
             Element stepW = createItem(
@@ -284,8 +294,12 @@
                 cr, new String[] {
                     "stepQFree",
                     String.valueOf(getStepsQ(minmaxQFree[0], minmaxQFree[1]))});
+            Element stepWFree = createItem(
+                cr, new String[] {
+                    "stepWFree",
+                    String.valueOf(getStepsW(minmaxWFree[0], minmaxWFree[1]))});
 
-            return new Element[] { stepW, stepQ, stepQFree };
+            return new Element[] { stepW, stepQ, stepQFree, stepWFree };
         }
     }
 
@@ -386,6 +400,48 @@
 
 
     /**
+     * Determines the min and max W value. If no min and
+     * max values could be determined, this method will return
+     * [Double.MIN_VALUE, Double.MAX_VALUE].
+     *
+     * @param artifact The FLYSArtifact.
+     *
+     * @return the min and max W values.
+     */
+    protected double[] determineMinMaxWFree(Artifact artifact) {
+        logger.debug("WQSelect.determineMinMaxWFree");
+
+        WINFOArtifact winfo = (WINFOArtifact) artifact;
+        WstValueTable valueTable = winfo.getWstValueTable();
+
+        double[] minmaxW = null;
+        if(valueTable != null) {
+            double[] km = null;
+            if(winfo.isRange()) {
+                km = winfo.getFromToStep();
+                minmaxW = valueTable.getMinMaxW(km[0], km[1], km[2]);
+            }
+            else {
+                km = winfo.getKms();
+                minmaxW = valueTable.getMinMaxW(km[0]);
+                for (int i = 1; i < km.length; i++) {
+                    double[] tmp = valueTable.getMinMaxW(km[i]);
+                    if(tmp[0] < minmaxW[0]) {
+                        minmaxW[0] = tmp[0];
+                    }
+                    if(tmp[1] > minmaxW[1]) {
+                        minmaxW[1] = tmp[1];
+                    }
+                }
+            }
+        }
+        return minmaxW != null
+            ? minmaxW
+            : new double[] { Double.MIN_VALUE, Double.MAX_VALUE };
+    }
+
+
+    /**
      * Determines the min and max Q value for the current gauge. If no min and
      * max values could be determined, this method will return
      * [Double.MIN_VALUE, Double.MAX_VALUE].
@@ -425,20 +481,30 @@
     protected double[] determineMinMaxQ(Artifact artifact) {
         logger.debug("WQSelect.determineMinMaxQ");
 
-        FLYSArtifact flys = (FLYSArtifact) artifact;
-        double[]     kms  = FLYSUtils.getKmRange(flys);
-
-        if (kms == null || kms.length == 0) {
-            return new double[] { Double.MIN_VALUE, Double.MAX_VALUE };
-        }
+        WINFOArtifact winfo = (WINFOArtifact) artifact;
+        WstValueTable valueTable = winfo.getWstValueTable();
 
-        River river = FLYSUtils.getRiver(flys);
-        Wst    wst  = WstFactory.getWst(river);
-
-        logger.debug("User defined KMs: " + kms[0] + " - " + kms[kms.length-1]);
-
-        double[] minmaxQ = wst.determineMinMaxQFree(kms[0]);
-
+        double[] minmaxQ = null;
+        if(valueTable != null) {
+            double[] km = null;
+            if(winfo.isRange()) {
+                km = winfo.getFromToStep();
+                minmaxQ = valueTable.getMinMaxQ(km[0], km[1], km[2]);
+            }
+            else {
+                km = winfo.getKms();
+                minmaxQ = valueTable.getMinMaxQ(km[0]);
+                for (int i = 1; i < km.length; i++) {
+                    double[] tmp = valueTable.getMinMaxQ(km[i]);
+                    if(tmp[0] < minmaxQ[0]) {
+                        minmaxQ[0] = tmp[0];
+                    }
+                    if(tmp[1] > minmaxQ[1]) {
+                        minmaxQ[1] = tmp[1];
+                    }
+                }
+            }
+        }
         return minmaxQ != null
             ? minmaxQ
             : new double[] { Double.MIN_VALUE, Double.MAX_VALUE };
@@ -531,8 +597,11 @@
         else if (mode == FLYSUtils.WQ_MODE.QGAUGE) {
             minmax = determineMinMaxQAtGauge(artifact);
         }
+        else if (mode == FLYSUtils.WQ_MODE.QFREE) {
+            minmax = determineMinMaxQ(artifact);
+        }
         else {
-            minmax = determineMinMaxQ(artifact);
+            minmax = determineMinMaxWFree(artifact);
         }
 
         double min = all.get(0);
@@ -583,6 +652,9 @@
             else if (mode == FLYSUtils.WQ_MODE.QFREE) {
                 return validateFreeQ(artifact, from, to, step);
             }
+            else if (mode == FLYSUtils.WQ_MODE.WFREE) {
+                return validateFreeW(artifact, from, to, step);
+            }
             else {
                 throw new IllegalArgumentException(
                     "error_feed_invalid_wq_mode");
@@ -669,5 +741,32 @@
 
         return validateBounds(minmaxQ[0], minmaxQ[1], from, to, step);
     }
+
+
+    /**
+     * Validates the inserted W values based on the W range for the current
+     * kilometer range.
+     *
+     * @param artifact The owner artifact.
+     * @param from The lower value of the W range.
+     * @param to The upper value of the W range.
+     * @param step The step width.
+     *
+     * @return true, if everything was fine, otherwise an exception is thrown.
+     */
+    protected boolean validateFreeW(
+        Artifact artifact,
+        double   from,
+        double   to,
+        double   step)
+    throws IllegalArgumentException
+    {
+        logger.debug("WQSelect.validateFreeW");
+
+        double[] minmaxW = determineMinMaxWFree(artifact);
+
+        return validateBounds(minmaxW[0], minmaxW[1], from, to, step);
+    }
+
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org