[PATCH 2 of 4] Configured "static" sq relation to use a default D4EArtifact and two states to hold the parameters and outs

Wald Commits scm-commit at wald.intevation.org
Wed Sep 24 12:02:43 CEST 2014


# HG changeset patch
# User Raimund Renkert <rrenkert at intevation.de>
# Date 1411552789 -7200
# Node ID 9f5059f4f01a8bd5a9e7aa6d7cb78a0e5fc185bb
# Parent  7b282a3f50f09c717bbca27e9cf36872497d6d71
Configured "static" sq relation to use a default D4EArtifact and two states to hold the parameters and outs.

* Updated configuration
* Added new state

diff -r 7b282a3f50f0 -r 9f5059f4f01a artifacts/doc/conf/artifacts/sqrelation.xml
--- a/artifacts/doc/conf/artifacts/sqrelation.xml	Wed Sep 24 11:56:03 2014 +0200
+++ b/artifacts/doc/conf/artifacts/sqrelation.xml	Wed Sep 24 11:59:49 2014 +0200
@@ -1,9 +1,16 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <artifact name="staticsqrelation">
     <states>
+        <state id="state.sqrelation.init" description="state.sqrelation.init" state="org.dive4elements.river.artifacts.states.sq.SQInitState">
+            <data name="river" type="String"/>
+            <data name="station" type="Integer" />
+            <data name="station_name" type="String" />
+        </state>
+        <transition transition="org.dive4elements.river.artifacts.transitions.DefaultTransition">
+            <from state="state.sqrelation.init"/>
+            <to state="state.sqrelation.static"/>
+        </transition>
          <state id="state.sqrelation.static" description="state.sqrelation.static" state="org.dive4elements.river.artifacts.states.sq.SQStaticState">
-            <data name="river" type="String" />
-            <data name="station" type="String" />
             <outputmodes>
                 <outputmode name="sq_relation_a" description="output.sq_relation" type="chart">
                     <facets>
@@ -47,17 +54,6 @@
                         <facet name="sq_g_curve" description="A facet for sq curve"/>
                     </facets>
                 </outputmode>
-                <outputmode name="sq_overview" description="output.sq_overview" type="overview">
-                    <facets>
-                        <facet name="sq_chart_overview" description="A facet for sq chart overview"/>
-                    </facets>
-                </outputmode>
-                <outputmode name="sqrelation_export" description="output.sqrelation_export" mime-type="text/plain" type="export">
-                    <facets>
-                        <facet name="csv" description="facet.sqrelation_export.csv" />
-                        <facet name="pdf" description="facet.sqrelation_export.pdf" />
-                    </facets>
-                </outputmode>
             </outputmodes>
          </state>
     </states>
diff -r 7b282a3f50f0 -r 9f5059f4f01a artifacts/doc/conf/conf.xml
--- a/artifacts/doc/conf/conf.xml	Wed Sep 24 11:56:03 2014 +0200
+++ b/artifacts/doc/conf/conf.xml	Wed Sep 24 11:59:49 2014 +0200
@@ -12,6 +12,7 @@
     <!ENTITY modules SYSTEM "modules.xml">
     <!ENTITY porosity-artifact  SYSTEM "artifacts/porosity.xml">
     <!ENTITY gaugedischargecurve-artifact  SYSTEM "artifacts/gaugedischargecurve.xml">
+    <!ENTITY sqrelation-artifact SYSTEM "artifacts/sqrelation.xml">
     <!ENTITY sedimentload-artifact  SYSTEM "artifacts/sedimentload.xml">
     <!ENTITY sedimentload-ls-artifact  SYSTEM "artifacts/sedimentload-ls.xml">
 
@@ -140,7 +141,7 @@
                 artifact="org.dive4elements.river.artifacts.BedHeightsArtifact">org.dive4elements.artifactdatabase.DefaultArtifactFactory</artifact-factory>
             <artifact-factory name="staticsqrelation" description="Factory to create an artifact that generates sq relations from db."
                 ttl="3600000"
-                artifact="org.dive4elements.river.artifacts.SQRelationArtifact">org.dive4elements.artifactdatabase.DefaultArtifactFactory</artifact-factory>
+                artifact="org.dive4elements.river.artifacts.D4EArtifact">org.dive4elements.artifactdatabase.DefaultArtifactFactory</artifact-factory>
             <artifact-factory name="morph-width" description="Factory to create an artifact used in minfo datacage."
                 ttl="3600000"
                 artifact="org.dive4elements.river.artifacts.StaticMorphWidthArtifact">org.dive4elements.artifactdatabase.DefaultArtifactFactory</artifact-factory>
