changeset 692:22e4bffbe240 facets-slt

Generated facets for each output aspect. flys-artifacts/branches/facets-slt@2132 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 16 Jun 2011 10:05:44 +0000
parents 2600aa2c7319
children af393c5eb2c8
files flys-artifacts/doc/conf/artifacts/winfo.xml flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ComputeCallback.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ComputeCallbackAdapter.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ComputedDischargeCurveState.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DischargeLongitudinalSection.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DurationCurveState.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/LocationDistanceSelect.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java
diffstat 10 files changed, 211 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/doc/conf/artifacts/winfo.xml	Thu Jun 16 09:04:59 2011 +0000
+++ b/flys-artifacts/doc/conf/artifacts/winfo.xml	Thu Jun 16 10:05:44 2011 +0000
@@ -45,7 +45,6 @@
             <outputmodes>
                 <outputmode name="discharge_curve" description="output.discharge_curve" mime-type="image/png">
                     <facets>
-                        <facet name="discharge_curve.curve" description="facet.discharge_curve.curve"/>
                         <facet name="discharge_curve.w" description="facet.discharge_curve.w"/>
                         <facet name="discharge_curve.q" description="facet.discharge_curve.q"/>
                     </facets>
@@ -130,7 +129,6 @@
             <outputmodes>
                 <outputmode name="computed_discharge_curve" description="output.computed_discharge_curve" mime-type="image/png">
                     <facets>
-                        <facet name="computed_discharge_curve.w" description="facet.computed_discharge_curve.w"/>
                         <facet name="computed_discharge_curve.q" description="facet.computed_discharge_curve.q"/>
                     </facets>
                 </outputmode>
@@ -176,6 +174,7 @@
                     <facets>
                         <facet name="discharge_longitudinal_section.w"/>
                         <facet name="discharge_longitudinal_section.q"/>
+                        <facet name="discharge_longitudinal_section.c"/>
                     </facets>
                 </outputmode>
                 <outputmode name="discharge_longitudinal_section_export" description="output.discharge_longitudinal_section_export" mime-type="text/plain">
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Thu Jun 16 09:04:59 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Thu Jun 16 10:05:44 2011 +0000
@@ -1082,11 +1082,12 @@
             return null;
         }
 
-        return compute(hash, callback, type);
+        return compute(context, hash, callback, type);
     }
 
 
     public Object compute(
+        CallContext     context,
         String          key,
         ComputeCallback callback,
         ComputeType     type)
@@ -1102,10 +1103,10 @@
         if (cache == null) {
             switch (type) {
                 case FEED:
-                    return callback.computeFeed(fs);
+                    return callback.computeFeed(context, fs);
 
                 case ADVANCE:
-                    return callback.computeAdvance(fs);
+                    return callback.computeAdvance(context, fs);
             }
         }
 
@@ -1118,11 +1119,11 @@
         Object result = null;
         switch (type) {
             case FEED:
-                result = callback.computeFeed(fs);
+                result = callback.computeFeed(context, fs);
                 break;
 
             case ADVANCE:
-                result = callback.computeAdvance(fs);
+                result = callback.computeAdvance(context, fs);
         }
 
         if (result != null) {
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ComputeCallback.java	Thu Jun 16 09:04:59 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ComputeCallback.java	Thu Jun 16 10:05:44 2011 +0000
@@ -2,6 +2,8 @@
 
 import java.util.List;
 
+import de.intevation.artifacts.CallContext;
+
 import de.intevation.artifactdatabase.state.Facet;
 
 
@@ -11,8 +13,8 @@
         FEED, ADVANCE
     }
 
-    Object computeAdvance(List<Facet> facets);
+    Object computeAdvance(CallContext context, List<Facet> facets);
 
-    Object computeFeed(List<Facet> facets);
+    Object computeFeed(CallContext context, List<Facet> facets);
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ComputeCallbackAdapter.java	Thu Jun 16 09:04:59 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/ComputeCallbackAdapter.java	Thu Jun 16 10:05:44 2011 +0000
@@ -2,19 +2,21 @@
 
 import java.util.List;
 
