annotate gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/horizontal/HorizontalProfileMeshVectorOutputState.java @ 1074:649f564a5184

Implemented a new output state and chart type for horizontal profiles using vector data. gnv-artifacts/trunk@1174 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 08 Jun 2010 13:00:58 +0000
parents
children dc9727a67d41
rev   line source
1074
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
1 package de.intevation.gnv.state.profile.horizontal;
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
2
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
3 import de.intevation.artifacts.CallContext;
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
4
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
5 import de.intevation.gnv.artifacts.cache.CacheFactory;
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
6
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
7 import de.intevation.gnv.chart.Chart;
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
8 import de.intevation.gnv.chart.ChartLabels;
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9 import de.intevation.gnv.chart.HorizontalProfileVectorChart;
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11 import de.intevation.gnv.geobackend.base.Result;
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13 import de.intevation.gnv.utils.VectorDataProcessor;
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15 import java.util.Collection;
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16 import java.util.Locale;
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18 import net.sf.ehcache.Cache;
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
19
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20 import org.apache.log4j.Logger;
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
21
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22 import org.jfree.chart.ChartTheme;
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
24
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25 /**
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
27 */
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
28 public class HorizontalProfileMeshVectorOutputState
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29 extends HorizontalProfileMeshOutputState
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30 {
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
31 private static Logger logger =
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32 Logger.getLogger(HorizontalProfileMeshVectorOutputState.class);
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34 public static final String[] RESULT_COLUMNS = {
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35 "YORDINATE", "SHAPE",
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36 "GROUP1", "GROUP2", "GROUP3",
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
37 "IPOSITION", "JPOSITION",
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
38 "DATAID", "MESHID",
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39 "SERIES"
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40 };
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
43 @Override
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44 protected Object getChartResult(String uuid, CallContext callContext) {
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
45 logger.debug("Fetch data for horizontalprofile chart with vector data");
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46 CacheFactory factory = CacheFactory.getInstance();
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48 if (factory.isInitialized()) {
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49 // we use a cache
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50 logger.info("Using cache.");
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51 Cache cache = factory.getCache();
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52 String key = "chart_" + getHash();
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54 net.sf.ehcache.Element value = cache.get(key);
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55 if (value != null) {
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56 logger.debug("Found element in cache.");
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
57 return value.getObjectValue();
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
58 }
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
59 else {
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60 logger.debug("Element not in cache, we ask the database");
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
61 Collection<Result> res = (Collection<Result>)getData(queryID);
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
62 res = VectorDataProcessor.process(res, RESULT_COLUMNS);
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
63 logger.debug("Got " + res.size() + " elements from database.");
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65 cache.put(new net.sf.ehcache.Element(key, res));
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
67 return res;
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68 }
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69 }
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70 else {
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71 // we don't use a cache, so we have to query the database every
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
72 // single time
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73 logger.info("Not using a cache.");
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
74 return VectorDataProcessor.process(
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
75 getData(queryID), RESULT_COLUMNS);
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
76 }
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
77 }
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
78
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
79
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
80 @Override
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
81 protected Chart getChart(
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
82 ChartLabels chartLables,
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
83 ChartTheme theme,
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
84 Collection parameters,
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
85 Collection measurements,
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
86 Collection dates,
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
87 Object result,
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
88 Locale locale,
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
89 String uuid,
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
90 boolean linesVisible,
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
91 boolean shapesVisible,
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
92 CallContext callContext
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
93 ) {
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
94 Chart chart = new HorizontalProfileVectorChart(
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
95 chartLables,
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
96 theme,
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
97 parameters,
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
98 measurements,
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
99 dates,
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
100 (Collection)result,
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
101 timeGapDefinitions,
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
102 locale,
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
103 linesVisible,
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
104 shapesVisible
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
105 );
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
106 chart.generateChart();
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
107
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
108 return chart;
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
109 }
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
110 }
649f564a5184 Implemented a new output state and chart type for horizontal profiles using vector data.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
111 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org