@@ -291,7 +292,7 @@
         <artifact name="fixanalysis" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${artifacts.config.dir}/artifacts/fixanalysis.xml" />
         <artifact name="gaugedischarge" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${artifacts.config.dir}/artifacts/gaugedischarge.xml" />
         <artifact name="qsector" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${artifacts.config.dir}/artifacts/qsector.xml" />
-        <artifact name="staticsqrelation" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${artifacts.config.dir}/artifacts/sqrelation.xml" />
+        &sqrelation-artifact;
         &porosity-artifact;
         &gaugedischargecurve-artifact;
         &sedimentload-artifact;
diff -r 7b282a3f50f0 -r 9f5059f4f01a artifacts/src/main/java/org/dive4elements/river/artifacts/states/sq/SQInitState.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/sq/SQInitState.java	Wed Sep 24 11:59:49 2014 +0200
@@ -0,0 +1,14 @@
+package org.dive4elements.river.artifacts.states.sq;
+
+import org.dive4elements.river.artifacts.states.DefaultState;
+
+
+public class SQInitState
+extends DefaultState
+{
+
+    @Override
+    protected String getUIProvider() {
+        return "static_data";
+    }
+}
diff -r 7b282a3f50f0 -r 9f5059f4f01a artifacts/src/main/java/org/dive4elements/river/artifacts/states/sq/SQStaticState.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/sq/SQStaticState.java	Wed Sep 24 11:56:03 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/sq/SQStaticState.java	Wed Sep 24 11:59:49 2014 +0200
@@ -15,9 +15,12 @@
 import org.apache.log4j.Logger;
 
 import org.dive4elements.artifactdatabase.state.Facet;
+import org.dive4elements.artifacts.CallContext;
 import org.dive4elements.artifacts.CallMeta;
 import org.dive4elements.river.artifacts.D4EArtifact;
 import org.dive4elements.river.artifacts.access.StaticSQRelationAccess;
+import org.dive4elements.river.artifacts.model.DataFacet;
+import org.dive4elements.river.artifacts.model.FacetTypes;
 import org.dive4elements.river.artifacts.model.sq.StaticSQContainer;
 import org.dive4elements.river.artifacts.model.sq.StaticSQFactory;
 import org.dive4elements.river.artifacts.model.sq.StaticSQRelation;
@@ -27,6 +30,7 @@
 
 public class SQStaticState
 extends StaticState
+implements FacetTypes
 {
 
     private static final Logger log =
@@ -44,6 +48,61 @@
     }
 
     @Override
+    public Object computeAdvance(
+        D4EArtifact artifact,
+        String hash,
+        CallContext context,
+        List<Facet> facets,
+        Object old) {
+        StaticSQContainer sqRelations;
+        StaticSQRelationAccess access = new StaticSQRelationAccess(artifact);
+        String river = access.getRiverName();
+        String measurementStation = access.getMeasurementStation();
+
+        int ms = -1;
+        try {
+            ms = Integer.parseInt(measurementStation);
+        }
+        catch (NumberFormatException nfe) {
+            log.error("Unparseable measurement station: " + measurementStation);
+            return null;
+        }
+        log.debug("Parsed measurement station: " + ms);
+
+        sqRelations = StaticSQFactory.getSQRelations(river, ms);
+        DateFormat df = new SimpleDateFormat("yyyy");
+
+        for (StaticSQRelation.Parameter p: StaticSQRelation.Parameter.values()) {
+            log.debug("parameter: " + p.toString());
+            List<StaticSQRelation> relations =
+                sqRelations.getRelationsByParameter(p);
+
+            if (!relations.isEmpty()) {
+                int count = 0;
+
+                for (StaticSQRelation relation : relations) {
+                    log.debug("add facet for " + p.toString().toLowerCase());
+                    String name = "sq_" + p.toString().toLowerCase() + "_curve";
+                    String desc =
+                        Resources.getMsg(context.getMeta(),
+                            FACET_DESCRIPTION,
+                            FACET_DESCRIPTION,
+                            new Object[] {
+                                df.format(relation.getStartTime()),
+                                df.format(relation.getStopTime())});
+                    facets.add(new StaticSQRelationFacet(
+                        count,
+                        name,
+                        desc,
+                        relation));
+                    count++;
+                }
+            }
+        }
+        return null;
+    }
+
+    @Override
     public Object computeInit(
         D4EArtifact artifact,
         String       hash,


More information about the Dive4Elements-commits mailing list