+import de.intevation.artifacts.CallContext;
+
 import de.intevation.artifactdatabase.state.Facet;
 
 
 public class ComputeCallbackAdapter implements ComputeCallback {
 
     @Override
-    public Object computeAdvance(List<Facet> facets) {
+    public Object computeAdvance(CallContext context, List<Facet> facets) {
         return null;
     }
 
 
     @Override
-    public Object computeFeed(List<Facet> facets) {
+    public Object computeFeed(CallContext context, List<Facet> facets) {
         return null;
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/FacetTypes.java	Thu Jun 16 10:05:44 2011 +0000
@@ -0,0 +1,17 @@
+package de.intevation.flys.artifacts.model;
+
+public interface FacetTypes {
+
+    String DISCHARGE_LONGITUDINAL_W = "discharge_longitudinal_section.w";
+    String DISCHARGE_LONGITUDINAL_Q = "discharge_longitudinal_section.q";
+    String DISCHARGE_LONGITUDINAL_C = "discharge_longitudinal_section.c";
+
+    String LONGITUDINAL_W = "facet.longitudinal_section.w";
+    String LONGITUDINAL_Q = "facet.longitudinal_section.q";
+
+    String COMPUTED_DISCHARGE_Q = "computed_discharge_curve.q";
+
+    String DURATION_W = "discharge_curve.w";
+    String DURATION_Q = "discharge_curve.q";
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ComputedDischargeCurveState.java	Thu Jun 16 09:04:59 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ComputedDischargeCurveState.java	Thu Jun 16 10:05:44 2011 +0000
@@ -4,12 +4,18 @@
 
 import org.apache.log4j.Logger;
 
+import de.intevation.artifacts.CallContext;
+
+import de.intevation.artifactdatabase.state.DefaultFacet;
 import de.intevation.artifactdatabase.state.Facet;
 
 import de.intevation.flys.artifacts.FLYSArtifact;
 import de.intevation.flys.artifacts.WINFOArtifact;
 import de.intevation.flys.artifacts.model.ComputeCallback;
 import de.intevation.flys.artifacts.model.ComputeCallbackAdapter;
+import de.intevation.flys.artifacts.model.FacetTypes;
+import de.intevation.flys.artifacts.model.WQKms;
+import de.intevation.flys.artifacts.resources.Resources;
 
 /**
  * The final state that will be reached after the discharge curve calculation
@@ -17,8 +23,10 @@
  *
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
  */
-public class ComputedDischargeCurveState extends DefaultState {
-
+public class ComputedDischargeCurveState
+extends      DefaultState
+implements   FacetTypes
+{
     /** The logger that is used in this state.*/
     private static Logger logger =
         Logger.getLogger(ComputedDischargeCurveState.class);
@@ -36,8 +44,33 @@
         return new ComputeCallbackAdapter() {
 
             @Override
-            public Object computeAdvance(List<Facet> facets) {
-                return winfo.getComputedDischargeCurveData();
+            public Object computeAdvance(
+                CallContext context,
+                List<Facet> facets)
+            {
+                WQKms res = winfo.getComputedDischargeCurveData();
+
+                if (res == null) {
+                    logger.debug("No results given.");
+                    return null;
+                }
+
+                Object[] args = new Object[] {
+                    winfo.getRiver().getName(),
+                    res.getName()
+                };
+
+                String name = Resources.getMsg(
+                    context.getMeta(),
+                    "chart.computed.discharge.curve.curve.label",
+                    "",
+                    args);
+
+                Facet q = new DefaultFacet(0, DISCHARGE_LONGITUDINAL_Q, name);
+
+                facets.add(q);
+
+                return res;
             }
         };
     }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DischargeLongitudinalSection.java	Thu Jun 16 09:04:59 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DischargeLongitudinalSection.java	Thu Jun 16 10:05:44 2011 +0000
@@ -4,15 +4,23 @@
 
 import org.apache.log4j.Logger;
 
+import de.intevation.artifacts.CallContext;
+
+import de.intevation.artifactdatabase.state.DefaultFacet;
 import de.intevation.artifactdatabase.state.Facet;
 
 import de.intevation.flys.artifacts.FLYSArtifact;
 import de.intevation.flys.artifacts.WINFOArtifact;
 import de.intevation.flys.artifacts.model.ComputeCallback;
 import de.intevation.flys.artifacts.model.ComputeCallbackAdapter;
+import de.intevation.flys.artifacts.model.FacetTypes;
+import de.intevation.flys.artifacts.model.WQKms;
+import de.intevation.flys.artifacts.model.WQCKms;
 
-public class DischargeLongitudinalSection extends DefaultState {
-
+public class DischargeLongitudinalSection
+extends      DefaultState
+implements   FacetTypes
+{
     private static Logger logger =
         Logger.getLogger(DischargeLongitudinalSection.class);
 
@@ -26,8 +34,54 @@
         return new ComputeCallbackAdapter() {
 
             @Override
-            public Object computeAdvance(List<Facet> facets) {
-                return winfo.getDischargeLongitudinalSectionData();
+            public Object computeAdvance(
+                CallContext context,
+                List<Facet> facets)
+            {
+                WQKms res[] = winfo.getDischargeLongitudinalSectionData();
+
+                if (res == null) {
+                    logger.debug("No results given.");
+                    return null;
+                }
+
+                for (int i = 0; i < res.length; i++) {
+                    String nameW = null;
+                    String nameQ = null;
+
+                    if (winfo.isQ()) {
+                        nameQ = res[i].getName();
+                        nameW = "W(" + nameQ + ")";
+                    }
+                    else {
+                        nameW = res[i].getName();
+                        nameQ = "Q(" + nameQ + ")";
+                    }
+
+                    Facet w = new DefaultFacet(
+                        i, DISCHARGE_LONGITUDINAL_W, nameW);
+
+                    Facet q = new DefaultFacet(
+                        i, DISCHARGE_LONGITUDINAL_Q, nameQ);
+
+                    facets.add(w);
+                    facets.add(q);
+
+                    if (res[i] instanceof WQCKms) {
+                        // TODO DO i18n
+
+                        String nameC = nameW.replace(
+                            "Benutzerdefiniert",
+                            "Benutzerdefiniert [korrigiert]");
+
+                        Facet c = new DefaultFacet(
+                            i, DISCHARGE_LONGITUDINAL_C, nameC);
+
+                        facets.add(c);
+                    }
+                }
+
+                return res;
             }
         };
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DurationCurveState.java	Thu Jun 16 09:04:59 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DurationCurveState.java	Thu Jun 16 10:05:44 2011 +0000
@@ -4,12 +4,18 @@
 
 import org.apache.log4j.Logger;
 
+import de.intevation.artifacts.CallContext;
+
+import de.intevation.artifactdatabase.state.DefaultFacet;
 import de.intevation.artifactdatabase.state.Facet;
 
 import de.intevation.flys.artifacts.FLYSArtifact;
 import de.intevation.flys.artifacts.WINFOArtifact;
 import de.intevation.flys.artifacts.model.ComputeCallback;
 import de.intevation.flys.artifacts.model.ComputeCallbackAdapter;
+import de.intevation.flys.artifacts.model.FacetTypes;
+import de.intevation.flys.artifacts.model.WQDay;
+import de.intevation.flys.artifacts.resources.Resources;
 
 /**
  * The final state that will be reached after the duration curve calculation
@@ -17,8 +23,10 @@
  *
  * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
  */
-public class DurationCurveState extends DefaultState {
-
+public class DurationCurveState
+extends      DefaultState
+implements   FacetTypes
+{
     /** The logger that is used in this state.*/
     private static Logger logger = Logger.getLogger(DurationCurveState.class);
 
@@ -35,8 +43,40 @@
         return new ComputeCallbackAdapter() {
 
             @Override
-            public Object computeAdvance(List<Facet> facets) {
-                return winfo.getDurationCurveData();
+            public Object computeAdvance(
+                CallContext context,
+                List<Facet> facets)
+            {
+                WQDay res = winfo.getDurationCurveData();
+
+                if (res == null) {
+                    logger.debug("No results given.");
+                    return null;
+                }
+
+                Object[] args = new Object[] {
+                    winfo.getRiver().getName()
+                };
+
+                String nameW = Resources.getMsg(
+                    context.getMeta(),
+                    "chart.duration.curve.curve.w",
+                    "",
+                    args);
+
+                String nameQ = Resources.getMsg(
+                    context.getMeta(),
+                    "chart.duration.curve.curve.q",
+                    "",
+                    args);
+
+                Facet w = new DefaultFacet(0, DURATION_W, nameW);
+                Facet q = new DefaultFacet(0, DURATION_Q, nameQ);
+
+                facets.add(w);
+                facets.add(q);
+
+                return res;
             }
         };
     }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/LocationDistanceSelect.java	Thu Jun 16 09:04:59 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/LocationDistanceSelect.java	Thu Jun 16 10:05:44 2011 +0000
@@ -307,7 +307,7 @@
         return new ComputeCallbackAdapter() {
 
             @Override
-            public Object computeFeed(List<Facet> facets) {
+            public Object computeFeed(CallContext context, List<Facet> facets) {
                 return winfo.getDischargeCurveData();
             }
         };
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java	Thu Jun 16 09:04:59 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java	Thu Jun 16 10:05:44 2011 +0000
@@ -11,16 +11,21 @@
 
 import de.intevation.artifacts.common.utils.XMLUtils;
 
+import de.intevation.artifactdatabase.state.DefaultFacet;
 import de.intevation.artifactdatabase.state.Facet;
 
 import de.intevation.flys.artifacts.FLYSArtifact;
 import de.intevation.flys.artifacts.WINFOArtifact;
 import de.intevation.flys.artifacts.model.ComputeCallback;
 import de.intevation.flys.artifacts.model.ComputeCallbackAdapter;
+import de.intevation.flys.artifacts.model.FacetTypes;
+import de.intevation.flys.artifacts.model.WQKms;
 
 
-public class WaterlevelState extends DefaultState {
-
+public class WaterlevelState
+extends      DefaultState
+implements   FacetTypes
+{
     /** The logger that is used in this state.*/
     private static Logger logger = Logger.getLogger(WaterlevelState.class);
 
@@ -45,8 +50,38 @@
         return new ComputeCallbackAdapter() {
 
             @Override
-            public Object computeAdvance(List<Facet> facets) {
-                return winfo.getWaterlevelData();
+            public Object computeAdvance(
+                CallContext context,
+                List<Facet> facets)
+            {
+                WQKms[] res = winfo.getWaterlevelData();
+
+                if (res == null) {
+                    logger.debug("No results given.");
+                    return null;
+                }
+
+                for (int i = 0; i < res.length; i++) {
+                    String nameW = null;
+                    String nameQ = null;
+
+                    if (winfo.isQ()) {
+                        nameQ = res[i].getName();
+                        nameW = "W(" + nameQ + ")";
+                    }
+                    else {
+                        nameW = res[i].getName();
+                        nameQ = "Q(" + nameQ + ")";
+                    }
+
+                    Facet w = new DefaultFacet(i, LONGITUDINAL_W, nameW);
+                    Facet q = new DefaultFacet(i, LONGITUDINAL_Q, nameQ);
+
+                    facets.add(w);
+                    facets.add(q);
+                }
+
+                return res;
             }
         };
     }

http://dive4elements.wald.intevation.org