changeset 1629:4aec853a2f85

Added WaterlevelArtifact and respective infrastructure. flys-artifacts/trunk@2804 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 21 Sep 2011 14:28:39 +0000
parents 16c74ca3586e
children cafd8af6734a
files flys-artifacts/ChangeLog flys-artifacts/doc/conf/artifacts/waterlevel.xml flys-artifacts/doc/conf/conf.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/WaterlevelArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelInfoState.java
diffstat 5 files changed, 261 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Wed Sep 21 14:01:14 2011 +0000
+++ b/flys-artifacts/ChangeLog	Wed Sep 21 14:28:39 2011 +0000
@@ -1,3 +1,20 @@
+2011-09-21  Felix Wolfsteller <felix.wolfsteller@intevation.de>
+
+ Added WaterlevelArtifact to accompany WDifferencesPlots.
+
+	* src/main/java/de/intevation/flys/artifacts/WaterlevelArtifact.java:
+	  New WaterlevelArtifact.
+
+	* doc/conf/conf.xml:
+	  Added configuration for WaterlevelArtifact configuration (path to state-xml)
+	  waterlevel-factory.
+
+	* doc/conf/artifacts/waterlevel.xml:
+	  New, trivial state description for Waterlevelartifact.
+
+	* src/main/java/de/intevation/flys/artifacts/states/WaterlevelInfoState.java:
+	  New, only state for WaterlevelArtifact.
+
 2011-09-21  Felix Wolfsteller <felix.wolfsteller@intevation.de>
 
  Cosmetics, docs.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/doc/conf/artifacts/waterlevel.xml	Wed Sep 21 14:28:39 2011 +0000
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<artifact name="waterlevel">
+    <states>
+        <state id="state.waterlevel.done"
+               description="state.waterlevel.done"
+               state="de.intevation.flys.artifacts.states.WaterlevelInfoState">
+           <outputmodes>
+             <outputmode name="w_differences" description="output.w_differences" mime-type="image/png" type="chart">
+                  <facets>
+                     <facet name="longitudinal_section.w" description="facet.longitudinal_section.w" />
+                  </facets>
+              </outputmode>
+           </outputmodes>
+        </state>
+    </states>
+</artifact>
--- a/flys-artifacts/doc/conf/conf.xml	Wed Sep 21 14:01:14 2011 +0000
+++ b/flys-artifacts/doc/conf/conf.xml	Wed Sep 21 14:28:39 2011 +0000
@@ -23,6 +23,9 @@
             <artifact-factory name="annotations" description="Factory to create an artifact to access Annotations for Points at rivers"
                 ttl="3600000"
                 artifact="de.intevation.flys.artifacts.AnnotationArtifact">de.intevation.artifactdatabase.DefaultArtifactFactory</artifact-factory>
+            <artifact-factory name="waterlevel" description="Factory to create an artifact to access waterlevel data"
+                ttl="3600000"
+                artifact="de.intevation.flys.artifacts.WaterlevelArtifact">de.intevation.artifactdatabase.DefaultArtifactFactory</artifact-factory>
             <artifact-factory name="mainvalue" description="Factory to create an artifact to access Main Values for discharge curve diagrams"
                 ttl="3600000"
                 artifact="de.intevation.flys.artifacts.MainValuesArtifact">de.intevation.artifactdatabase.DefaultArtifactFactory</artifact-factory>
@@ -69,6 +72,7 @@
 
     <artifacts>
         <artifact name="winfo" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${artifacts.config.dir}/artifacts/winfo.xml" />
