changeset 2172:3ecc76ef25a9

New, basic infrastructure for user-provided data ('manual points'). flys-artifacts/trunk@3767 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 26 Jan 2012 12:52:44 +0000
parents 9083e1b47b66
children 9317863e867b
files flys-artifacts/doc/conf/artifacts/manualpoints.xml flys-artifacts/doc/conf/conf.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/ManualPointsArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ManualPointsFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ManualPointsSingleState.java
diffstat 5 files changed, 315 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/doc/conf/artifacts/manualpoints.xml	Thu Jan 26 12:52:44 2012 +0000
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<artifact name="manualpoints">
+  <states>
+    <state id="state.manualpoints.static"
+               description="state.manualpoints.static"
+               state="de.intevation.flys.artifacts.states.ManualPointsSingleState">
+      <outputmodes>
+        <outputmode name="longitudinal_section" description="output.longitudinal_section" mime-type="image/png" type="chart">
+          <facets>
+            <facet name="manualpoints" description="Points provided by user." />
+          </facets>
+        </outputmode>
+      </outputmodes>
+    </state>
+  </states>
+</artifact>
--- a/flys-artifacts/doc/conf/conf.xml	Wed Jan 25 15:12:07 2012 +0000
+++ b/flys-artifacts/doc/conf/conf.xml	Thu Jan 26 12:52:44 2012 +0000
@@ -80,6 +80,9 @@
             <artifact-factory name="new_chart" description="Factory to create an artifact to be used for new chart"
                 ttl="3600000"
                 artifact="de.intevation.flys.artifacts.ChartArtifact">de.intevation.artifactdatabase.DefaultArtifactFactory</artifact-factory>
+            <artifact-factory name="manualpoints" description="Factory to create an artifact for storing and editing points added by the user."
+                ttl="3600000"
+                artifact="de.intevation.flys.artifacts.ManualPointsArtifact">de.intevation.artifactdatabase.DefaultArtifactFactory</artifact-factory>
         </artifact-factories>
 
         <user-factory name="default" description="Factory to create new users">de.intevation.artifactdatabase.DefaultUserFactory</user-factory>
@@ -131,6 +134,7 @@
         description="A CallContext.Listener to open and close Hibernatesessions">de.intevation.flys.artifacts.context.SessionCallContextListener</callcontext-listener>
 
     <artifacts>
