changeset 3088:960307cf2adc

Moved current km to context and added an abstract generator for fix analysis charts. flys-artifacts/trunk@4686 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Raimund Renkert <raimund.renkert@intevation.de>
date Mon, 18 Jun 2012 11:21:30 +0000
parents 4a76da133144
children 7e4c8590067a
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisEventsFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisPeriodsFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixDerivateFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixOutlierFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixReferenceEventsFacet.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixChartGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixDerivedCurveGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixWQCurveGenerator.java
diffstat 12 files changed, 99 insertions(+), 88 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Mon Jun 18 09:16:05 2012 +0000
+++ b/flys-artifacts/ChangeLog	Mon Jun 18 11:21:30 2012 +0000
@@ -1,3 +1,25 @@
+2012-06-18  Raimund Renkert <raimund.renkert@intevation.de>
+
+	* src/main/java/de/intevation/flys/exports/fixings/FixChartGenerator.java:
+	  New. Abstract chart generator for fix analysis. This generator adds the
+	  current km to the context.
+
+	* src/main/java/de/intevation/flys/exports/fixings/FixDerivedCurveGenerator.java,
+	  src/main/java/de/intevation/flys/exports/fixings/FixWQCurveGenerator.java:
+	  Generators now extend the FixCahrtGenerator.
+
+	* src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.java,
+	  src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java,
+	  src/main/java/de/intevation/flys/artifacts/model/fixings/FixDerivateFacet.java,
+	  src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisEventsFacet.java,
+	  src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisPeriodsFacet.java,
+	  src/main/java/de/intevation/flys/artifacts/model/fixings/FixReferenceEventsFacet.java,
+	  src/main/java/de/intevation/flys/artifacts/model/fixings/FixOutlierFacet.java:
+	  Get the current km from context.
+
+	* src/main/java/de/intevation/flys/exports/ChartGenerator.java:
+	  Removed getter for current km.
+
 2012-06-18	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/map/PrintMap.java,
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisEventsFacet.java	Mon Jun 18 09:16:05 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisEventsFacet.java	Mon Jun 18 11:21:30 2012 +0000
@@ -29,8 +29,6 @@
     /** House logger. */
     private static Logger logger = Logger.getLogger(FixAnalysisEventsFacet.class);
 
-    private double currentKm;
-
     /** Trivial Constructor. */
     public FixAnalysisEventsFacet() {
     }
@@ -49,12 +47,6 @@
     }
 
 
-    public Object getData(Artifact artifact, CallContext context, double km) {
-        this.currentKm = km;
-        return getData(artifact, context);
-    }
-
-
     /**
      * Returns the data this facet requires.
      *
@@ -77,6 +69,8 @@
                                                  false);
 
             FixResult result = (FixResult) res.getData();
+            Double currentKm =
+                ((Double)context.getContextValue("currentKm")).doubleValue();
 
             KMIndex<AnalysisPeriod []> kmPeriods = result.getAnalysisPeriods();
             KMIndex.Entry<AnalysisPeriod []> kmPeriodsEntry =
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisPeriodsFacet.java	Mon Jun 18 09:16:05 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAnalysisPeriodsFacet.java	Mon Jun 18 11:21:30 2012 +0000
@@ -29,8 +29,6 @@
     /** House logger. */
     private static Logger logger = Logger.getLogger(FixAnalysisPeriodsFacet.class);
 
-    private double currentKm;
-
     /** Trivial Constructor. */
     public FixAnalysisPeriodsFacet() {
     }
@@ -49,12 +47,6 @@
     }
 
 
-    public Object getData(Artifact artifact, CallContext context, double km) {
-        this.currentKm = km;
-        return getData(artifact, context);
-    }
-
-
     /**
      * Returns the data this facet requires.
      *
@@ -77,6 +69,8 @@
                                                  false);
 
             FixResult result = (FixResult) res.getData();
+            double currentKm =
+                ((Double)context.getContextValue("currentKm")).doubleValue();
 
             KMIndex<AnalysisPeriod []> kmPeriods = result.getAnalysisPeriods();
             KMIndex.Entry<AnalysisPeriod []> kmPeriodsEntry =
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.java	Mon Jun 18 09:16:05 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixAvSectorFacet.java	Mon Jun 18 11:21:30 2012 +0000
@@ -29,8 +29,6 @@
     /** House logger. */
     private static Logger logger = Logger.getLogger(FixAvSectorFacet.class);
 
-    private double currentKm;
-
     /** Trivial Constructor. */
     public FixAvSectorFacet() {
     }
@@ -47,12 +45,6 @@
     }
 
 
