diff flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java @ 2038:f73036b991e2

Bugfix: repaired broken named values in exports - the last solution had bad side effects. flys-artifacts/trunk@3515 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 21 Dec 2011 15:44:41 +0000
parents 3ebbe497d7f7
children e5f01f2325c9
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java	Wed Dec 21 11:56:08 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java	Wed Dec 21 15:44:41 2011 +0000
@@ -39,6 +39,12 @@
 
     public static enum KM_MODE { RANGE, LOCATIONS, NONE };
 
+    /**
+     * An enum that represents the 5 possible WQ modes in FLYS. The 5 values are
+     * <i>QFREE</i> <i>QGAUGE</i> <i>WGAUGE</i> <i>WFREE</i> and <i>NONE</i>.
+     */
+    public static enum WQ_MODE { QFREE, QGAUGE, WFREE, WGAUGE, NONE };
+
     public static final String XPATH_RIVER_PROJECTION =
         "/artifact-database/floodmap/river[@name=$name]/srid/@value";
 
@@ -133,6 +139,31 @@
     }
 
 
+    /**
+     * This method returns an WQ_MODE enum which is based on the parameters
+     * stored in <i>flys</i> Artifact. If there is no <i>wq_mode</i> parameter
+     * existing, WQ_MODE.NONE is returned.
+     *
+     * @param flys The FLYSArtifact that stores wq mode relevant parameters.
+     *
+     * @return an enum WQ_MODE.
+     */
+    public static WQ_MODE getWQMode(FLYSArtifact flys) {
+        String  mode = flys.getDataAsString("wq_mode");
+        boolean free = flys.getDataAsBoolean("wq_free");
+
+        if (mode != null && mode.equals("Q")) {
+            return free ? WQ_MODE.QFREE : WQ_MODE.QGAUGE;
+        }
+        else if (mode != null && mode.equals("W")) {
+            return free ? WQ_MODE.WFREE : WQ_MODE.WGAUGE;
+        }
+        else {
+            return WQ_MODE.NONE;
+        }
+    }
+
+
     public static KM_MODE getKmRangeMode(FLYSArtifact flys) {
         String mode = flys.getDataAsString("ld_mode");
 
@@ -353,6 +384,27 @@
     }
 
 
+    /**
+     * Returns the named main value if a Q was selected and if this Q fits to a
+     * named main value. Otherwise, this function returns null.
+     *
+     * @param winfo The WINFO Artifact.
+     * @param value The Q (or W) value.
+     *
+     * @return a named main value or null.
+     */
+    public static String getNamedMainValue(WINFOArtifact winfo, double value) {
+        WQ_MODE wqmode = getWQMode(winfo);
+
+        if (wqmode != WQ_MODE.QGAUGE) {
+            return null;
+        }
+        else {
+            return getNamedMainValue(winfo.getGauge(), value);
+        }
+    }
+
+
     public static String getNamedMainValue(Gauge gauge, double value) {
         List<MainValue> mainValues = gauge.getMainValues();
         logger.debug("Search named main value for: " + value);

http://dive4elements.wald.intevation.org