diff gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileMeshVectorOutputState.java @ 1074:649f564a5184

Implemented a new output state and chart type for horizontal profiles using vector data. gnv-artifacts/trunk@1174 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 08 Jun 2010 13:00:58 +0000
parents
children dc9727a67d41
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileMeshVectorOutputState.java	Tue Jun 08 13:00:58 2010 +0000
@@ -0,0 +1,111 @@
+package de.intevation.gnv.state.profile.horizontal;
+
+import de.intevation.artifacts.CallContext;
+
+import de.intevation.gnv.artifacts.cache.CacheFactory;
+
+import de.intevation.gnv.chart.Chart;
+import de.intevation.gnv.chart.ChartLabels;
+import de.intevation.gnv.chart.HorizontalProfileVectorChart;
+
+import de.intevation.gnv.geobackend.base.Result;
+
+import de.intevation.gnv.utils.VectorDataProcessor;
+
+import java.util.Collection;
+import java.util.Locale;
+
+import net.sf.ehcache.Cache;
+
+import org.apache.log4j.Logger;
+
+import org.jfree.chart.ChartTheme;
+
+
+/**
+ * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
+ */
+public class HorizontalProfileMeshVectorOutputState
+extends      HorizontalProfileMeshOutputState
+{
+    private static Logger logger =
+        Logger.getLogger(HorizontalProfileMeshVectorOutputState.class);
+
+    public static final String[] RESULT_COLUMNS = {
+        "YORDINATE", "SHAPE",
+        "GROUP1",    "GROUP2",    "GROUP3",
+        "IPOSITION", "JPOSITION",
+        "DATAID",    "MESHID",
+        "SERIES"
+    };
+
+
+    @Override
+    protected Object getChartResult(String uuid, CallContext callContext) {
+        logger.debug("Fetch data for horizontalprofile chart with vector data");
+        CacheFactory factory = CacheFactory.getInstance();
+
+        if (factory.isInitialized()) {
+            // we use a cache
+            logger.info("Using cache.");
+            Cache cache = factory.getCache();
+            String key  = "chart_" + getHash();
+
+            net.sf.ehcache.Element value = cache.get(key);
+            if (value != null) {
+                logger.debug("Found element in cache.");
+                return value.getObjectValue();
+            }
+            else {
+                logger.debug("Element not in cache, we ask the database");
+                Collection<Result> res = (Collection<Result>)getData(queryID);
+                res = VectorDataProcessor.process(res, RESULT_COLUMNS);
+                logger.debug("Got " + res.size() + " elements from database.");
+
+                cache.put(new net.sf.ehcache.Element(key, res));
+
+                return res;
+            }
+        }
+        else {
+            // we don't use a cache, so we have to query the database every
+            // single time
+            logger.info("Not using a cache.");
+            return VectorDataProcessor.process(
+                getData(queryID), RESULT_COLUMNS);
+        }
+    }
+
+
+    @Override
+    protected Chart getChart(
+        ChartLabels  chartLables,
+        ChartTheme   theme,
+        Collection   parameters,
+        Collection   measurements,
+        Collection   dates,
+        Object       result,
+        Locale       locale,
+        String       uuid,
+        boolean      linesVisible,
+        boolean      shapesVisible,
+        CallContext  callContext
+    ) {
+        Chart chart = new HorizontalProfileVectorChart(
+            chartLables,
+            theme,
+            parameters,
+            measurements,
+            dates,
+            (Collection)result,
+            timeGapDefinitions,
+            locale,
+            linesVisible,
+            shapesVisible
+        );
+        chart.generateChart();
+
+        return chart;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org