-    public Object getData(Artifact artifact, CallContext context, double km) {
-        this.currentKm = km;
-        return getData(artifact, context);
-    }
-
-
     /**
      * Returns the data this facet requires.
      *
@@ -76,6 +68,8 @@
 
             FixResult result = (FixResult) res.getData();
 
+            double currentKm =
+                ((Double)context.getContextValue("currentKm")).doubleValue();
             KMIndex<AnalysisPeriod []> kmPeriods = result.getAnalysisPeriods();
             KMIndex.Entry<AnalysisPeriod []> kmPeriodsEntry =
                 kmPeriods.binarySearch(currentKm);
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixDerivateFacet.java	Mon Jun 18 09:16:05 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixDerivateFacet.java	Mon Jun 18 11:21:30 2012 +0000
@@ -31,7 +31,6 @@
     /** House logger. */
     private static Logger logger = Logger.getLogger(FixDerivateFacet.class);
 
-    private double currentKm;
     private double maxQ;
 
     /** Trivial Constructor. */
@@ -47,12 +46,6 @@
     }
 
 
-    public Object getData(Artifact artifact, CallContext context, double km) {
-        this.currentKm = km;
-        return getData(artifact, context);
-    }
-
-
     /**
      * Returns the data this facet requires.
      *
@@ -74,6 +67,8 @@
                                                  false);
 
             FixResult result = (FixResult) res.getData();
+            double currentKm =
+                ((Double)context.getContextValue("currentKm")).doubleValue();
 
             String function = access.getFunction();
             Function ff = FunctionFactory.getInstance().getFunction(function);
@@ -83,7 +78,7 @@
             
             // Determine maxQ
             double[] maxQs = params
-                .interpolate("km", this.currentKm, new String [] { "max_q" });
+                .interpolate("km", currentKm, new String [] { "max_q" });
             if(maxQs != null) {
                 maxQ = maxQs[0];
             }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixOutlierFacet.java	Mon Jun 18 09:16:05 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixOutlierFacet.java	Mon Jun 18 11:21:30 2012 +0000
@@ -29,8 +29,6 @@
     /** House logger. */
     private static Logger logger = Logger.getLogger(FixOutlierFacet.class);
 
-    private double currentKm;
-
     /** Trivial Constructor. */
     public FixOutlierFacet() {
     }
@@ -44,12 +42,6 @@
     }
 
 
-    public Object getData(Artifact artifact, CallContext context, double km) {
-        this.currentKm = km;
-        return getData(artifact, context);
-    }
-
-
     /**
      * Returns the data this facet requires.
      *
@@ -72,6 +64,8 @@
                                                  false);
 
             FixResult result = (FixResult) res.getData();
+            double currentKm =
+                ((Double)context.getContextValue("currentKm")).doubleValue();
 
             KMIndex<QW []> kmQWs = result.getOutliers();
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixReferenceEventsFacet.java	Mon Jun 18 09:16:05 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixReferenceEventsFacet.java	Mon Jun 18 11:21:30 2012 +0000
@@ -29,8 +29,6 @@
     /** House logger. */
     private static Logger logger = Logger.getLogger(FixReferenceEventsFacet.class);
 
-    private double currentKm;
-
     /** Trivial Constructor. */
     public FixReferenceEventsFacet() {
     }
@@ -49,12 +47,6 @@
     }
 
 
-    public Object getData(Artifact artifact, CallContext context, double km) {
-        this.currentKm = km;
-        return getData(artifact, context);
-    }
-
-
     /**
      * Returns the data this facet requires.
      *
@@ -77,6 +69,8 @@
                                                  false);
 
             FixResult result = (FixResult) res.getData();
+            double currentKm =
+                ((Double)context.getContextValue("currentKm")).doubleValue();
 
             KMIndex<QW []> kmQWs = result.getReferenced();
             KMIndex.Entry<QW []> kmQWsEntry = kmQWs.binarySearch(currentKm);
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java	Mon Jun 18 09:16:05 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/fixings/FixWQCurveFacet.java	Mon Jun 18 11:21:30 2012 +0000
@@ -30,11 +30,8 @@
     /** House logger. */
     private static Logger logger = Logger.getLogger(FixWQCurveFacet.class);
 
-    private double currentKm;
-
     /** Trivial Constructor. */
     public FixWQCurveFacet() {
-        currentKm = 0;
     }
 
 
@@ -46,12 +43,6 @@
     }
 
 
-    public Object getData(Artifact artifact, CallContext context, double km) {
-        this.currentKm = km;
-        return getData(artifact, context);
-    }
-
-
     /**
      * Returns the data this facet requires.
      *
@@ -73,6 +64,8 @@
                                                  false);
 
             FixResult result = (FixResult) res.getData();
+            double currentKm =
+                ((Double)context.getContextValue("currentKm")).doubleValue();
 
             logger.debug("getData: km = " + currentKm);
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java	Mon Jun 18 09:16:05 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ChartGenerator.java	Mon Jun 18 11:21:30 2012 +0000
@@ -94,9 +94,6 @@
     public static final String XPATH_CHART_Y_RANGE =
         "/art:action/art:attributes/art:yrange";
 
-    public static final String XPATH_CHART_CURRENTKM =
-        "/art:action/art:attributes/art:currentKm";
-
 
     /** The document of the incoming out() request.*/
     protected Document request;
