changeset 689:f8ac04b2dbd0 facets-slt

Added two more compute() methods to ComputeCallback to distinguish between different phases of the artifact. flys-artifacts/branches/facets-slt@2129 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 16 Jun 2011 08:43:58 +0000
parents dc3613c4daf6
children 3481cd37e609
files flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ComputeCallback.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ComputeCallbackAdapter.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ComputedDischargeCurveState.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DischargeLongitudinalSection.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DurationCurveState.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/LocationDistanceSelect.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java
diffstat 9 files changed, 107 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Thu Jun 16 08:25:06 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Thu Jun 16 08:43:58 2011 +0000
@@ -51,6 +51,7 @@
 import de.intevation.flys.artifacts.model.Segment;
 
 import de.intevation.flys.artifacts.states.DefaultState;
+import de.intevation.flys.artifacts.states.CalculationSelect;
 import de.intevation.flys.artifacts.states.LocationDistanceSelect;
 
 
@@ -194,6 +195,9 @@
 
         try {
             saveData(target, XPATH_FEED_INPUT, context);
+
+            compute(context);
+
             return describe(target, context);
         }
         catch (IllegalArgumentException iae) {
@@ -257,6 +261,8 @@
 
             setCurrentStateId(targetState);
 
+            compute(context);
+
             return describe(target, context);
         }
 
@@ -1038,6 +1044,45 @@
     }
 
 
