changeset 6582:7216143665d9

issue1394, issue1366: Prepare difference state to handle other artifacts, esp. FixationArtifacts (for vollmer-curves).
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 17 Jul 2013 12:15:00 +0200 (2013-07-17)
parents 5f0e3e9cf6f3
children e7e5b40cccc3
files artifacts/src/main/java/org/dive4elements/river/artifacts/states/WDifferencesState.java
diffstat 1 files changed, 36 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/WDifferencesState.java	Wed Jul 17 12:10:23 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/WDifferencesState.java	Wed Jul 17 12:15:00 2013 +0200
@@ -18,10 +18,12 @@
 
 import org.dive4elements.artifacts.CallContext;
 import org.dive4elements.artifacts.Artifact;
+import org.dive4elements.river.artifacts.ChartArtifact;
 import org.dive4elements.river.artifacts.D4EArtifact;
+import org.dive4elements.river.artifacts.FixationArtifact;
+import org.dive4elements.river.artifacts.MINFOArtifact;
 import org.dive4elements.river.artifacts.StaticWKmsArtifact;
 import org.dive4elements.river.artifacts.WINFOArtifact;
-import org.dive4elements.river.artifacts.ChartArtifact;
 
 import org.dive4elements.river.artifacts.math.WKmsOperation;
 
@@ -29,11 +31,12 @@
 import org.dive4elements.river.artifacts.model.DataFacet;
 import org.dive4elements.river.artifacts.model.DifferenceCurveFacet;
 import org.dive4elements.river.artifacts.model.EmptyFacet;
-
 import org.dive4elements.river.artifacts.model.FacetTypes;
 import org.dive4elements.river.artifacts.model.WKms;
 import org.dive4elements.river.artifacts.model.WQKms;
 
+import org.dive4elements.river.artifacts.model.fixings.FixRealizingResult;
+
 import org.dive4elements.river.utils.RiverUtils;
 import org.dive4elements.river.utils.StringUtil;
 
@@ -76,9 +79,10 @@
 
 
     /**
-     * Access the data (wkms).
+     * Access the data (wkms) of an artifact, coded in mingle.
      */
     protected WKms getWKms(String mingle, CallContext context) {
+        logger.debug("WDifferencesState.getWKms " + mingle);
         String[] def  = mingle.split(";");
         String   uuid = def[0];
         String   name = def[1];
@@ -96,23 +100,45 @@
             return wkms;
         }
 
-        WINFOArtifact flys = (WINFOArtifact) RiverUtils.getArtifact(
+        D4EArtifact d4eArtifact = RiverUtils.getArtifact(
             uuid,
             context);
 
-        if (flys == null) {
+        if (d4eArtifact == null) {
             logger.warn("One of the artifacts (1) for diff calculation could not be loaded");
             return null;
         }
-        else{
+
+        if (d4eArtifact instanceof WINFOArtifact) {
+            logger.debug("Get WKms from WINFOArtifact");
+            WINFOArtifact flys = (WINFOArtifact) d4eArtifact;
+
             WQKms[] wqkms = (WQKms[]) flys.getWaterlevelData().
                                               getData();
-            if (wqkms == null)
-            logger.warn("not  waterlevels in artifact");
-            else if (wqkms.length < idx)
-            logger.warn("not enough waterlevels in artifact");
+            if (wqkms == null) {
+                logger.warn("no waterlevels in artifact");
+            }
+            else if (wqkms.length < idx+1) {
+                logger.warn("not enough waterlevels in artifact");
+                return new WQKms();
+            }
             return wqkms[idx];
         }
+        else if (d4eArtifact instanceof MINFOArtifact) {
+            logger.debug("Get WKms from MINFOArtifact");
+            CalculationResult r = (CalculationResult)
+                d4eArtifact.compute(context, ComputeType.ADVANCE, false);
+        }
+        else if (d4eArtifact instanceof FixationArtifact) {
+            logger.debug ("Get WKms from FixationArtifact.");
+            CalculationResult r = (CalculationResult)
+                d4eArtifact.compute(context, ComputeType.ADVANCE, false);
+            FixRealizingResult frR = (FixRealizingResult) r.getData();
+            return frR.getWQKms()[idx];
+        }
+
+        logger.error("Do not know how to handle (getWKms) minuend/subtrahend");
+        return null;
     }
 
 

http://dive4elements.wald.intevation.org