@@ -1082,30 +1079,6 @@
     }
 
 
-    public double getCurrentKmFromRequest() {
-        Element km = (Element)XMLUtils.xpath(
-            request,
-            XPATH_CHART_CURRENTKM,
-            XPathConstants.NODE,
-            ArtifactNamespaceContext.INSTANCE);
-
-        if (km == null) {
-            return -1d;
-        }
-
-        String uri = ArtifactNamespaceContext.NAMESPACE_URI;
-
-        String currentKm = km.getAttributeNS(uri, "km");
-        try {
-            double d = Double.valueOf(currentKm).doubleValue();
-            return d;
-        }
-        catch(NumberFormatException nfe) {
-            return -1d;
-        }
-    }
-
-
     /**
      * Returns the default size of a chart export as array.
      *
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixChartGenerator.java	Mon Jun 18 11:21:30 2012 +0000
@@ -0,0 +1,58 @@
+package de.intevation.flys.exports.fixings;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
+
+import org.apache.log4j.Logger;
+
+import java.io.OutputStream;
+
+import javax.xml.xpath.XPathConstants;
+
+import de.intevation.artifacts.ArtifactNamespaceContext;
+import de.intevation.artifacts.common.utils.XMLUtils;
+import de.intevation.artifacts.CallContext;
+
+import de.intevation.flys.exports.XYChartGenerator;
+
+public abstract class FixChartGenerator
+extends XYChartGenerator
+{
+    private static Logger logger = Logger.getLogger(FixChartGenerator.class);
+
+    public static final String XPATH_CHART_CURRENTKM =
+        "/art:action/art:attributes/art:currentKm";
+
+
+    @Override
+    public void init(Document request, OutputStream out, CallContext context) {
+        super.init(request, out, context);
+
+        logger.debug("currentKm = " + new Double(getCurrentKmFromRequest()));
+        context.putContextValue("currentKm", new Double(getCurrentKmFromRequest()));
+    }
+
+    public double getCurrentKmFromRequest() {
+        Element km = (Element)XMLUtils.xpath(
+            request,
+            XPATH_CHART_CURRENTKM,
+            XPathConstants.NODE,
+            ArtifactNamespaceContext.INSTANCE);
+
+        if (km == null) {
+            return -1d;
+        }
+
+        String uri = ArtifactNamespaceContext.NAMESPACE_URI;
+
+        String currentKm = km.getAttributeNS(uri, "km");
+        try {
+            double d = Double.valueOf(currentKm).doubleValue();
+            return d;
+        }
+        catch(NumberFormatException nfe) {
+            return -1d;
+        }
+    }
+}
+
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixDerivedCurveGenerator.java	Mon Jun 18 09:16:05 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixDerivedCurveGenerator.java	Mon Jun 18 11:21:30 2012 +0000
@@ -26,7 +26,7 @@
  * @author <a href="mailto:christian.lins@intevation.de">Christian Lins</a>
  */
 public class FixDerivedCurveGenerator
-extends XYChartGenerator
+extends FixChartGenerator
 implements FacetTypes
 {
     private static Logger logger =
@@ -69,7 +69,7 @@
 
         FixDerivateFacet facet = (FixDerivateFacet)aaf.getFacet();
         FixFunction func = (FixFunction)facet.getData(
-            aaf.getArtifact(), context, getCurrentKmFromRequest());
+            aaf.getArtifact(), context);
         
         double maxQ = func.getMaxQ();
         maxQ = Math.min(2000.0, Math.abs(maxQ));
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixWQCurveGenerator.java	Mon Jun 18 09:16:05 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixWQCurveGenerator.java	Mon Jun 18 11:21:30 2012 +0000
@@ -25,7 +25,7 @@
 import org.w3c.dom.Document;
 
 public class FixWQCurveGenerator
-extends XYChartGenerator
+extends FixChartGenerator
 implements FacetTypes
 {
     private static Logger logger =
@@ -133,7 +133,7 @@
 
         FixWQCurveFacet facet = (FixWQCurveFacet)aaf.getFacet();
         FixFunction func = (FixFunction)facet.getData(
-            aaf.getArtifact(), context, getCurrentKmFromRequest());
+            aaf.getArtifact(), context);
 
         if (func == null) {
             logger.warn("doWQCurveOut: Facet does not contain FixFunction");

http://dive4elements.wald.intevation.org