Mercurial > dive4elements > gnv-client
view gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/horizontal/HorizontalProfileOutputTransition.java @ 333:19571fd1d0e8
Sourced ChartFactory call out to an own method, which is overriden by TimeSeriesChart.
gnv-artifacts/trunk@399 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 07 Dec 2009 10:33:31 +0000 |
parents | 1c427acb6c76 |
children |
line wrap: on
line source
/** * */ package de.intevation.gnv.transition.profile.horizontal; import com.vividsolutions.jts.geom.Point; import com.vividsolutions.jts.io.WKTReader; import com.vividsolutions.jts.io.ParseException; import java.io.IOException; import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.text.SimpleDateFormat; import java.util.Collection; import java.util.Date; import java.util.Iterator; import java.util.Locale; import org.apache.log4j.Logger; import de.intevation.gnv.chart.Chart; import de.intevation.gnv.chart.ChartLabels; import de.intevation.gnv.chart.HorizontalProfileChart; import de.intevation.gnv.geobackend.base.Result; import de.intevation.gnv.statistics.HorizontalProfileStatistics; import de.intevation.gnv.statistics.Statistics; import de.intevation.gnv.transition.exception.TransitionException; import de.intevation.gnv.transition.timeseries.TimeSeriesOutputTransition; import de.intevation.gnv.exports.DefaultExport; import de.intevation.gnv.exports.ShapeDataCollector; import de.intevation.gnv.exports.DefaultProfile; import de.intevation.gnv.exports.Export.Profile; import de.intevation.gnv.transition.describedata.KeyValueDescibeData; /** * @author Tim Englich <tim.englich@intevation.de> * */ public class HorizontalProfileOutputTransition extends TimeSeriesOutputTransition { /** * The UID of this class */ private static final long serialVersionUID = 4401516087492028840L; private static Logger log = Logger .getLogger(HorizontalProfileOutputTransition.class); public static final String DATE_FORMAT = "yyyy.MM.dd HH:mm:ss"; public static final String [] CHART_TITLE_META = { "CRUISE", "DEPTH", "SHAPE" }; public static final String [] CHART_TITLE_META_RESSOURCES = { "cruiseid", "depth", "coordinate" }; public static final String [] TIMESERIES_CSV_PROFILE_NAMES = { "SHAPE", "YORDINATE", "GROUP1", "GROUP2", "GROUP3" }; public static final Profile TIMESERIES_CSV_PROFILE = new DefaultProfile( null, ',', '"', '"', "CSV", "ISO-8859-1"); /** * Constructor */ public HorizontalProfileOutputTransition() { super(); super.domainLable = "Distance [km]"; } @Override protected Chart getChart( ChartLabels chartLables, Collection parameters, Collection measurements, Collection dates, Collection result, Locale locale, String uuid, boolean linesVisible, boolean shapesVisible ) { Chart chart = null; if (CACHE_CHART) { log.info("Try to get horizontalprofile chart from cache."); chart = (Chart) getChartFromCache(uuid); } if (chart != null) return chart; log.info("Chart not in cache yet."); chart = new HorizontalProfileChart( chartLables, createStyle(), parameters, measurements, dates, result, null, locale, linesVisible, shapesVisible ); chart.generateChart(); if (CACHE_CHART) { log.info("Put chart into cache."); purifyChart(chart, uuid); } return chart; } /** * @see de.intevation.gnv.transition.timeseries.TimeSeriesOutputTransition#getStatisticsGenerator() */ @Override protected Statistics getStatisticsGenerator() { return new HorizontalProfileStatistics(); } @Override protected void createCSV(OutputStream outputStream, Collection<Result> chartResult) throws UnsupportedEncodingException, IOException, TransitionException { log.debug("createCSV for HorizontalProfileOutputTransition."); DefaultExport export = new DefaultExport( new ShapeDataCollector(TIMESERIES_CSV_PROFILE_NAMES)); export.create(TIMESERIES_CSV_PROFILE, outputStream, chartResult); } protected String createChartTitle(Locale locale, String uuid) { String fisName = getFisName(locale); log.debug("created title for horizontal profile chart: " + fisName); return fisName; } protected String createChartSubtitle(Locale locale, String uuid) { log.debug("create chart subtitle."); String subtitle = createTimePeriod(locale, uuid); // ODV results contain meta information about cruise, station and so on Collection results = getODVResult(uuid); if (results != null) { Iterator iter = results.iterator(); Result result = iter.hasNext() ? (Result) iter.next() : null; subtitle += subtitle.length() != 0 ? "\n" : ""; subtitle += createMetaChartSubtitle(locale, result); } return subtitle; } protected String createMetaChartSubtitle(Locale locale, Result result) { log.debug("Fetch meta information and put it into subtitle."); if (result == null) return ""; StringBuilder meta = new StringBuilder(); WKTReader wktReader = new WKTReader(); for (int i = 0; i < CHART_TITLE_META.length; i++) { String qry = CHART_TITLE_META[i]; if (qry.equals("SHAPE")) { try { Point p = (Point) wktReader.read(result.getString(qry)); meta.append(getMessage(locale,"coordinate","coordinate")); meta.append(": "); log.debug( "Add " + qry + " to meta information of subtitle: " + p.toString() ); meta.append(p.getX() + ", " + p.getY()); } catch (ParseException pe) { log.warn("Error while parsing point.", pe); } } else { log.debug( "Add " + qry + " to meta information of subtitle: " + result.getString(qry) ); meta.append(getMessage( locale, CHART_TITLE_META_RESSOURCES[i], CHART_TITLE_META_RESSOURCES[i] )); meta.append(": "); meta.append(result.getString(qry)); } if (i != CHART_TITLE_META.length-1) meta.append("\n"); } log.debug("Meta title for chart: " + meta.toString()); return meta.toString(); } protected String createTimePeriod(Locale locale, String uuid) { log.debug("create time period for chart subtitle."); String subTitle = null; Date startDate = null; Date endDate = null; Collection dates = getDates(uuid); if (dates == null) { log.debug("No time period for subtitle."); return ""; } SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT); KeyValueDescibeData data = null; Iterator iter = dates.iterator(); while (iter.hasNext()) { try { data = (KeyValueDescibeData)iter.next(); if (!data.isSelected()) continue; Date current = format.parse(data.getValue()); long time = current.getTime(); if (startDate == null) { startDate = current; endDate = current; } else if (time < startDate.getTime()) { startDate = current; } else if (time > endDate.getTime()) { endDate = current; } } catch (java.text.ParseException pe) { log.warn("Error while parsing date: " + data.getValue(), pe); } } subTitle = format.format(startDate) + " - " + format.format(endDate); log.debug("created title for horizontal profile chart: " + subTitle); return subTitle; } }