+        <artifact name="manualpoints" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${artifacts.config.dir}/artifacts/manualpoints.xml" />
         <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="annotation" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${artifacts.config.dir}/artifacts/annotation.xml" />
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/ManualPointsArtifact.java	Thu Jan 26 12:52:44 2012 +0000
@@ -0,0 +1,130 @@
+package de.intevation.flys.artifacts;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import org.w3c.dom.Document;
+
+import de.intevation.artifactdatabase.data.DefaultStateData;
+import de.intevation.artifactdatabase.state.Facet;
+import de.intevation.artifactdatabase.state.DefaultOutput;
+import de.intevation.artifactdatabase.state.State;
+
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.ArtifactFactory;
+import de.intevation.artifacts.CallMeta;
+
+import de.intevation.flys.model.Gauge;
+import de.intevation.flys.model.MainValue;
+import de.intevation.flys.model.River;
+
+import de.intevation.flys.artifacts.model.Calculation;
+import de.intevation.flys.artifacts.model.FacetTypes;
+import de.intevation.flys.artifacts.model.MainValuesQFacet;
+import de.intevation.flys.artifacts.model.MainValuesWFacet;
+import de.intevation.flys.artifacts.model.NamedDouble;
+import de.intevation.flys.artifacts.model.WstValueTable;
+import de.intevation.flys.artifacts.model.WstValueTableFactory;
+
+import de.intevation.flys.artifacts.states.StaticState;
+import de.intevation.flys.artifacts.states.DefaultState;
+
+import de.intevation.flys.artifacts.resources.Resources;
+
+import de.intevation.flys.utils.FLYSUtils;
+
+
+/**
+ * Artifact to store user-added points.
+ */
+public class ManualPointsArtifact
+extends      StaticFLYSArtifact
+implements   FacetTypes
+{
+    /** The logger for this class. */
+    private static Logger logger = Logger.getLogger(ManualPointsArtifact.class);
+
+    /** The name of the artifact. */
+    public static final String ARTIFACT_NAME = "manualpoints";
+
+    /** Name of data item where points are stored (jsonized). */
+    public static final String POINT_DATA = "manualpoints.data";
+
+    /**
+     * Trivial Constructor.
+     */
+    public ManualPointsArtifact() {
+        logger.debug("ManualPointsArtifact.ManualPointsartifact()");
+    }
+
+
+    /**
+     * Gets called from factory, to set things up.
+     */
+    @Override
+    public void setup(
+        String          identifier,
+        ArtifactFactory factory,
+        Object          context,
+        CallMeta        callMeta,
+        Document        data)
+    {
+        logger.debug("ManualPointsArtifact.setup");
+        super.setup(identifier, factory, context, callMeta, data);
+        initialize(null, context, callMeta);
+    }
+
+
+    /** Return the name of this artifact. */
+    public String getName() {
+        return ARTIFACT_NAME;
+    }
+
+
+    /** Access state data storing the jsonstring with points. */
+    public String getPointsData() {
+        return getDataAsString(POINT_DATA);
+    }
+
+
+    /** Setup state and facet. */
+    @Override
+    protected void initialize(Artifact artifact, Object context, CallMeta meta) {
+        logger.debug("ManualPointsArtifact.initialize");
+        List<Facet> fs = new ArrayList<Facet>();
+        addStringData(POINT_DATA, "[]");
+
+        DefaultState state = (DefaultState) getCurrentState(context);
+        state.computeInit(this, hash(), context, meta, fs);
+        if (!fs.isEmpty()) { 
+            logger.debug("Facets to add in ManualPointsArtifact.initialize ."); 
+            facets.put(getCurrentStateId(), fs); 
+        } 
+        else { 
+            logger.debug("No facets to add in ManualPointsArtifact.initialize ("
+                + state.getID() + ").");
+        }
+    }
+
+
+    /**
+     * Determines Facets initial disposition regarding activity (think of
+     * selection in Client ThemeList GUI). This will be checked one time
+     * when the facet enters a collections describe document.
+     *
+     * @param facetName name of the facet.
+     * @param index     index of the facet.
+     * @return 0 if not active
+     */
+    @Override
+    public int getInitialFacetActivity(
+        String outputName,
+        String facetName,
+        int index)
+    {
+        return 1;
+    }
+}
+// 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/ManualPointsFacet.java	Thu Jan 26 12:52:44 2012 +0000
@@ -0,0 +1,77 @@
+package de.intevation.flys.artifacts.model;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.CallContext;
+
+import de.intevation.flys.artifacts.ManualPointsArtifact;
+
+import de.intevation.flys.jfree.FLYSAnnotation;
+
+import de.intevation.flys.model.Annotation;
+import de.intevation.flys.model.FastAnnotations;
+
+import de.intevation.artifactdatabase.state.DefaultFacet;
+import de.intevation.artifactdatabase.state.Facet;
+
+import de.intevation.flys.utils.FLYSUtils;
+
+import de.intevation.flys.artifacts.FLYSArtifact;
+
+
+/**
+ * Facet to access ManualPoints that where added by user.
+ */
+public class ManualPointsFacet
+extends      DefaultFacet
+{
+    /** Logger for this class. */
+    private static final Logger logger = Logger.getLogger(ManualPointsFacet.class);
+
+
+    /**
+     * Trivial Constructor.
+     */
+    public ManualPointsFacet() {
+    }
+
+
+    /**
+     * Trivial Constructor for a ManualPointsFacet.
+     *
+     * @param index       Database-Index to use.
+     * @param name        Name (~type) of Facet.
+     * @param description Description of Facet.
+     */
+    public ManualPointsFacet(int index, String name, String description) {
+        super(index, name, description);
+    }
+
+
+    /**
+     * Get List of ManualPointss for river from Artifact.
+     *
+     * @param artifact (ManualPoints-)Artifact to query for list of ManualPoints.
+     * @param context  Ignored.
+     */
+    @Override
+    public Object getData(Artifact artifact, CallContext context) {
+        ManualPointsArtifact pointsArtifact = (ManualPointsArtifact) artifact;
+        return pointsArtifact.getPointsData();
+    }
+
+
+    /** Do a deep copy. */
+    @Override
+    public Facet deepCopy() {
+        ManualPointsFacet copy = new ManualPointsFacet();
+        copy.set(this);
+        return copy;
+    }
+}
+// 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/ManualPointsSingleState.java	Thu Jan 26 12:52:44 2012 +0000
@@ -0,0 +1,88 @@
+package de.intevation.flys.artifacts.states;
+
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import de.intevation.artifacts.CallMeta;
+import de.intevation.artifacts.CallContext;
+
+import de.intevation.artifactdatabase.state.Facet;
+
+import de.intevation.flys.artifacts.FLYSArtifact;
+
+import de.intevation.flys.artifacts.model.ManualPointsFacet;
+import de.intevation.flys.artifacts.model.FacetTypes;
+
+import de.intevation.flys.artifacts.resources.Resources;
+
+
+/**
+ * The only state for an ManualPointArtifact.
+ */
+public class ManualPointsSingleState
+extends      DefaultState
+implements   FacetTypes
+{
+    /** Developer-centric description of facet. */
+    public static final String I18N_DESCRIPTION = "facet.longitudinal_section.manualpoint";
+
+    /** The logger that is used in this state. */
+    private static final Logger logger = Logger.getLogger(ManualPointsSingleState.class);
+
+
+    /**
+     * Add an ManualPointsFacet to list of Facets.
+     *
+     * @param artifact Ignored.
+     * @param hash Ignored.
+     * @param context Ignored.
+     * @param meta CallMeta to be used for internationalization.
+     * @param facets List to add ManualPointsFacet to.
+     *
+     * @return null.
+     */
+    public Object compute(
+        FLYSArtifact artifact,
+        String       hash,
+        CallMeta     meta,
+        List<Facet>  facets
+    ) {
+        logger.debug("ManualPointsSingleState.computeInit()");
+
+        ManualPointsFacet facet = new ManualPointsFacet(
+            0,
+            MANUALPOINTS,
+            //Resources.getMsg(meta, I18N_DESCRIPTION, I18N_DESCRIPTION));
+            ".(.,-)Punkt(Punkt,Komma,Strich)");
+
+        facets.add(facet);
+
+        return null;
+    }
+
+
+    @Override
+    public Object computeInit(
+        FLYSArtifact artifact,
+        String       hash,
+        Object       context,
+        CallMeta     meta,
+        List<Facet>  facets
+     ) {
+        return compute(artifact, hash, meta, facets);
+    }
+
+
+    @Override
+    public Object computeFeed(
+        FLYSArtifact artifact,
+        String hash,
+        CallContext context,
+        List<Facet> facets,
+        Object old
+    ) {
+        return compute(artifact, hash, context.getMeta(), facets);
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org