diff artifacts/src/main/java/org/dive4elements/river/artifacts/states/WDifferencesState.java @ 8547:04367906f158

(issue1754) Add distantce handling to WINFO differences state
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 16 Feb 2015 12:55:38 +0100
parents 522f72f43ae6
children fa57a2cb1dfa
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/WDifferencesState.java	Mon Feb 16 11:30:27 2015 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/WDifferencesState.java	Mon Feb 16 12:55:38 2015 +0100
@@ -19,6 +19,7 @@
 
 import org.dive4elements.artifacts.CallContext;
 import org.dive4elements.artifacts.Artifact;
+import org.dive4elements.river.artifacts.access.RangeAccess;
 import org.dive4elements.river.artifacts.ChartArtifact;
 import org.dive4elements.river.artifacts.D4EArtifact;
 import org.dive4elements.river.artifacts.FixationArtifact;
@@ -108,25 +109,12 @@
     /**
      * Access the data (wkms) of an artifact, coded in mingle.
      */
-    public WKms getWKms(String mingle, CallContext context) {
+    public WKms getWKms(String mingle, CallContext context, double from, double to) {
         log.debug("WDifferencesState.getWKms " + mingle);
         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);
-            log.debug("WDifferencesState obtain data from StaticWKms");
-            WKms wkms = staticWKms.getWKms(idx);
-            if (wkms == null)
-                log.error("No WKms from artifact.");
-            return wkms;
-        }
-
         D4EArtifact d4eArtifact = RiverUtils.getArtifact(
             uuid,
             context);
@@ -136,7 +124,16 @@
             return null;
         }
 
-        if (d4eArtifact instanceof WINFOArtifact) {
+        if (d4eArtifact instanceof StaticWKmsArtifact) {
+            StaticWKmsArtifact staticWKms = (StaticWKmsArtifact) d4eArtifact;
+            log.debug("WDifferencesState obtain data from StaticWKms");
+            WKms wkms = staticWKms.getWKms(idx, from, to);
+            if (wkms == null) {
+                log.error("No WKms from Static artifact for this range.");
+                return new WQKms();
+            }
+            return wkms;
+        } else if (d4eArtifact instanceof WINFOArtifact) {
             log.debug("Get WKms from WINFOArtifact");
             WINFOArtifact flys = (WINFOArtifact) d4eArtifact;
 
@@ -150,13 +147,11 @@
                 return new WQKms();
             }
             return wkms[idx];
-        }
-        else if (d4eArtifact instanceof MINFOArtifact) {
+        } else if (d4eArtifact instanceof MINFOArtifact) {
             log.warn("Get WKms from MINFOArtifact not implemented!");
 //            CalculationResult r = (CalculationResult)
 //                d4eArtifact.compute(context, ComputeType.ADVANCE, false);
-        }
-        else if (d4eArtifact instanceof FixationArtifact) {
+        } else if (d4eArtifact instanceof FixationArtifact) {
             log.debug ("Get WKms from FixationArtifact.");
             CalculationResult r = (CalculationResult)
                 d4eArtifact.compute(context, ComputeType.ADVANCE, false);
@@ -188,7 +183,9 @@
         }
         WINFOArtifact winfo = (WINFOArtifact) artifact;
         String id = getID();
-
+        RangeAccess rangeAccess = new RangeAccess(artifact);
+        double from = rangeAccess.getFrom();
+        double to = rangeAccess.getTo();
         // Load the Artifacts/facets that we want to subtract and display.
         // Expected format is:
         // [42537f1e-3522-42ef-8968-635b03d8e9c6;longitudinal_section.w;0]#[1231f2-....]
@@ -213,9 +210,9 @@
             // e.g.:
             // 42537f1e-3522-42ef-8968-635b03d8e9c6;longitudinal_section.w;1
             WKms minuendWKms = getWKms(StringUtil.unbracket(datas[i+0]),
-                context);
+                context, from, to);
             WKms subtrahendWKms = getWKms(StringUtil.unbracket(datas[i+1]),
-                context);
+                context, from, to);
 
             String facetName = "diff ()";
             String minName = "min";

http://dive4elements.wald.intevation.org