changeset 439:8975de9d7483

Loop through configuration to chart generation. gnv-artifacts/trunk@487 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 28 Dec 2009 16:24:05 +0000
parents 7399bb8f83ea
children eb2ac62e853a
files gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/state/OutputStateBase.java gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileMeshCrossOutputState.java gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileOutputState.java gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/vertical/VerticalProfileOutputState.java gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java gnv-artifacts/src/main/java/de/intevation/gnv/utils/StringUtils.java
diffstat 9 files changed, 123 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog	Mon Dec 28 11:50:27 2009 +0000
+++ b/gnv-artifacts/ChangeLog	Mon Dec 28 16:24:05 2009 +0000
@@ -1,3 +1,22 @@
+2009-12-28	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/gnv/state/OutputStateBase.java,
+	  src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java,
+	  src/main/java/de/intevation/gnv/state/profile/vertical/VerticalProfileOutputState.java,
+	  src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileOutputState.java,
+	  src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileMeshCrossOutputState.java,
+	  src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java,
+	  src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java:
+	  Bring CallContext down to the chart generation. This is necessary to
+	  access the configuration. BTW: this a much cleaner way than
+	  the omnipresent singletons all around in the code!
+
+	  Observation: All the stuff derived from OutputStateBase is coded very messy 
+	  ... even if your demands are not high about aesthetic :-/
+
+	* src/main/java/de/intevation/gnv/utils/StringUtils.java: New.
+	  Some functions to ease working with strings.
+
 2009-12-28	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/gnv/raster/PaletteManager.java: New.
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/OutputStateBase.java	Mon Dec 28 11:50:27 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/OutputStateBase.java	Mon Dec 28 16:24:05 2009 +0000
@@ -16,7 +16,10 @@
 import org.w3c.dom.NodeList;
 
 import de.intevation.artifactdatabase.Config;
+
 import de.intevation.artifacts.CallMeta;
+import de.intevation.artifacts.CallContext;
+
 import de.intevation.gnv.artifacts.cache.CacheFactory;
 import de.intevation.gnv.artifacts.ressource.RessourceFactory;
 import de.intevation.gnv.geobackend.base.Result;
@@ -142,15 +145,15 @@
     /**
      * @return
      */
