comparison 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
comparison
equal deleted inserted replaced
1070:7096a2e13676 1071:9bb1979aabbe
1 package de.intevation.gnv.state.profile.vertical;
2
3 import au.com.bytecode.opencsv.CSVWriter;
4
5 import de.intevation.artifacts.CallContext;
6
7 import de.intevation.gnv.artifacts.cache.CacheFactory;
8
9 import de.intevation.gnv.chart.Chart;
10 import de.intevation.gnv.chart.ChartLabels;
11 import de.intevation.gnv.chart.VerticalProfileVectorChart;
12
13 import de.intevation.gnv.exports.DefaultExport;
14 import de.intevation.gnv.exports.DefaultProfile;
15 import de.intevation.gnv.exports.Export;
16 import de.intevation.gnv.exports.Export.Profile;
17 import de.intevation.gnv.exports.SimpleOdvDataCollector;
18
19 import de.intevation.gnv.geobackend.base.Result;
20
21 import de.intevation.gnv.utils.VectorDataProcessor;
22
23 import de.intevation.gnv.state.exception.StateException;
24
25 import java.io.IOException;
26 import java.io.OutputStream;
27
28 import java.util.Collection;
29 import java.util.Locale;
30
31 import net.sf.ehcache.Cache;
32
33 import org.apache.log4j.Logger;
34
35 import org.jfree.chart.ChartTheme;
36
37 /**
38 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
39 */
40 public class VerticalProfileVectorOutputState
41 extends VerticalProfileOutputState
42 {
43 private static Logger logger =
44 Logger.getLogger(VerticalProfileVectorOutputState.class);
45
46 public static final String[] RESULT_COLUMNS = {
47 "YORDINATE", "XORDINATE",
48 "GROUP1", "GROUP2", "GROUP3",
49 "DATAID", "FEATUREID", "TIMESERIESID",
50 "SERIES"
51 };
52
53
54 public static final String[] ODV_COLUMN_HEADERS = {
55 "Cruise",
56 "Station",
57 "Type",
58 "yyyy-mm-dd hh:mm",
59 "Lon (°E)",
60 "Lat (°N)",
61 "Bot. Depth [m]",
62 "Depth [m]",
63 "QF",
64 "XComponent",
65 "QF",
66 "YComponent",
67 "QF",
68 "ZComponent",
69 "QF",
70 "Speed",
71 "QF",
72 "Direction",
73 "QF"
74 };
75
76 public static final String[] ODV_PROFILE_NAMES = {
77 "CRUISE",
78 "STATION",
79 "TYPE",
80 "TIMEVALUE",
81 "SHAPE",
82 "BOTDEPTH",
83 "DEPTH",
84 "QF",
85 "XCOMPONENT",
86 "QF",
87 "YCOMPONENT",
88 "QF",
89 "ZCOMPONENT",
90 "QF",
91 "SPEED",
92 "QF",
93 "DIRECTION",
94 "QF"};
95
96
97 @Override
98 protected Object getChartResult(String uuid, CallContext callContext) {
99 logger.debug("Fetch chart data for vertical profile with vector data.");
100 CacheFactory factory = CacheFactory.getInstance();
101
102 if (factory.isInitialized()) {
103 // we use a cache
104 logger.info("Using cache.");
105 Cache cache = factory.getCache();
106 String key = "chart_" + getHash();
107
108 net.sf.ehcache.Element value = cache.get(key);
109 if (value != null) {
110 logger.debug("Found element in cache.");
111 return value.getObjectValue();
112 }
113 else {
114 logger.debug("Element not in cache, we ask the database");
115 Collection<Result> res = (Collection<Result>)getData(queryID);
116 logger.debug("Got " + res.size() + " elements from db.");
117
118 res = VectorDataProcessor.process(res, RESULT_COLUMNS);
119 cache.put(new net.sf.ehcache.Element(key, res));
120
121 return res;
122 }
123 }
124 else {
125 // we don't use a cache, so we have to query the database every
126 // single time
127 logger.info("Not using a cache.");
128 return VectorDataProcessor.process(
129 getData(queryID), RESULT_COLUMNS);
130 }
131 }
132
133
134 @Override
135 protected Chart getChart(
136 ChartLabels chartLables,
137 ChartTheme theme,
138 Collection parameters,
139 Collection measurements,
140 Collection dates,
141 Object result,
142 Locale locale,
143 String uuid,
144 boolean linesVisible,
145 boolean shapesVisible,
146 CallContext callContext
147 ) {
148 Chart chart = new VerticalProfileVectorChart(
149 chartLables,
150 theme,
151 parameters,
152 measurements,
153 dates,
154 (Collection)result,
155 timeGapDefinitions,
156 locale,
157 linesVisible,
158 shapesVisible
159 );
160 chart.generateChart();
161
162 return chart;
163 }
164
165
166 @Override
167 protected void createODV(
168 OutputStream outputStream, Collection result, String uuid)
169 throws IOException, StateException
170 {
171 logger.info("Start exporting " + result.size() + " items to odv.");
172 Export export = new DefaultExport(
173 new SimpleOdvDataCollector(ODV_PROFILE_NAMES));
174
175 Profile profile = new DefaultProfile(
176 ODV_COLUMN_HEADERS,
177 '\t',
178 CSVWriter.NO_QUOTE_CHARACTER,
179 CSVWriter.NO_ESCAPE_CHARACTER,
180 "ODV",
181 "ISO-8859-1");
182
183 export.create(profile, outputStream, result);
184 }
185 }
186 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org