+        <artifact name="waterlevel" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${artifacts.config.dir}/artifacts/waterlevel.xml" />
         <artifact name="riveraxis" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${artifacts.config.dir}/artifacts/riveraxis.xml" />
         <artifact name="annotation" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${artifacts.config.dir}/artifacts/annotation.xml" />
         <artifact name="wmsbackground" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${artifacts.config.dir}/artifacts/wmsbackground.xml" />
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WaterlevelArtifact.java	Wed Sep 21 14:28:39 2011 +0000
@@ -0,0 +1,79 @@
+package de.intevation.flys.artifacts;
+
+import de.intevation.artifactdatabase.state.Facet;
+import de.intevation.artifactdatabase.state.Output;
+
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.CallMeta;
+
+import de.intevation.flys.artifacts.states.DefaultState;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+
+/**
+ * Clone of an WINFOArtifact to expose waterlevels only.
+ * @TODO Straighten inheritance-line (waterlevel-WINFO or vice versa).
+ */
+public class WaterlevelArtifact extends WINFOArtifact {
+
+    /** The logger for this class. */
+    private static Logger logger = Logger.getLogger(WaterlevelArtifact.class);
+
+    /** The name of the artifact. */
+    public static final String ARTIFACT_NAME = "waterlevel";
+
+
+    /**
+     * The default constructor.
+     */
+    public WaterlevelArtifact() {
+    }
+
+
+    /**
+     * Clone important stuff of an WINFOArtifact (called from factory).
+     */
+    protected void initialize(Artifact artifact,
+              Object context,
+              CallMeta meta) {
+        WINFOArtifact winfo = (WINFOArtifact) artifact;
+        this.data = winfo.cloneData();
+	logger.debug("Cloned data of winfo artifact.");
+        // Statically add Facets.
+        List<Facet> fs = new ArrayList<Facet>();
+        DefaultState state = (DefaultState) getCurrentState(context);
+        state.computeInit(this, hash(), context, meta, fs);
+        if (!fs.isEmpty()) { 
+            logger.debug("Facets to add in WaterlevelArtifact.initialize ."); 
+            facets.put(getCurrentStateId(), fs); 
+        } 
+        else { 
+            logger.debug("No facets to add in WaterlevelArtifact.initialize ("+state.getID()+")."); 
+        }
+	this.filterFacets = null;
+    }
+
+
+    /**
+     * Prevent filtering from taking place.
+     */
+    @Override
+    protected List<Output> filterOutputs(List<Output> outs) {
+       return outs;
+    }
+
+
+    /**
+     * Returns the name of the concrete artifact.
+     *
+     * @return the name of the concrete artifact.
+     */
+    public String getName() {
+        return ARTIFACT_NAME;
+    }
+}
+// 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/states/WaterlevelInfoState.java	Wed Sep 21 14:28:39 2011 +0000
@@ -0,0 +1,145 @@
+package de.intevation.flys.artifacts.states;
+
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import de.intevation.artifacts.CallContext;
+import de.intevation.artifacts.CallMeta;
+
+import de.intevation.artifactdatabase.state.Facet;
+
+import de.intevation.flys.artifacts.FLYSArtifact;
+import de.intevation.flys.artifacts.WINFOArtifact;
+import de.intevation.flys.artifacts.model.FacetTypes;
+import de.intevation.flys.artifacts.model.ReportFacet;
+import de.intevation.flys.artifacts.model.WaterlevelFacet;
+import de.intevation.flys.artifacts.model.WQKms;
+
+import de.intevation.flys.artifacts.model.DataFacet;
+import de.intevation.flys.artifacts.model.CrossSectionFacet;
+import de.intevation.flys.artifacts.model.CrossSectionWaterLineFacet;
+import de.intevation.flys.artifacts.model.CalculationResult;
+
+
+public class WaterlevelInfoState
+extends      DefaultState
+implements   FacetTypes
+{
+    /** The logger that is used in this state. */
+    private static Logger logger = Logger.getLogger(WaterlevelInfoState.class);
+
+
+    @Override
+    protected String getUIProvider() {
+        return "noinput";
+    }
+
+
+    public Object computeInit(
+        FLYSArtifact artifact,
+        String       hash,
+        Object       context,
+        CallMeta     meta,
+        List<Facet>  facets
+    ) {
+        return compute((WINFOArtifact) artifact, hash, facets, null);
+    }
+
+
+    protected Object compute(
+        WINFOArtifact winfo,
+        String        hash,
+        List<Facet>   facets,
+        Object        old
+    ) {
+        logger.debug("WaterlevelInfoState.compute");
+        String id = getID();
+
+        CalculationResult res = old instanceof CalculationResult
+            ? (CalculationResult)old
+            : winfo.getWaterlevelData();
+
+        if (facets == null) {
+            return res;
+        }
+
+        WQKms [] wqkms = (WQKms [])res.getData();
+
+        for (int i = 0; i < wqkms.length; i++) {
+            String nameW = null;
+            String nameQ = null;
+
+            if (winfo.isQ()) {
+                nameQ = wqkms[i].getName();
+                nameW = "W(" + nameQ + ")";
+            }
+            else {
+                nameW = wqkms[i].getName();
+                nameQ = "Q(" + nameQ + ")";
+            }
+
+            logger.debug("WaterlevelInfoState Create facet: " + nameW);
+            logger.debug("WaterlevelInfoState Create facet: " + nameQ);
+
+            Facet w = new WaterlevelFacet(
+                i, LONGITUDINAL_W, nameW, ComputeType.ADVANCE, id, hash);
+            Facet q = new WaterlevelFacet(
+                i, LONGITUDINAL_Q, nameQ, ComputeType.ADVANCE, id, hash);
+
+            facets.add(w);
+            facets.add(q);
+        }
+
+        if (wqkms.length > 0) {
+            Facet wst = new DataFacet(
+                WST, "WST data", ComputeType.ADVANCE, hash, id);
+            Facet csv = new DataFacet(
+                CSV, "CSV data", ComputeType.ADVANCE, hash, id);
+
+            facets.add(wst);
+            facets.add(csv);
+        }
+
+        if (res.getReport().hasProblems()) {
+            facets.add(new ReportFacet(ComputeType.ADVANCE, hash, id));
+        }
+
+        // Also register the CrossSectionFacet (added to respective out).
+        facets.add(new CrossSectionFacet(winfo.getCrossSectionName()));
+        // Assume to be in wq_single mode.
+        facets.add(new CrossSectionWaterLineFacet("Q=" + winfo.getDataAsString("wq_single")));
+        return res;
+    }
+
+
+    /**
+     * @param context Ignored.
+     */
+    @Override
+    public Object computeFeed(
+        FLYSArtifact artifact,
+        String       hash,
+        CallContext  context,
+        List<Facet>  facets,
+        Object       old
+    ) {
+        return compute((WINFOArtifact) artifact, hash, facets, old);
+    }
+
+
+    /**
+     * @param context Ignored.
+     */
+    @Override
+    public Object computeAdvance(
+        FLYSArtifact artifact,
+        String       hash,
+        CallContext  context,
+        List<Facet>  facets,
+        Object       old
+    ) {
+        return compute((WINFOArtifact) artifact, hash, facets, old);
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org