changeset 2693:edaa2297aea3

Started module MINFO (MINFOArtifact, state to choose calculations, configurations). flys-artifacts/trunk@4397 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 14 May 2012 08:09:10 +0000
parents 32b1e28edb15
children 28c3f6588011
files flys-artifacts/ChangeLog flys-artifacts/doc/conf/artifacts/minfo.xml flys-artifacts/doc/conf/conf.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/MINFOArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/CalculationSelectMinfo.java flys-artifacts/src/main/resources/messages.properties flys-artifacts/src/main/resources/messages_de.properties flys-artifacts/src/main/resources/messages_de_DE.properties flys-artifacts/src/main/resources/messages_en.properties
diffstat 9 files changed, 437 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Sun May 13 21:39:55 2012 +0000
+++ b/flys-artifacts/ChangeLog	Mon May 14 08:09:10 2012 +0000
@@ -1,3 +1,22 @@
+2012-05-14  Ingo Weinzierl <ingo@intevation.de>
+
+	* doc/conf/artifacts/minfo.xml: New Artifact configuration for module
+	  MINFO.
+
+	* src/main/java/de/intevation/flys/artifacts/MINFOArtifact.java: New
+	  Artifact for module INFO.
+
+	* src/main/java/de/intevation/flys/artifacts/states/CalculationSelectMinfo.java:
+	  New. The state is used for choosing the calculation in module MINFO.
+
+	* doc/conf/conf.xml: Registered the MINFO Artifact.
+
+	* src/main/resources/messages.properties,
+	  src/main/resources/messages_de_DE.properties,
+	  src/main/resources/messages_en.properties,
+	  src/main/resources/messages_de.properties: New strings for states and
+	  calculations.
+
 2012-05-13  Felix Wolfsteller <felix.wolfsteller@intevation.de>
 
 	* src/main/java/de/intevation/flys/exports/DurationCurveGenerator.java:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/doc/conf/artifacts/minfo.xml	Mon May 14 08:09:10 2012 +0000
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<artifact name="minfo">
+
+    <states>
+        <state id="state.minfo.river" description="state.minfo.river" state="de.intevation.flys.artifacts.states.RiverSelect" helpText="help.index">
+            <data name="river" type="String" />
+        </state>
+
+        <transition transition="de.intevation.flys.artifacts.transitions.DefaultTransition">
+                <from state="state.minfo.river"/>
+                <to state="state.minfo.calculation_mode"/>
+        </transition>
+
+        <state id="state.minfo.calculation_mode" description="state.minfo.calculation_mode" state="de.intevation.flys.artifacts.states.CalculationSelectMinfo" helpText="help.minfo">
+            <data name="calculation_mode" type="String"/>
+        </state>
+    </states>
+
+</artifact>
--- a/flys-artifacts/doc/conf/conf.xml	Sun May 13 21:39:55 2012 +0000
+++ b/flys-artifacts/doc/conf/conf.xml	Mon May 14 08:09:10 2012 +0000
@@ -98,6 +98,11 @@
             <artifact-factory name="fixanalysis" description="Factory to create an artifact to be used in fixation analysis."
                 ttl="3600000"
                 artifact="de.intevation.flys.artifacts.FixationArtifact">de.intevation.artifactdatabase.DefaultArtifactFactory</artifact-factory>
+
+            <!-- MINFO specific Artifacts -->
+            <artifact-factory name="minfo" description="Factory to create an artifact to be used in module minfo."
+                ttl="3600000"
+                artifact="de.intevation.flys.artifacts.MINFOArtifact">de.intevation.artifactdatabase.DefaultArtifactFactory</artifact-factory>
         </artifact-factories>
 
         <user-factory name="default" description="Factory to create new users">de.intevation.artifactdatabase.DefaultUserFactory</user-factory>
