Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/timeseries/TimeSeriesVectorOutputState.java @ 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 | cc4ec127d666 |
comparison
equal
deleted
inserted
replaced
1040:70653c29fc1d | 1041:8a8ee5abc084 |
---|---|
1 package de.intevation.gnv.state.timeseries; | 1 package de.intevation.gnv.state.timeseries; |
2 | 2 |
3 import au.com.bytecode.opencsv.CSVWriter; | |
4 | |
3 import de.intevation.artifacts.CallContext; | 5 import de.intevation.artifacts.CallContext; |
6 | |
7 import de.intevation.gnv.artifacts.cache.CacheFactory; | |
4 | 8 |
5 import de.intevation.gnv.chart.Chart; | 9 import de.intevation.gnv.chart.Chart; |
6 import de.intevation.gnv.chart.ChartLabels; | 10 import de.intevation.gnv.chart.ChartLabels; |
7 import de.intevation.gnv.chart.TimeSeriesVectorChart; | 11 import de.intevation.gnv.chart.TimeSeriesVectorChart; |
8 | 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 | |
9 import de.intevation.gnv.geobackend.base.Result; | 19 import de.intevation.gnv.geobackend.base.Result; |
10 import de.intevation.gnv.geobackend.base.query.QueryExecutor; | |
11 import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory; | |
12 import de.intevation.gnv.geobackend.base.query.exception.QueryException; | |
13 | 20 |
14 import de.intevation.gnv.utils.VectorDataProcessor; | 21 import de.intevation.gnv.utils.VectorDataProcessor; |
15 | 22 |
23 import de.intevation.gnv.state.exception.StateException; | |
24 | |
25 import java.io.IOException; | |
26 import java.io.OutputStream; | |
27 | |
16 import java.util.Collection; | 28 import java.util.Collection; |
17 import java.util.Locale; | 29 import java.util.Locale; |
30 | |
31 import net.sf.ehcache.Cache; | |
18 | 32 |
19 import org.apache.log4j.Logger; | 33 import org.apache.log4j.Logger; |
20 | 34 |
21 import org.jfree.chart.ChartTheme; | 35 import org.jfree.chart.ChartTheme; |
22 | 36 |
26 public class TimeSeriesVectorOutputState extends TimeSeriesOutputState { | 40 public class TimeSeriesVectorOutputState extends TimeSeriesOutputState { |
27 | 41 |
28 private static Logger logger = | 42 private static Logger logger = |
29 Logger.getLogger(TimeSeriesVectorOutputState.class); | 43 Logger.getLogger(TimeSeriesVectorOutputState.class); |
30 | 44 |
45 public static final String[] ODV_COLUMN_HEADERS = { | |
46 "Cruise", | |
47 "Station", | |
48 "Type", | |
49 "yyyy-mm-dd hh:mm", | |
50 "Lon (°E)", | |
51 "Lat (°N)", | |
52 "Bot. Depth [m]", | |
53 "Depth [m]", | |
54 "QF", | |
55 "XComponent", | |
56 "QF", | |
57 "YComponent", | |
58 "QF", | |
59 "ZComponent", | |
60 "QF", | |
61 "Speed", | |
62 "QF", | |
63 "Direction", | |
64 "QF" | |
65 }; | |
66 | |
67 public static final String[] ODV_PROFILE_NAMES = { | |
68 "CRUISE", | |
69 "STATION", | |
70 "TYPE", | |
71 "TIMEVALUE", | |
72 "SHAPE", | |
73 "BOTDEPTH", | |
74 "DEPTH", | |
75 "QF", | |
76 "XCOMPONENT", | |
77 "QF", | |
78 "YCOMPONENT", | |
79 "QF", | |
80 "ZCOMPONENT", | |
81 "QF", | |
82 "SPEED", | |
83 "QF", | |
84 "DIRECTION", | |
85 "QF"}; | |
86 | |
31 public TimeSeriesVectorOutputState() { | 87 public TimeSeriesVectorOutputState() { |
32 } | 88 } |
33 | 89 |
34 | 90 |
35 @Override | 91 @Override |
36 protected Collection<Result> getData(String queryID) { | 92 protected Object getChartResult(String uuid, CallContext callContext) { |
37 logger.debug("Fetch chart data from database and convert it."); | 93 logger.debug("OutputStateBase.getChartResult"); |
38 try { | 94 CacheFactory factory = CacheFactory.getInstance(); |
39 String[] filter = generateFilterValuesFromInputData(); | |
40 QueryExecutor queryExecutor = | |
41 QueryExecutorFactory.getInstance().getQueryExecutor(); | |
42 | 95 |
43 Collection<Result> res = queryExecutor.executeQuery(queryID,filter); | 96 if (factory.isInitialized()) { |
44 return VectorDataProcessor.process(res); | 97 // we use a cache |
98 logger.info("Using cache."); | |
99 Cache cache = factory.getCache(); | |
100 String key = "chart_" + getHash(uuid); | |
101 | |
102 net.sf.ehcache.Element value = cache.get(key); | |
103 if (value != null) { | |
104 logger.debug("Found element in cache."); | |
105 return value.getObjectValue(); | |
106 } | |
107 else { | |
108 logger.debug("Element not in cache, we ask the database"); | |
109 Collection<Result> res = (Collection<Result>)getData(queryID); | |
110 res = VectorDataProcessor.process(res); | |
111 cache.put(new net.sf.ehcache.Element(key, res)); | |
112 | |
113 return res; | |
114 } | |
45 } | 115 } |
46 catch (RuntimeException e) { | 116 else { |
47 logger.error(e, e); | 117 // we don't use a cache, so we have to query the database every |
118 // single time | |
119 logger.info("Not using a cache."); | |
120 return VectorDataProcessor.process(getData(queryID)); | |
48 } | 121 } |
49 catch (QueryException e) { | |
50 logger.error(e, e); | |
51 } | |
52 | |
53 return null; | |
54 } | 122 } |
55 | 123 |
56 | 124 |
57 @Override | 125 @Override |
58 protected Chart getChart( | 126 protected Chart getChart( |
82 ); | 150 ); |
83 chart.generateChart(); | 151 chart.generateChart(); |
84 | 152 |
85 return chart; | 153 return chart; |
86 } | 154 } |
155 | |
156 | |
157 @Override | |
158 protected void createODV( | |
159 OutputStream outputStream, Collection result, String uuid) | |
160 throws IOException, StateException | |
161 { | |
162 logger.info("Start exporting " + result.size() + " items to odv."); | |
163 Export export = new DefaultExport( | |
164 new SimpleOdvDataCollector(ODV_PROFILE_NAMES)); | |
165 | |
166 Profile profile = new DefaultProfile( | |
167 ODV_COLUMN_HEADERS, | |
168 '\t', | |
169 CSVWriter.NO_QUOTE_CHARACTER, | |
170 CSVWriter.NO_ESCAPE_CHARACTER, | |
171 "ODV", | |
172 "ISO-8859-1"); | |
173 | |
174 export.create(profile, outputStream, result); | |
175 } | |
87 } | 176 } |
88 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : | 177 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |