Mercurial > dive4elements > gnv-client
changeset 1041:8a8ee5abc084
Implemented the odv export for timeseries using vector data (Issue27).
gnv-artifacts/trunk@1113 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 20 May 2010 09:47:19 +0000 |
parents | 70653c29fc1d |
children | 07b829c06981 |
files | gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesVectorOutputState.java |
diffstat | 2 files changed, 118 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog Wed May 19 14:05:33 2010 +0000 +++ b/gnv-artifacts/ChangeLog Thu May 20 09:47:19 2010 +0000 @@ -1,3 +1,14 @@ +2010-05-20 Ingo Weinzierl <ingo.weinzierl@intevation.de> + + Issue27 - Implemented odv export for vector data of timeseriespoints. + + * src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesVectorOutputState.java: + Implemented the odv export for vector data on timeseriespoints.Therefore, + the getData(.) method for processing vector data has been removed. The + processing needs to take place after getData(.) fetched the data from + database, because it's not necessary to process vector data used for an + odv export (which is fetched via getData(.) as well). + 2010-05-19 Ingo Weinzierl <ingo.weinzierl@intevation.de> Issue27 - Vector data support for timeseriespoints finished.
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesVectorOutputState.java Wed May 19 14:05:33 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesVectorOutputState.java Thu May 20 09:47:19 2010 +0000 @@ -1,21 +1,35 @@ package de.intevation.gnv.state.timeseries; +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.TimeSeriesVectorChart; +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.geobackend.base.query.QueryExecutor; -import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory; -import de.intevation.gnv.geobackend.base.query.exception.QueryException; 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; @@ -28,29 +42,83 @@ private static Logger logger = Logger.getLogger(TimeSeriesVectorOutputState.class); + 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"}; + public TimeSeriesVectorOutputState() { } @Override - protected Collection<Result> getData(String queryID) { - logger.debug("Fetch chart data from database and convert it."); - try { - String[] filter = generateFilterValuesFromInputData(); - QueryExecutor queryExecutor = - QueryExecutorFactory.getInstance().getQueryExecutor(); + protected Object getChartResult(String uuid, CallContext callContext) { + logger.debug("OutputStateBase.getChartResult"); + CacheFactory factory = CacheFactory.getInstance(); - Collection<Result> res = queryExecutor.executeQuery(queryID,filter); - return VectorDataProcessor.process(res); + if (factory.isInitialized()) { + // we use a cache + logger.info("Using cache."); + Cache cache = factory.getCache(); + String key = "chart_" + getHash(uuid); + + 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); + cache.put(new net.sf.ehcache.Element(key, res)); + + return res; + } } - catch (RuntimeException e) { - logger.error(e, e); + 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)); } - catch (QueryException e) { - logger.error(e, e); - } - - return null; } @@ -84,5 +152,26 @@ 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 :