-    protected Object getChartResult(String uuid) {
+    protected Object getChartResult(String uuid, CallContext callContext) {
         log.debug("OutputStateBase.getChartResult");
-        Collection<Result> result = null;
+        Object result = null;
         if (CacheFactory.getInstance().isInitialized()) {
             String key = uuid + super.getID();
             log.debug("Hash for Queryelements: " + key);
             net.sf.ehcache.Element value = CacheFactory.getInstance().getCache().get(key);
             if (value != null) {
-                result = (Collection<Result>) (value.getObjectValue());
+                result = value.getObjectValue();
             }else{
                 result = this.getData(this.queryID);
                 if (CacheFactory.getInstance().isInitialized()) {
@@ -162,7 +165,7 @@
         return result;
     }
 
-    protected Object getChartFromCache(String uuid) {
+    protected Object getChartFromCache(String uuid, CallContext callContext) {
         log.debug("Fetch chart [" + uuid + "] from cache");
         CacheFactory cacheFactory = CacheFactory.getInstance();
         if (cacheFactory.isInitialized()) {
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileMeshCrossOutputState.java	Mon Dec 28 11:50:27 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileMeshCrossOutputState.java	Mon Dec 28 16:24:05 2009 +0000
@@ -34,6 +34,9 @@
 
 import de.intevation.gnv.utils.DistanceCalculator;
 import de.intevation.gnv.utils.WKTUtils;
+import de.intevation.gnv.utils.StringUtils;
+
+import de.intevation.artifacts.CallContext;
 
 import org.jfree.chart.ChartTheme;
 
@@ -41,7 +44,6 @@
 import com.vividsolutions.jts.geom.LineString;
 import com.vividsolutions.jts.io.WKTReader;
 
-
 /**
  * @author Tim Englich <tim.englich@intevation.de>
  *
@@ -92,12 +94,13 @@
         Locale       locale,
         String       uuid,
         boolean      linesVisible,
-        boolean      shapesVisible
+        boolean      shapesVisible,
+        CallContext  callContext
     ) {
         Chart chart = null;
         if (CACHE_CHART) {
             log.info("Try to get horizontalprofilemeshcross chart from cache.");
-            chart = (Chart) getChartFromCache(uuid);
+            chart = (Chart) getChartFromCache(uuid, callContext);
         }
 
         if (chart != null)
@@ -127,7 +130,7 @@
     }
 
     @Override
-    protected Object getChartResult(String uuid) {
+    protected Object getChartResult(String uuid, CallContext callContext) {
         log.debug("HorizontalProfileMeshCrossOutputState.getChartResult");
         Collection<Result> result = null;
         if (CacheFactory.getInstance().isInitialized()) {
@@ -227,7 +230,7 @@
 
                 for (int j = 0; j < columns; ++j) {
                     String columnName = rd.getColumnName(j);
-                    if (!blacklisted(columnName)) {
+                    if (!StringUtils.contains(COLUMN_BLACKLIST, columnName)) {
                         resultDescriptor.addColumn(
                             columnName,
                             rd.getColumnClassName(j));
@@ -262,15 +265,6 @@
     }
 
 
-    private static final boolean blacklisted(String column) {
-        for (int i = 0; i < COLUMN_BLACKLIST.length; ++i) {
-            if (COLUMN_BLACKLIST.equals(column)) {
-                return true;
-            }
-        }
-        return false;
-    }
-
     private static final String [] DIFF_COLUMS = {
         "GROUP1",
         "GROUP2",
@@ -367,7 +361,7 @@
             int pcolums = pd.getColumnCount();
             for (int i = 0, j = 0; i < pcolums; ++i) {
                 String colname = pd.getColumnName(i);
-                if (blacklisted(colname)) {
+                if (StringUtils.contains(COLUMN_BLACKLIST, colname)) {
                     continue;
                 }
                 if (colname.equals("SHAPE")) {
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileOutputState.java	Mon Dec 28 11:50:27 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileOutputState.java	Mon Dec 28 16:24:05 2009 +0000
@@ -20,6 +20,8 @@
 
 import org.jfree.chart.ChartTheme;
 
+import de.intevation.artifacts.CallContext;
+
 import de.intevation.gnv.chart.Chart;
 import de.intevation.gnv.chart.ChartLabels;
 import de.intevation.gnv.chart.HorizontalProfileChart;
@@ -125,13 +127,14 @@
         Locale       locale,
         String       uuid,
         boolean      linesVisible,
-        boolean      shapesVisible
+        boolean      shapesVisible,
+        CallContext  callContext
     ) {
         Chart chart = null;
 
         if (CACHE_CHART) {
             log.info("Try to get horizontalprofile chart from cache.");
-            chart = (Chart) getChartFromCache(uuid);
+            chart = (Chart) getChartFromCache(uuid, callContext);
         }
 
         if (chart != null)
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java	Mon Dec 28 11:50:27 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontalcrosssection/HorizontalCrossSectionMeshOutputState.java	Mon Dec 28 16:24:05 2009 +0000
@@ -23,6 +23,8 @@
 import de.intevation.gnv.state.timeseries.TimeSeriesOutputState;
 import de.intevation.gnv.statistics.Statistics;
 
+import de.intevation.artifacts.CallContext;
+
 /**
  * @author Tim Englich <tim.englich@intevation.de>
  * 
@@ -57,13 +59,14 @@
         Locale       locale,
         String       uuid,
         boolean      linesVisible,
-        boolean      shapesVisible
+        boolean      shapesVisible,
+        CallContext  callContext
     ) {
         Chart chart = null;
 
         if (CACHE_CHART) {
             log.info("Try to get horizontalcrosssection chart from cache.");
-            chart = (Chart) getChartFromCache(uuid);
+            chart = (Chart) getChartFromCache(uuid, callContext);
         }
 
         if (chart != null)
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/vertical/VerticalProfileOutputState.java	Mon Dec 28 11:50:27 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/vertical/VerticalProfileOutputState.java	Mon Dec 28 16:24:05 2009 +0000
@@ -27,6 +27,8 @@
 import de.intevation.gnv.statistics.Statistics;
 import de.intevation.gnv.statistics.VerticalProfileStatistics;
 
+import de.intevation.artifacts.CallContext;
+
 /**
  * @author Tim Englich <tim.englich@intevation.de>
  * 
@@ -97,13 +99,14 @@
         Locale      locale,
         String      uuid,
         boolean     linesVisible,
-        boolean     shapesVisible
+        boolean     shapesVisible,
+        CallContext callContext
     ) {
         Chart chart = null;
 
         if (CACHE_CHART) {
             log.info("Try to get verticalprofile chart from cache.");
-            chart = (Chart) getChartFromCache(uuid);
+            chart = (Chart) getChartFromCache(uuid, callContext);
         }
 
         if (chart != null)
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java	Mon Dec 28 11:50:27 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java	Mon Dec 28 16:24:05 2009 +0000
@@ -29,6 +29,8 @@
 import com.vividsolutions.jts.io.ParseException;
 import com.vividsolutions.jts.io.WKTReader;
 
+import de.intevation.artifacts.CallContext;
+
 import de.intevation.gnv.artifacts.cache.CacheFactory;
 
 import de.intevation.gnv.chart.Chart;
@@ -57,6 +59,7 @@
 import de.intevation.gnv.statistics.VerticalProfileStatistics;
 
 import de.intevation.gnv.utils.WKTUtils;
+import de.intevation.gnv.utils.StringUtils;
 
 /**
  * @author Tim Englich <tim.englich@intevation.de>
@@ -93,7 +96,7 @@
 
 
     @Override
-    protected Object getChartResult(String uuid) {
+    protected Object getChartResult(String uuid, CallContext callContext) {
         log.debug("VerticalCrossSectionOutputState.getChartResult");
         Collection<Result> result = null;
         String key = uuid + super.getID();
@@ -192,7 +195,7 @@
                 for (int i = 0; i < columnCount; i++) {
                     String colName = rd.getColumnName(i);
 
-                    if (!attributeInList(colName)) {
+                    if (!StringUtils.contains(ATTRIBUTE_LIST, colName)) {
                         attColumns.setAttribute(
                             colName,
                             result.getObject(colName));
@@ -248,13 +251,14 @@
         Locale       locale,
         String       uuid,
         boolean      linesVisible,
-        boolean      shapesVisible
+        boolean      shapesVisible,
+        CallContext  callContext
     ) {
         Chart chart = null;
 
         if (CACHE_CHART) {
             log.info("Try to get verticalcrosssection chart from cache.");
-            chart = (Chart) getChartFromCache(uuid);
+            chart = (Chart) getChartFromCache(uuid, callContext);
         }
 
         if (chart != null)
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java	Mon Dec 28 11:50:27 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesOutputState.java	Mon Dec 28 16:24:05 2009 +0000
@@ -266,7 +266,8 @@
                     chartWidth,
                     chartHeight,
                     linesVisible,
-                    shapesVisible
+                    shapesVisible,
+                    callContext
                 );
             }
             else if (outputMode.equalsIgnoreCase("pdf")) {
@@ -354,13 +355,13 @@
             else if (outputMode.equalsIgnoreCase("csv")) {
                 log.debug("CSV-File will be generated.");
                 Collection<Result> chartResult =
-                    (Collection<Result>) getChartResult(uuid);
+                    (Collection<Result>) getChartResult(uuid, callContext);
                 this.createCSV(outputStream, chartResult);
             } else if (outputMode.equalsIgnoreCase("statistics")) {
                 log.debug("Statistics will be generated.");
                 Statistics s = getStatisticsGenerator();
                 Collection<Result> chartResult =
-                    (Collection<Result>) getChartResult(uuid);
+                    (Collection<Result>) getChartResult(uuid, callContext);
                 Collection<KeyValueDescibeData> parameters = 
                                                 this.getParameters(uuid);
                 Collection<KeyValueDescibeData> measurements = 
@@ -573,7 +574,8 @@
         int          width,
         int          height,
         boolean      linesVisible,
-        boolean      shapesVisible
+        boolean      shapesVisible,
+        CallContext  callContext
     )
     throws IOException, TechnicalChartException
     {
@@ -584,11 +586,12 @@
             parameters,
             measurements,
             dates,
-            getChartResult(uuid),
+            getChartResult(uuid, callContext),
             locale, // Locale
             uuid,
             linesVisible,
-            shapesVisible
+            shapesVisible,
+            callContext
         );
 
         if (chart == null) {
@@ -631,11 +634,12 @@
             parameters,
             measurements,
             dates,
-            (Collection) getChartResult(uuid),
+            (Collection) getChartResult(uuid, context),
             locale,
             uuid,
             linesVisible,
-            shapesVisible
+            shapesVisible,
+            context
         );
 
         if (chart == null) {
@@ -651,6 +655,7 @@
             50F, 50F, 50F, 50F
         );
 
+        /* XXX: @Ingo: What's this? Looks like dev test remains.
         try {
             OutputStream toFile = new FileOutputStream("/vol1/home/iweinzierl/tmp/test.svg");
             ChartExportHelper.exportSVG(
@@ -663,6 +668,7 @@
             toFile.close();
         }
         catch(Exception e) { log.debug("ERROR WHLILE TEST."); }
+        */
     }
 
 
@@ -686,11 +692,12 @@
             parameters,
             measurements,
             dates,
-            (Collection) getChartResult(uuid),
+            (Collection) getChartResult(uuid, callContext),
             locale,
             uuid,
             linesVisible,
-            shapesVisible
+            shapesVisible,
+            callContext
         );
 
         if (chart == null) {
@@ -719,13 +726,14 @@
         Locale       locale,
         String       uuid,
         boolean      linesVisible,
-        boolean      shapesVisible
+        boolean      shapesVisible,
+        CallContext  callContext
     ) {
         Chart chart = null;
 
         if (CACHE_CHART) {
             log.info("Try to get timeseries chart from cache.");
-            chart = (Chart) getChartFromCache(uuid);
+            chart = (Chart) getChartFromCache(uuid, callContext);
         }
 
         if (chart != null)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/StringUtils.java	Mon Dec 28 16:24:05 2009 +0000
@@ -0,0 +1,45 @@
+package de.intevation.gnv.utils;
+
+/**
+ * @author Sascha L. Teichmann <sascha.teichmann@intevation.de>
+ */
+public final class StringUtils
+{
+    private StringUtils() {
+    }
+
+    public static final String [] append(String [] haystack, String straw) {
+        if (haystack == null) {
+            return new String [] { straw };
+        }
+        String [] nhaystack = new String[haystack.length];
+        System.arraycopy(haystack, 0, nhaystack, 0, haystack.length);
+        nhaystack[haystack.length] = straw;
+        return nhaystack;
+    }
+
+    public static final boolean contains(String [] haystack, String needle) {
+        if (haystack == null) {
+            return false;
+        }
+
+        if (needle == null) {
+            for (int i = haystack.length - 1; i >= 0; --i) {
+                if (haystack[i] == null) {
+                    return true;
+                }
+            }
+        }
+        else {
+            for (int i = haystack.length - 1; i >= 0; --i) {
+                String straw = haystack[i];
+                if (straw != null && straw.equals(needle)) {
+                    return true;
+                }
+            }
+        }
+
+        return false;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

http://dive4elements.wald.intevation.org