changeset 7697:640342d9ab8a

(issue1649) Remove broken getWKms from RiverUtils and use WDifferencesState instead This was basically duplicated code but only the code in WDifferenceState was maintained and extended. Another RiverUtils function bites the dust.
author Andre Heinecke <aheinecke@intevation.de>
date Mon, 16 Dec 2013 16:24:07 +0100
parents feb23ab736f4
children 7efeaa2058e1
files artifacts/src/main/java/org/dive4elements/river/artifacts/states/WDifferencesState.java artifacts/src/main/java/org/dive4elements/river/utils/RiverUtils.java
diffstat 2 files changed, 5 insertions(+), 59 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/WDifferencesState.java	Mon Dec 16 16:00:10 2013 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/WDifferencesState.java	Mon Dec 16 16:24:07 2013 +0100
@@ -80,7 +80,7 @@
     /**
      * Access the data (wkms) of an artifact, coded in mingle.
      */
-    protected WKms getWKms(String mingle, CallContext context) {
+    public WKms getWKms(String mingle, CallContext context) {
         logger.debug("WDifferencesState.getWKms " + mingle);
         String[] def  = mingle.split(";");
         String   uuid = def[0];
--- a/artifacts/src/main/java/org/dive4elements/river/utils/RiverUtils.java	Mon Dec 16 16:00:10 2013 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/utils/RiverUtils.java	Mon Dec 16 16:24:07 2013 +0100
@@ -723,6 +723,8 @@
     {
         State state = winfo.getCurrentState(context);
         if(state instanceof WDifferencesState) {
+            WDifferencesState wState = (WDifferencesState) state;
+
             String diffids = winfo.getDataAsString("diffids");
             String datas[] = diffids.split("#");
 
@@ -741,9 +743,9 @@
             for(int i = 0; i < datas.length; i+=2) {
                 // e.g.:
                 // 42537f1e-3522-42ef-8968-635b03d8e9c6;longitudinal_section.w;1
-                WKms minuendWKms = getWKms(StringUtil.unbracket(datas[i+0]),
+                WKms minuendWKms = wState.getWKms(StringUtil.unbracket(datas[i+0]),
                     context);
-                WKms subtrahendWKms = getWKms(StringUtil.unbracket(datas[i+1]),
+                WKms subtrahendWKms = wState.getWKms(StringUtil.unbracket(datas[i+1]),
                     context);
                 if (minuendWKms != null && subtrahendWKms != null) {
                     diffs += StringUtil.wWrap(minuendWKms.getName())
@@ -759,62 +761,6 @@
         }
     }
 
-
-    protected static WKms getWKms(String mingle, CallContext context) {
-        String[] def  = mingle.split(";");
-        String   uuid = def[0];
-        String   name = def[1];
-        int      idx  = Integer.parseInt(def[2]);
-
-        if (name.startsWith("staticwkms")) {
-            StaticWKmsArtifact staticWKms =
-                (StaticWKmsArtifact) RiverUtils.getArtifact(
-                    uuid,
-                    context);
-            WKms wkms = staticWKms.getWKms(idx);
-            if (wkms == null)
-                logger.error("No WKms from artifact.");
-            return wkms;
-        }
-
-        WINFOArtifact flys = (WINFOArtifact) RiverUtils.getArtifact(
-            uuid,
-            context);
-
-        if (flys == null) {
-            logger.warn("One of the artifacts (1) for diff calculation could not be loaded");
-            return null;
-        }
-        else{
-            Object data = flys.getWaterlevelData(context).getData();
-
-            if (data == null) {
-                logger.error("No waterlevel Data in artifact");
-                return null;
-            }
-
-            if (data instanceof WQKms[]) {
-                WQKms[] wqkms = (WQKms[]) data;
-                if (wqkms.length < idx) {
-                    logger.error("not enough waterlevels in artifact");
-                    return null;
-                }
-                return wqkms[idx];
-            } else if (data instanceof WKms[]) {
-                WKms[] wkms = (WKms[]) data;
-                if (wkms.length < idx) {
-                    logger.error("not enough wkms in artifact");
-                    return null;
-                }
-                return wkms[idx];
-            }
-
-            logger.error("unknown Waterlevel Data.");
-            return null;
-        }
-    }
-
-
     /**
      * Transform a string into an int array. Therefore, the string
      * <i>raw</i> must consist of int values separated by a <i>';'</i>.

http://dive4elements.wald.intevation.org