[PATCH 3 of 7] issue1435: SedimentYieldArtifact: Add functionality

Wald Commits scm-commit at wald.intevation.org
Fri Sep 27 14:33:27 CEST 2013


# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1380285448 -7200
# Node ID 644b2f461272b8fed2acd35e83125bb3c2341d8f
# Parent  963b8bd54a638716b6503259dbb0c7024b3ffb54
issue1435: SedimentYieldArtifact: Add functionality.
Now the overriden state can actually access the load.

diff -r 963b8bd54a63 -r 644b2f461272 artifacts/src/main/java/org/dive4elements/river/artifacts/SedimentYieldArtifact.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/SedimentYieldArtifact.java	Fri Sep 27 14:36:05 2013 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/SedimentYieldArtifact.java	Fri Sep 27 14:37:28 2013 +0200
@@ -23,9 +23,12 @@
 import org.dive4elements.artifacts.CallMeta;
 import org.dive4elements.artifacts.common.utils.XMLUtils;
 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType;
+import org.dive4elements.river.artifacts.model.Calculation;
+import org.dive4elements.river.artifacts.model.CalculationResult;
 import org.dive4elements.river.artifacts.model.minfo.SedimentLoad;
 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadFacet;
 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadFactory;
+import org.dive4elements.river.artifacts.model.minfo.SedimentLoadResult;
 import org.dive4elements.river.artifacts.states.StaticState;
 
 import org.dive4elements.river.artifacts.model.FacetTypes;
@@ -76,9 +79,27 @@
     }
 
 
+    private Object getSedimentLoad() {
+        logger.debug("SedimentYieldArtifact.getSedimentLoad");
+        String id = getDataAsString(DATA_NAME);
+        String river = getDataAsString("river");
+
+        SedimentLoad myLoad = SedimentLoadFactory.getSedimentLoadWithDataUncached(id, river);
+        return new CalculationResult(
+            new SedimentLoadResult[] {
+                new SedimentLoadResult(1983,2042,myLoad)
+            }, new Calculation());
+    }
+
+
     /** Create a new state with bogus output. */
     protected State spawnState() {
-        state = new StaticState(STATIC_STATE_NAME);
+        state = new StaticState(STATIC_STATE_NAME) {
+
+            public Object staticCompute(List<Facet> facets) {
+                 return getSedimentLoad();
+            }
+        };
         List<Facet> fs = getFacets(STATIC_STATE_NAME);
         DefaultOutput output = new DefaultOutput(
             "general",
@@ -106,9 +127,14 @@
     {
         logger.debug("SedimentYieldArtifact.setup");
 
+        // Refactor? this happens at another place, too
         // Store id, yield yields.
-        state = new StaticState(STATIC_STATE_NAME);
+        state = new StaticState(STATIC_STATE_NAME) {
 
+            public Object staticCompute(List<Facet> facets) {
+                 return getSedimentLoad();
+            }
+        };
         if (logger.isDebugEnabled()) {
             logger.debug(XMLUtils.toString(data));
         }
@@ -119,16 +145,12 @@
         // TODO need river, too.
         //
         if (code != null) {
-            // parse code, interact with factory, add real facets.
-            // store relevant parts of code as data.
-            // TODO no fakes
-            String fakeRiver = "Elbe";
-            SedimentLoad myLoad = SedimentLoadFactory.getSedimentLoadWithDataUncached(code, fakeRiver);
-            String name = myLoad.getDescription();
+            String name = SedimentLoadFactory.getSedimentYieldDescription(Integer.valueOf(code));
 
             Facet facet = new SedimentLoadFacet(
-                0, name,
+                0,
                 SEDIMENT_LOAD_COARSE,
+                name,
                 //????
                 ComputeType.ADVANCE, state.getID(), "hash"
                 );
@@ -200,8 +222,8 @@
         Object context,
         CallMeta meta)
     {
-        logger.debug("initialize");
-        // TODO Copy river data!
+        logger.debug("SedimentYieldArtifact.initialize");
+        importData((D4EArtifact) artifact, "river");
     }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :


More information about the Dive4elements-commits mailing list