Mercurial > dive4elements > gnv-client
view gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesVectorOutputState.java @ 1145:dfe1ac687c7f tip
added tags
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:16:15 +0200 |
parents | f953c9a559d8 |
children |
line wrap: on
line source
/* * Copyright (c) 2010 by Intevation GmbH * * This program is free software under the LGPL (>=v2.1) * Read the file LGPL.txt coming with the software for details * or visit http://www.gnu.org/licenses/ if it does not exist. */ 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.utils.VectorDataProcessor; import de.intevation.gnv.state.describedata.KeyValueDescibeData; import de.intevation.gnv.state.exception.StateException; import de.intevation.gnv.statistics.Statistics; import de.intevation.gnv.statistics.TimeseriesVectorStatistics; import java.io.IOException; import java.io.OutputStream; import java.util.Collection; import java.util.Locale; import java.util.Map; 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 TimeSeriesVectorOutputState extends TimeSeriesOutputState { private static Logger logger = Logger.getLogger(TimeSeriesVectorOutputState.class); public static final String[] RESULT_COLUMNS = { "YORDINATE", "XORDINATE", "GROUP1", "GROUP2", "GROUP3", "GAPID", "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"}; public TimeSeriesVectorOutputState() { } @Override protected Object getChartResult(String uuid, CallContext callContext) { logger.debug("OutputStateBase.getChartResult"); 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); 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 TimeSeriesVectorChart( chartLables, theme, parameters, measurements, dates, (Collection)result, timeGapDefinitions, locale, linesVisible, shapesVisible ); chart.generateChart(); return chart; } @Override protected Chart[] getHistograms( String uuid, CallContext callContext, Collection<KeyValueDescibeData> parameters, Collection<KeyValueDescibeData> measurements, Collection<KeyValueDescibeData> dates, Map requestParameter ) { Collection results = (Collection) getChartResult(uuid, callContext); ChartTheme theme = createStyle(callContext); return VectorDataProcessor.getHistograms( uuid, callContext, results, theme, requestParameter); } @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); } protected Statistics getStatisticsGenerator() { return new TimeseriesVectorStatistics(); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :