[Dive4elements-commits] [PATCH 3 of 8] Refactor BedHeightArtifacts to provide bed height single values of a range

Wald Commits scm-commit at wald.intevation.org
Thu Nov 15 16:31:32 CET 2012


# HG changeset patch
# User Björn Ricks <bjoern.ricks at intevation.de>
# Date 1352992802 -3600
# Node ID b838d16c629ea3c6a263c1c1c671ab0896329d42
# Parent  1619f80eb62ebce85fc31e9aad4537c2bf510b4a
Refactor BedHeightArtifacts to provide bed height single values of a range

The range of bed height single values is necessary to generate a chart for
sounding widths.

diff -r 1619f80eb62e -r b838d16c629e flys-artifacts/src/main/java/de/intevation/flys/artifacts/BedHeightsArtifact.java
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/BedHeightsArtifact.java	Thu Nov 15 16:18:02 2012 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/BedHeightsArtifact.java	Thu Nov 15 16:20:02 2012 +0100
@@ -6,25 +6,29 @@
 import org.apache.log4j.Logger;
 import org.w3c.dom.Document;
 
+import de.intevation.artifactdatabase.state.DefaultOutput;
 import de.intevation.artifactdatabase.state.Facet;
 import de.intevation.artifactdatabase.state.FacetActivity;
-import de.intevation.artifactdatabase.state.State;
 import de.intevation.artifacts.ArtifactFactory;
+import de.intevation.artifacts.Artifact;
 import de.intevation.artifacts.CallMeta;
 import de.intevation.artifacts.common.utils.XMLUtils;
 import de.intevation.flys.artifacts.model.minfo.BedHeight;
 import de.intevation.flys.artifacts.model.minfo.BedHeightFacet;
 import de.intevation.flys.artifacts.model.minfo.BedHeightFactory;
 import de.intevation.flys.artifacts.states.StaticState;
+import de.intevation.flys.model.BedHeightSingle;
+import de.intevation.flys.model.BedHeightSingleValue;
 
 public class BedHeightsArtifact
-extends      StaticFLYSArtifact
+extends      AbstractStaticStateArtifact
 {
     /** The logger for this class. */
     private static Logger logger =
         Logger.getLogger(BedHeightsArtifact.class);
 
     private static final String NAME = "bedheights";
+    private static final String STATIC_FACET_NAME = "bedheight";
 
     static {
         // TODO: Move to configuration.
@@ -40,10 +44,6 @@
     public static final String DATA_HEIGHT_TYPE =
         "height_marks";
 
-    /** One and only state to be in. */
-    protected transient State state = null;
-
-
     /**
      * Trivial Constructor.
      */
@@ -69,53 +69,44 @@
     {
         logger.debug("BedHeightsArtifact.setup");
 
-        state = new StaticState(STATIC_STATE_NAME);
-
         if (logger.isDebugEnabled()) {
             logger.debug(XMLUtils.toString(data));
         }
 
-        List<Facet> fs = new ArrayList<Facet>();
         String code = getDatacageIDValue(data);
 
         if (code != null) {
             String [] parts = code.split("-");
 
             if (parts.length >= 4) {
-                if (parts[0].equals("bedheight")) {
-                    addStringData("type", parts[1]);
+                String name = parts[0];
+                String type = parts[1];
+                String btype = type;
+                int hId = Integer.parseInt(parts[2]);
+                if (name.equals("bedheight")) {
+                    addStringData("type", type);
                     addStringData("height_id", parts[2]);
                     addStringData("time", parts[3]);
                 }
-                int hId = Integer.parseInt(parts[2]);
-                String bedHName = BedHeightFactory.getHeightName(parts[1], hId);
+                if (type.equals("singlevalues")) {
+                    btype = "single";
+                }
 
-                Facet bedHFacet = new BedHeightFacet(
-                    "bedheight",
-                    bedHName);
+                String bedHName = BedHeightFactory.getHeightName(btype, hId);
 
-                fs.add(bedHFacet);
-                addFacets(state.getID(), fs);
+                Facet facet = new BedHeightFacet(
+                        STATIC_FACET_NAME, bedHName, type);
+
+                ArrayList<Facet> facets = new ArrayList<Facet>(1);
+                facets.add(facet);
+
+                addFacets(STATIC_STATE_NAME, facets);
             }
         }
-
-        //spawnState();
         super.setup(identifier, factory, context, callMeta, data);
     }
 
     /**
-     * Get a list containing the one and only State.
-     * @param  context ignored.
-     * @return list with one and only state.
-     */
-    @Override
-    protected List<State> getStates(Object context) {
-        ArrayList<State> states = new ArrayList<State>();
-        states.add(state);
-        return states;
-    }
-
-    /**
      */
     public BedHeight getHeight() {
         return BedHeightFactory.getHeight(
@@ -123,5 +114,45 @@
             Integer.parseInt(getDataAsString("height_id")),
             Integer.parseInt(getDataAsString("time")));
     }
+
+    public List<BedHeightSingleValue> getSingleValues() {
+        logger.debug("getSingleValues");
+        BedHeightSingle single = BedHeightSingle.getBedHeightSingleById(
+                getDataAsInteger("height_id"));
+        return BedHeightSingleValue.getBedHeightSingleValues(single,
+                getDataAsDouble("ld_from"),
+                getDataAsDouble("ld_to"));
+    }
+
+    @Override
+    protected void initStaticState() {
+
+        logger.debug("initStaticState " + getName() + " " + identifier());
+
+        StaticState state = new StaticState(STATIC_STATE_NAME);
+        DefaultOutput output = new DefaultOutput(
+                "general",
+                "general",
+                "image/png",
+                "chart");
+
+        List<Facet> facets = getFacets(STATIC_STATE_NAME);
+        output.addFacets(facets);
+        state.addOutput(output);
+
+        setStaticState(state);
+    }
+
+    @Override
+    protected void initialize(Artifact artifact, Object context, CallMeta meta) {
+        // do not clone facets, etc. from master artifact
+
+        logger.debug("initialize");
+        importData((FLYSArtifact)artifact, "ld_from");
+        importData((FLYSArtifact)artifact, "ld_to");
+
+        logger.debug("ld_from " + getDataAsString("ld_from"));
+        logger.debug("ld_to " + getDataAsString("ld_to"));
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :


More information about the Dive4elements-commits mailing list