changeset 3573:374c2d70b982

Added stub of QSector-Artifact-infrastructure. flys-artifacts/trunk@5188 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 10 Aug 2012 10:25:47 +0000
parents b8b1280606c2
children 416288f88763
files flys-artifacts/ChangeLog flys-artifacts/doc/conf/artifacts/qsector.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/QSectorArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QSectorFacet.java
diffstat 4 files changed, 230 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Thu Aug 09 08:04:06 2012 +0000
+++ b/flys-artifacts/ChangeLog	Fri Aug 10 10:25:47 2012 +0000
@@ -1,3 +1,20 @@
+2012-08-10	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	* doc/conf/artifacts/qsector.xml:
+	  Trivial state model for qsector artifact.
+
+	* src/main/java/de/intevation/flys/artifacts/model/QSectorFacet.java:
+	  Rather trivial facet to get QSectors from QSectorArtifact.
+
+	* src/main/java/de/intevation/flys/artifacts/QSectorArtifact.java:
+	  New QSectorArtifact.
+
+2012-08-09	Felix Wolfsteller	<felix.wolfsteller@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/services/FixingsKMChartService.java,
+	  src/main/java/de/intevation/flys/artifacts/datacage/templating/Builder.java:
+	  Cosmetics.
+
 2012-08-09	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/model/sq/Fitting.java,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/doc/conf/artifacts/qsector.xml	Fri Aug 10 10:25:47 2012 +0000
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<artifact name="qsector">
+  <states>
+    <state id="state.qsector.static"
+               description="state.qsector.static"
+               state="de.intevation.flys.artifacts.states.QSectorSingleState">
+      <outputmodes>
+        <outputmode name="fix_wq_curve" description="output.fix_wq_curve" mime-type="image/png" type="chart">
+          <facets>
+            <facet name="qsectors" description="qsectors."/>
+          </facets>
+        </outputmode>
+      </outputmodes>
+    </state>
+  </states>
+</artifact>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/QSectorArtifact.java	Fri Aug 10 10:25:47 2012 +0000
@@ -0,0 +1,131 @@
+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.state.Facet;
+
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.ArtifactFactory;
+import de.intevation.artifacts.CallMeta;
+
+import de.intevation.flys.artifacts.model.FacetTypes;
+import de.intevation.flys.artifacts.model.GaugeFinder;
+import de.intevation.flys.artifacts.model.GaugeFinderFactory;
+import de.intevation.flys.artifacts.model.GaugeRange;
+import de.intevation.flys.artifacts.model.NamedDouble;
+
+import de.intevation.flys.artifacts.services.FixingsKMChartService;
+
+import de.intevation.flys.artifacts.states.DefaultState;
+
+
+
+/**
+ * Artifact to produce sector markers.
+ */
+public class QSectorArtifact
+extends      StaticFLYSArtifact
+implements   FacetTypes
+{
+    /** The logger for this class. */
+    private static Logger logger = Logger.getLogger(QSectorArtifact.class);
+
+    /** The name of the artifact. */
+    public static final String ARTIFACT_NAME = "qsector";
+
+
+    /**
+     * Trivial Constructor.
+     */
+    public QSectorArtifact() {
+        logger.debug("QSectorArtifact.QSectorArtifact()");
+    }
+
+
+    /**
+     * Gets called from factory, to set things up.
+     */
+    @Override
+    public void setup(
+        String          identifier,
+        ArtifactFactory factory,
+        Object          context,
+        CallMeta        callMeta,
+        Document        data)
+    {
+        logger.debug("QSectorArtifact.setup");
+        super.setup(identifier, factory, context, callMeta, data);
+        initialize(null, context, callMeta);
+    }
+
+
+    /** Return the name of this artifact. */
+    public String getName() {
+        return ARTIFACT_NAME;
+    }
+
+
+    /** Get list of NamedDouble s (QSectors). */
+    public Object getQSectors(double km) {
+
+        String river = getDataAsString("river");
+        List<NamedDouble> qsectors = new ArrayList<NamedDouble>();
+
+        GaugeFinderFactory ggf = GaugeFinderFactory.getInstance();
+        GaugeFinder        gf  = ggf.getGaugeFinder(river);
+
+        if (gf == null) {
+            logger.warn("No gauge finder found for river '" + river + "'");
+            return null;
+        }
+
+        GaugeRange gr = gf.find(km);
+        if (gr == null) {
+            logger.debug("No gauge range found for km "
+                + km + " on river " + river + ".");
+            return null;
+        }
+
+        if (logger.isDebugEnabled()) {
+            logger.debug(gr);
+        }
+
+        for (int i = 0; i < FixingsKMChartService.I18N_Q_SECTOR_BOARDERS.length; ++i) {
+            String key   = FixingsKMChartService.I18N_Q_SECTOR_BOARDERS[i];
+            String def   = FixingsKMChartService.DEFAULT_Q_SECTOR_BORDERS[i];
+            String label = "label";//Resources.getMsg(meta, key, def);
+
+            qsectors.add(new NamedDouble(label, gr.getSectorBorder(i)));
+        }
+
+        return qsectors;
+    }
+
+
+    /** Setup state and facet. */
+    @Override
+    protected void initialize(Artifact artifact, Object context, CallMeta meta) {
+        logger.debug("QSectorArtifact.initialize");
+        List<Facet> fs = new ArrayList<Facet>();
+
+        FLYSArtifact flys = (FLYSArtifact) artifact;
+        importData(flys, "river");
+
+        DefaultState state = (DefaultState) getCurrentState(context);
+        state.computeInit(this, hash(), context, meta, fs);
+        if (!fs.isEmpty()) {
+            logger.debug("Facets to add in QSectorArtifact.initialize .");
+            facets.put(getCurrentStateId(), fs);
+        }
+        else {
+            logger.debug("No facets to add in QSectorArtifact.initialize ("
+                + state.getID() + ").");
+        }
+    }
+}
+// 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/QSectorFacet.java	Fri Aug 10 10:25:47 2012 +0000
@@ -0,0 +1,66 @@
+package de.intevation.flys.artifacts.model;
+
+import org.apache.log4j.Logger;
+
+import de.intevation.artifacts.Artifact;
+import de.intevation.artifacts.CallContext;
+
+import de.intevation.flys.artifacts.QSectorArtifact;
+
+import de.intevation.artifactdatabase.state.DefaultFacet;
+import de.intevation.artifactdatabase.state.Facet;
+
+
+/**
+ * Facet to access QSector that where added by user.
+ */
+public class QSectorFacet
+extends      DefaultFacet
+{
+    /** Logger for this class. */
+    private static final Logger logger = Logger.getLogger(QSectorFacet.class);
+
+
+    /**
+     * Trivial Constructor.
+     */
+    public QSectorFacet() {
+    }
+
+
+    /**
+     * Trivial Constructor for a QSectorFacet.
+     *
+     * @param index       Database-Index to use.
+     * @param name        Name (~type) of Facet.
+     * @param description Description of Facet.
+     */
+    public QSectorFacet(int index, String name, String description) {
+        super(index, name, description);
+    }
+
+
+    /**
+     * Get List of QSector for river from Artifact.
+     *
+     * @param artifact (QSector-)Artifact to query for list of QSector.
+     * @param context  Ignored.
+     */
+    @Override
+    public Object getData(Artifact artifact, CallContext context) {
+        QSectorArtifact qsectorArtifact = (QSectorArtifact) artifact;
+        double currentKm =
+            ((Double)context.getContextValue("currentKm")).doubleValue();
+        return qsectorArtifact.getQSectors(currentKm);
+    }
+
+
+    /** Do a deep copy. */
+    @Override
+    public Facet deepCopy() {
+        QSectorFacet copy = new QSectorFacet();
+        copy.set(this);
+        return copy;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org