+    /**
+     * Dispatches the computation request to compute(CallContext context, String
+     * hash) with the current hash value of the artifact which is provided by
+     * hash().
+     *
+     * @param context The CallContext.
+     */
+    public Object compute(CallContext context) {
+        return compute(context, hash());
+    }
+
+
+    /**
+     * Dispatches computation requests to the current state which needs to
+     * implement a createComputeCallback(String hash, FLYSArtifact artifact)
+     * method.
+     *
+     * @param context The CallContext.
+     * @param hash The hash value which is used to fetch computed data from
+     * cache.
+     *
+     * @return the computed data.
+     */
+    public Object compute(CallContext context, String hash) {
+        String calc = (String) getData(CalculationSelect.FIELD_MODE).getValue();
+
+        DefaultState current = (DefaultState) getCurrentState(context);
+
+        ComputeCallback callback = current.createComputeCallback(hash(), this);
+
+        if (callback == null) {
+            logger.info("There is no data which needs to be computed.");
+            return null;
+        }
+
+        return compute(hash, callback);
+    }
+
+
     public Object compute(String key, ComputeCallback callback) {
         Cache cache = CacheFactory.getCache(COMPUTING_CACHE);
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Thu Jun 16 08:25:06 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java	Thu Jun 16 08:43:58 2011 +0000
@@ -23,7 +23,6 @@
 import de.intevation.flys.model.Gauge;
 import de.intevation.flys.model.River;
 
-import de.intevation.flys.artifacts.states.CalculationSelect;
 import de.intevation.flys.artifacts.states.DefaultState;
 import de.intevation.flys.artifacts.context.FLYSContext;
 
@@ -246,45 +245,6 @@
 
 
     /**
-     * Dispatches the computation request to compute(CallContext context, String
-     * hash) with the current hash value of the artifact which is provided by
-     * hash().
-     *
-     * @param context The CallContext.
-     */
-    public Object compute(CallContext context) {
-        return compute(context, hash());
-    }
-
-
-    /**
-     * Dispatches computation requests to the current state which needs to
-     * implement a createComputeCallback(String hash, FLYSArtifact artifact)
-     * method.
-     *
-     * @param context The CallContext.
-     * @param hash The hash value which is used to fetch computed data from
-     * cache.
-     *
-     * @return the computed data.
-     */
-    public Object compute(CallContext context, String hash) {
-        String calc = (String) getData(CalculationSelect.FIELD_MODE).getValue();
-
-        DefaultState current = (DefaultState) getCurrentState(context);
-
-        ComputeCallback callback = current.createComputeCallback(hash(), this);
-
-        if (callback == null) {
-            logger.info("There is no data which needs to be computed.");
-            return null;
-        }
-
-        return compute(hash, callback);
-    }
-
-
-    /**
      * Returns the data that is computed by a waterlevel computation.
      *
      * @return an array of data triples that consist of W, Q and Kms.
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ComputeCallback.java	Thu Jun 16 08:25:06 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ComputeCallback.java	Thu Jun 16 08:43:58 2011 +0000
@@ -8,5 +8,9 @@
 public interface ComputeCallback {
 
     Object compute(List<Facet> facets);
+
+    Object computeAdvance(List<Facet> facets);
+
+    Object computeFeed(List<Facet> facets);
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ComputeCallbackAdapter.java	Thu Jun 16 08:43:58 2011 +0000
@@ -0,0 +1,33 @@
+package de.intevation.flys.artifacts.model;
+
+import java.util.List;
+
+import de.intevation.artifactdatabase.state.Facet;
+
+
+public class ComputeCallbackAdapter implements ComputeCallback {
+
+    @Override
+    public Object compute(List<Facet> facets) {
+        Object obj = computeAdvance(facets);
+
+        if (obj == null) {
+            obj = computeFeed(facets);
+        }
+
+        return obj;
+    }
+
+
+    @Override
+    public Object computeAdvance(List<Facet> facets) {
+        return null;
+    }
+
+
+    @Override
+    public Object computeFeed(List<Facet> facets) {
+        return null;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ComputedDischargeCurveState.java	Thu Jun 16 08:25:06 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ComputedDischargeCurveState.java	Thu Jun 16 08:43:58 2011 +0000
@@ -9,6 +9,7 @@
 import de.intevation.flys.artifacts.FLYSArtifact;
 import de.intevation.flys.artifacts.WINFOArtifact;
 import de.intevation.flys.artifacts.model.ComputeCallback;
+import de.intevation.flys.artifacts.model.ComputeCallbackAdapter;
 
 /**
  * The final state that will be reached after the discharge curve calculation
@@ -32,8 +33,10 @@
     {
         final WINFOArtifact winfo = (WINFOArtifact) flys;
 
-        return new ComputeCallback() {
-            public Object compute(List<Facet> facets) {
+        return new ComputeCallbackAdapter() {
+
+            @Override
+            public Object computeAdvance(List<Facet> facets) {
                 return winfo.getComputedDischargeCurveData();
             }
         };
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DischargeLongitudinalSection.java	Thu Jun 16 08:25:06 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DischargeLongitudinalSection.java	Thu Jun 16 08:43:58 2011 +0000
@@ -9,6 +9,7 @@
 import de.intevation.flys.artifacts.FLYSArtifact;
 import de.intevation.flys.artifacts.WINFOArtifact;
 import de.intevation.flys.artifacts.model.ComputeCallback;
+import de.intevation.flys.artifacts.model.ComputeCallbackAdapter;
 
 public class DischargeLongitudinalSection extends DefaultState {
 
@@ -22,8 +23,10 @@
     {
         final WINFOArtifact winfo = (WINFOArtifact) flys;
 
-        return new ComputeCallback() {
-            public Object compute(List<Facet> facets) {
+        return new ComputeCallbackAdapter() {
+
+            @Override
+            public Object computeAdvance(List<Facet> facets) {
                 return winfo.getDischargeLongitudinalSectionData();
             }
         };
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DurationCurveState.java	Thu Jun 16 08:25:06 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DurationCurveState.java	Thu Jun 16 08:43:58 2011 +0000
@@ -9,6 +9,7 @@
 import de.intevation.flys.artifacts.FLYSArtifact;
 import de.intevation.flys.artifacts.WINFOArtifact;
 import de.intevation.flys.artifacts.model.ComputeCallback;
+import de.intevation.flys.artifacts.model.ComputeCallbackAdapter;
 
 /**
  * The final state that will be reached after the duration curve calculation
@@ -31,8 +32,10 @@
     {
         final WINFOArtifact winfo = (WINFOArtifact) flys;
 
-        return new ComputeCallback() {
-            public Object compute(List<Facet> facets) {
+        return new ComputeCallbackAdapter() {
+
+            @Override
+            public Object computeAdvance(List<Facet> facets) {
                 return winfo.getDurationCurveData();
             }
         };
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/LocationDistanceSelect.java	Thu Jun 16 08:25:06 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/LocationDistanceSelect.java	Thu Jun 16 08:43:58 2011 +0000
@@ -22,6 +22,7 @@
 import de.intevation.flys.artifacts.FLYSArtifact;
 import de.intevation.flys.artifacts.WINFOArtifact;
 import de.intevation.flys.artifacts.model.ComputeCallback;
+import de.intevation.flys.artifacts.model.ComputeCallbackAdapter;
 import de.intevation.flys.artifacts.model.RiverFactory;
 import de.intevation.flys.artifacts.resources.Resources;
 
@@ -303,8 +304,10 @@
     {
         final WINFOArtifact winfo = (WINFOArtifact) flys;
 
-        return new ComputeCallback() {
-            public Object compute(List<Facet> facets) {
+        return new ComputeCallbackAdapter() {
+
+            @Override
+            public Object computeFeed(List<Facet> facets) {
                 return winfo.getDischargeCurveData();
             }
         };
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java	Thu Jun 16 08:25:06 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java	Thu Jun 16 08:43:58 2011 +0000
@@ -16,6 +16,7 @@
 import de.intevation.flys.artifacts.FLYSArtifact;
 import de.intevation.flys.artifacts.WINFOArtifact;
 import de.intevation.flys.artifacts.model.ComputeCallback;
+import de.intevation.flys.artifacts.model.ComputeCallbackAdapter;
 
 
 public class WaterlevelState extends DefaultState {
@@ -41,8 +42,10 @@
     {
         final WINFOArtifact winfo = (WINFOArtifact) flys;
 
-        return new ComputeCallback() {
-            public Object compute(List<Facet> facets) {
+        return new ComputeCallbackAdapter() {
+
+            @Override
+            public Object computeAdvance(List<Facet> facets) {
                 return winfo.getWaterlevelData();
             }
         };

http://dive4elements.wald.intevation.org