@@ -171,6 +176,7 @@
     <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="minfo" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${artifacts.config.dir}/artifacts/minfo.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" />
         <artifact name="hyk" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${artifacts.config.dir}/artifacts/hyk.xml" />
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/MINFOArtifact.java	Mon May 14 08:09:10 2012 +0000
@@ -0,0 +1,248 @@
+package de.intevation.flys.artifacts;
+
+import de.intevation.artifactdatabase.ProtocolUtils;
+
+import de.intevation.artifactdatabase.state.Output;
+import de.intevation.artifactdatabase.state.State;
+import de.intevation.artifactdatabase.state.StateEngine;
+
+import de.intevation.artifactdatabase.transition.TransitionEngine;
+
+import de.intevation.artifacts.CallContext;
+import de.intevation.artifacts.Message;
+
+import de.intevation.artifacts.common.ArtifactNamespaceContext;
+
+import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;
+
+import de.intevation.artifacts.common.utils.XMLUtils;
+
+import de.intevation.flys.artifacts.context.FLYSContext;
+
+import de.intevation.flys.artifacts.model.CalculationMessage;
+import de.intevation.flys.artifacts.model.FacetTypes;
+
+import de.intevation.flys.artifacts.states.DefaultState;
+
+import de.intevation.flys.utils.FLYSUtils;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * The default MINFO artifact.
+ *
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class MINFOArtifact
+extends      FLYSArtifact
+implements   FacetTypes {
+
+    /** The logger for this class. */
+    private static Logger logger = Logger.getLogger(MINFOArtifact.class);
+
+    /** The name of the artifact. */
+    public static final String ARTIFACT_NAME = "minfo";
+
+    /** XPath */
+    public static final String XPATH_STATIC_UI ="/art:result/art:ui/art:static";
+
+
+    /**
+     * The default constructor.
+     */
+    public MINFOArtifact() {
+    }
+
+
+    /**
+     * This method returns a description of this artifact.
+     *
+     * @param data Some data.
+     * @param context The CallContext.
+     *
+     * @return the description of this artifact.
+     */
+    public Document describe(Document data, CallContext context) {
+        logger.debug("Describe: the current state is: " + getCurrentStateId());
+
+        FLYSContext flysContext = FLYSUtils.getFlysContext(context);
+        StateEngine stateEngine = (StateEngine) flysContext.get(
+            FLYSContext.STATE_ENGINE_KEY);
+
+        TransitionEngine transitionEngine = (TransitionEngine) flysContext.get(
+            FLYSContext.TRANSITION_ENGINE_KEY);
+
+        List<State> reachable = transitionEngine.getReachableStates(
+            this, getCurrentState(context), stateEngine);
+
+        Document description            = XMLUtils.newDocument();
+        XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator(
+            description,
+            ArtifactNamespaceContext.NAMESPACE_URI,
+            ArtifactNamespaceContext.NAMESPACE_PREFIX);
+
+        Element root = ProtocolUtils.createRootNode(creator);
+        description.appendChild(root);
+
+        State current = getCurrentState(context);
+
+        ProtocolUtils.appendDescribeHeader(creator, root, identifier(), hash());
+        ProtocolUtils.appendState(creator, root, current);
+        ProtocolUtils.appendReachableStates(creator, root, reachable);
+
+        appendBackgroundActivity(creator, root, context);
+
+        Element name = ProtocolUtils.createArtNode(
+            creator, "name",
+            new String[] { "value" },
+            new String[] { getName() });
+
+        Element ui = ProtocolUtils.createArtNode(
+            creator, "ui", null, null);
+
+        Element staticUI  = ProtocolUtils.createArtNode(
+            creator, "static", null, null);
+
+        Element outs = ProtocolUtils.createArtNode(
+            creator, "outputmodes", null, null);
+        appendOutputModes(description, outs, context, identifier());
+
+        appendStaticUI(description, staticUI, context, identifier());
+
+        Element dynamic = current.describe(
+            this,
+            description,
+            root,
+            context,
+            identifier());
+
+        if (dynamic != null) {
+            ui.appendChild(dynamic);
+        }
+
+        ui.appendChild(staticUI);
+
+        root.appendChild(name);
+        root.appendChild(ui);
+        root.appendChild(outs);
+
+        return description;
+    }
+
+
+    /**
+     * Returns the name of the concrete artifact.
+     *
+     * @return the name of the concrete artifact.
+     */
+    public String getName() {
+        return ARTIFACT_NAME;
+    }
+
+
+    protected static void appendBackgroundActivity(
+        ElementCreator cr,
+        Element        root,
+        CallContext    context
+    ) {
+        Element inBackground = cr.create("background-processing");
+        root.appendChild(inBackground);
+
+        cr.addAttr(
+            inBackground,
+            "value",
+            String.valueOf(context.isInBackground()),
+            true);
+
+        LinkedList<Message> messages = context.getBackgroundMessages();
+
+        if (messages == null) {
+            return;
+        }
+
+        CalculationMessage  message  = (CalculationMessage) messages.getLast();
+        cr.addAttr(
+            inBackground,
+            "steps",
+            String.valueOf(message.getSteps()),
+            true);
+
+        cr.addAttr(
+            inBackground,
+            "currentStep",
+            String.valueOf(message.getCurrentStep()),
+            true);
+
+        inBackground.setTextContent(message.getMessage());
+    }
+
+
+    /**
+     * Append output mode nodes to a document.
+     */
+    protected void appendOutputModes(
+        Document    doc,
+        Element     outs,
+        CallContext context,
+        String      uuid)
+    {
+        List<Output> generated = getOutputs(context);
+        logger.debug("This Artifact has " + generated.size() + " Outputs.");
+
+        ProtocolUtils.appendOutputModes(doc, outs, generated);
+    }
+
+
+    /**
+     * This method appends the static data - that has already been inserted by
+     * the user - to the static node of the DESCRIBE document.
+     *
+     * @param doc The document.
+     * @param ui The root node.
+     * @param context The CallContext.
+     * @param uuid The identifier of the artifact.
+     */
+    protected void appendStaticUI(
+        Document    doc,
+        Node        ui,
+        CallContext context,
+        String uuid)
+    {
+        List<String> stateIds = getPreviousStateIds();
+
+        FLYSContext flysContext = FLYSUtils.getFlysContext(context);
+        StateEngine engine      = (StateEngine) flysContext.get(
+            FLYSContext.STATE_ENGINE_KEY);
+
+        for (String stateId: stateIds) {
+            logger.debug("Append static data for state: " + stateId);
+            DefaultState state = (DefaultState) engine.getState(stateId);
+
+            ui.appendChild(state.describeStatic(this, doc, ui, context, uuid));
+        }
+    }
+
+
+    /**
+     * 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) {
+        logger.warn("MINFOArtifact.getInitialFacetActivity: not implemented!");
+        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/states/CalculationSelectMinfo.java	Mon May 14 08:09:10 2012 +0000
@@ -0,0 +1,109 @@
+package de.intevation.flys.artifacts.states;
+
+import org.apache.log4j.Logger;
+
+import org.w3c.dom.Element;
+
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.CallContext;
+import de.intevation.artifacts.CallMeta;
+
+import de.intevation.artifacts.common.utils.XMLUtils;
+
+import de.intevation.artifactdatabase.data.StateData;
+
+import de.intevation.flys.artifacts.FLYSArtifact;
+import de.intevation.flys.artifacts.resources.Resources;
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class CalculationSelectMinfo extends DefaultState {
+
+    /** The logger that is used in this class. */
+    private static Logger logger = Logger.getLogger(CalculationSelectMinfo.class);
+
+
+    public static final String FIELD_MODE = "calculation_mode";
+
+    public static final String CALC_BED_MIDDLE    = "calc.bed.middle";
+    public static final String CALC_BED_DIFF      = "calc.bed.diff";
+    public static final String CALC_BED_QUALITY   = "calc.bed.quality";
+    public static final String CALC_SEDIMENT_LOAD = "calc.sediment.load";
+    public static final String CALC_FLOW_VELOCITY = "calc.flow.velocity";
+    public static final String CALC_SQ_RELATION   = "calc.sq.relation";
+
+    /** An array that holds all available calculation modes. */
+    public static final String[] CALCULATIONS = {
+        CALC_BED_MIDDLE,
+        CALC_BED_DIFF,
+        CALC_BED_QUALITY,
+        CALC_SEDIMENT_LOAD,
+        CALC_FLOW_VELOCITY,
+        CALC_SQ_RELATION
+    };
+
+
+    /** Error message that is thrown if no mode has been chosen. */
+    public static final String ERROR_NO_CALCULATION_MODE =
+        "error_feed_no_calculation_mode";
+
+    /** Error message that is thrown if an invalid calculation mode has been
+     * chosen. */
+    public static  final String ERROR_INVALID_CALCULATION_MODE =
+        "error_feed_invalid_calculation_mode";
+
+
+    public CalculationSelectMinfo() {
+    }
+
+
+    @Override
+    protected Element[] createItems(
+        XMLUtils.ElementCreator cr,
+        Artifact    artifact,
+        String      name,
+        CallContext context)
+    {
+        CallMeta meta   = context.getMeta();
+        Element[] calcs = new Element[CALCULATIONS.length];
+
+        for (int i = 0; i < CALCULATIONS.length; ++i) {
+            String calc = CALCULATIONS[i];
+            calcs[i] = createItem(
+                cr, new String[] {
+                    Resources.getMsg(meta, calc, calc),
+                    calc
+                });
+        }
+
+        return calcs;
+    }
+
+
+    @Override
+    public boolean validate(Artifact artifact)
+    throws IllegalArgumentException
+    {
+        logger.debug("CalculationSelect.validate");
+        FLYSArtifact flys = (FLYSArtifact) artifact;
+
+        StateData data = getData(flys, FIELD_MODE);
+        String    calc = (data != null) ? (String) data.getValue() : null;
+
+        if (calc == null) {
+            throw new IllegalArgumentException(ERROR_NO_CALCULATION_MODE);
+        }
+
+        calc = calc.trim().toLowerCase();
+
+        for (String mode: CALCULATIONS) {
+            if (mode.equals(calc)) {
+                return true;
+            }
+        }
+
+        throw new IllegalArgumentException(ERROR_INVALID_CALCULATION_MODE);
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/flys-artifacts/src/main/resources/messages.properties	Sun May 13 21:39:55 2012 +0000
+++ b/flys-artifacts/src/main/resources/messages.properties	Mon May 14 08:09:10 2012 +0000
@@ -21,6 +21,9 @@
 state.fix.river = River
 state.fix.calculation.mode = Calculation Mode
 
+state.minfo.river = River
+state.minfo.calculation_mode = Calculation Mode
+
 historical.mode.w = Waterlevel Analyse
 historical.mode.q = Discharge Analyse
 
@@ -34,6 +37,12 @@
 calc.reference.curve = Reference Curve
 calc.fixation.default = Fixation
 calc.fixation.volmer = Balanced Waterlevel
+calc.bed.middle = Middle Bed Height
+calc.bed.diff = Bed Height Difference
+calc.bed.quality = Bed Quality
+calc.sediment.load = Sediment Load
+calc.flow.velocity = Flow Velocity
+calc.sq.relation = Load Discharge Relation
 
 state.chart.river = River
 state.chart.type = Charttype
--- a/flys-artifacts/src/main/resources/messages_de.properties	Sun May 13 21:39:55 2012 +0000
+++ b/flys-artifacts/src/main/resources/messages_de.properties	Mon May 14 08:09:10 2012 +0000
@@ -21,6 +21,9 @@
 state.fix.river = Gew\u00e4sser
 state.fix.calculation.mode = Berechnungsart
 
+state.minfo.river = Gew\u00e4sser
+state.minfo.calculation_mode = Berechnungsart
+
 historical.mode.w = Wasserstandsanalyse
 historical.mode.q = Abflussanalyse
 
@@ -34,6 +37,12 @@
 calc.reference.curve = Bezugslinie
 calc.fixation.default = Fixierungsanalyse
 calc.fixation.volmer = Ausgeglichene Wasserspiegellage
+calc.bed.middle = Mittlere Sohlh\u00f6he
+calc.bed.diff = Sohlh\u00f6hendifferenz
+calc.bed.quality = Sohlbeschaffenheit
+calc.sediment.load = Sedimentfracht
+calc.flow.velocity = Flie\u00dfgeschwindigkeit
+calc.sq.relation = Transport-Abfluss Beziehung
 
 state.chart.river = Gew\u00e4sser
 state.chart.type = Diagrammtyp
--- a/flys-artifacts/src/main/resources/messages_de_DE.properties	Sun May 13 21:39:55 2012 +0000
+++ b/flys-artifacts/src/main/resources/messages_de_DE.properties	Mon May 14 08:09:10 2012 +0000
@@ -21,6 +21,9 @@
 state.fix.river = Gew\u00e4sser
 state.fix.calculation.mode = Berechnungsart
 
+state.minfo.river = Gew\u00e4sser
+state.minfo.calculation_mode = Berechnungsart
+
 historical.mode.w = Wasserstandsanalyse
 historical.mode.q = Abflussanalyse
 
@@ -32,6 +35,12 @@
 calc.w.differences = Differenzen
 calc.historical.discharge.curve = Hist. Abflusskurven
 calc.reference.curve = Bezugslinie
+calc.bed.middle = Mittlere Sohlh\u00f6he
+calc.bed.diff = Sohlh\u00f6hendifferenz
+calc.bed.quality = Sohlbeschaffenheit
+calc.sediment.load = Sedimentfracht
+calc.flow.velocity = Flie\u00dfgeschwindigkeit
+calc.sq.relation = Transport-Abfluss Beziehung
 
 state.chart.river = Gew\u00e4sser
 state.chart.type = Diagrammtyp
--- a/flys-artifacts/src/main/resources/messages_en.properties	Sun May 13 21:39:55 2012 +0000
+++ b/flys-artifacts/src/main/resources/messages_en.properties	Mon May 14 08:09:10 2012 +0000
@@ -21,6 +21,9 @@
 state.fix.river = River
 state.fix.calculation.mode = Calculation Mode
 
+state.minfo.river = River
+state.minfo.calculation_mode = Calculation Mode
+
 historical.mode.w = Waterlevel Analyse
 historical.mode.q = Discharge Analyse
 
@@ -34,6 +37,12 @@
 calc.reference.curve = Reference Curve
 calc.fixation.default = Fixation
 calc.fixation.volmer = Balanced Waterlevel
+calc.bed.middle = Middle Bed Height
+calc.bed.diff = Bed Height Difference
+calc.bed.quality = Bed Quality
+calc.sediment.load = Sediment Load
+calc.flow.velocity = Flow Velocity
+calc.sq.relation = Load Discharge Relation
 
 state.chart.river = River
 state.chart.type = Charttype

http://dive4elements.wald.intevation.org