diff gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/vertical/VerticalProfileVectorOutputState.java @ 1071:9bb1979aabbe

Added a new output state and chart type for vertical profiles using vector data. gnv-artifacts/trunk@1168 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 07 Jun 2010 15:00:23 +0000
parents
children 1657ee3ac054
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/vertical/VerticalProfileVectorOutputState.java	Mon Jun 07 15:00:23 2010 +0000
@@ -0,0 +1,186 @@
+package de.intevation.gnv.state.profile.vertical;
+
+import au.com.bytecode.opencsv.CSVWriter;
+
+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.VerticalProfileVectorChart;
+
+import de.intevation.gnv.exports.DefaultExport;
+import de.intevation.gnv.exports.DefaultProfile;
+import de.intevation.gnv.exports.Export;
+import de.intevation.gnv.exports.Export.Profile;
+import de.intevation.gnv.exports.SimpleOdvDataCollector;
+
+import de.intevation.gnv.geobackend.base.Result;
+
+import de.intevation.gnv.utils.VectorDataProcessor;
+
+import de.intevation.gnv.state.exception.StateException;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+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 VerticalProfileVectorOutputState
+extends      VerticalProfileOutputState
+{
+    private static Logger logger =
+        Logger.getLogger(VerticalProfileVectorOutputState.class);
+
+    public static final String[] RESULT_COLUMNS = {
+        "YORDINATE", "XORDINATE",
+        "GROUP1",    "GROUP2",     "GROUP3",
+        "DATAID",    "FEATUREID",  "TIMESERIESID",
+        "SERIES"
+    };
+
+
+    public static final String[] ODV_COLUMN_HEADERS = {
+        "Cruise",
+        "Station",
+        "Type",
+        "yyyy-mm-dd hh:mm",
+        "Lon (°E)",
+        "Lat (°N)",
+        "Bot. Depth [m]",
+        "Depth [m]",
+        "QF",
+        "XComponent",
+        "QF",
+        "YComponent",
+        "QF",
+        "ZComponent",
+        "QF",
+        "Speed",
+        "QF",
+        "Direction",
+        "QF"
+    };
+
+    public static final String[] ODV_PROFILE_NAMES = {
+        "CRUISE",
+        "STATION",
+        "TYPE",
+        "TIMEVALUE",
+        "SHAPE",
+        "BOTDEPTH",
+        "DEPTH",
+        "QF",
+        "XCOMPONENT",
+        "QF",
+        "YCOMPONENT",
+        "QF",
+        "ZCOMPONENT",
+        "QF",
+        "SPEED",
+        "QF",
+        "DIRECTION",
+        "QF"};
+
+
+    @Override
+    protected Object getChartResult(String uuid, CallContext callContext) {
+        logger.debug("Fetch chart data for vertical profile 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);
+                logger.debug("Got " + res.size() + " elements from db.");
+
+                res = VectorDataProcessor.process(res, RESULT_COLUMNS);
+                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 VerticalProfileVectorChart(
+            chartLables,
+            theme,
+            parameters,
+            measurements,
+            dates,
+            (Collection)result,
+            timeGapDefinitions,
+            locale,
+            linesVisible,
+            shapesVisible
+        );
+        chart.generateChart();
+
+        return chart;
+    }
+
+
+    @Override
+    protected void createODV(
+        OutputStream outputStream, Collection result, String uuid)
+    throws IOException, StateException
+    {
+        logger.info("Start exporting " + result.size() + " items to odv.");
+        Export export = new DefaultExport(
+            new SimpleOdvDataCollector(ODV_PROFILE_NAMES));
+
+        Profile profile = new DefaultProfile(
+            ODV_COLUMN_HEADERS,
+            '\t',
+            CSVWriter.NO_QUOTE_CHARACTER,
+            CSVWriter.NO_ESCAPE_CHARACTER,
+            "ODV",
+            "ISO-8859-1");
+
+        export.create(profile, outputStream, result);
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org