comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelState.java @ 3318:dbe2f85bf160

merged flys-artifacts/2.8
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:35 +0200
parents 3a93bbbe2ec7
children f858028dde5f
comparison
equal deleted inserted replaced
2987:98c7a46ec5ae 3318:dbe2f85bf160
1 package de.intevation.flys.artifacts.states;
2
3 import de.intevation.artifactdatabase.state.Facet;
4
5 import de.intevation.artifacts.CallContext;
6
7 import de.intevation.flys.artifacts.ChartArtifact;
8 import de.intevation.flys.artifacts.FLYSArtifact;
9 import de.intevation.flys.artifacts.WINFOArtifact;
10
11 import de.intevation.flys.artifacts.model.CalculationResult;
12 import de.intevation.flys.artifacts.model.CrossSectionWaterLineFacet;
13 import de.intevation.flys.artifacts.model.DataFacet;
14 import de.intevation.flys.artifacts.model.EmptyFacet;
15 import de.intevation.flys.artifacts.model.FacetTypes;
16 import de.intevation.flys.artifacts.model.ReportFacet;
17 import de.intevation.flys.artifacts.model.WQKms;
18 import de.intevation.flys.artifacts.model.WaterlevelFacet;
19
20 import de.intevation.flys.utils.FLYSUtils;
21
22 import java.util.List;
23
24 import org.apache.log4j.Logger;
25
26 public class WaterlevelState
27 extends DefaultState
28 implements FacetTypes
29 {
30 /** The logger that is used in this state. */
31 private static Logger logger = Logger.getLogger(WaterlevelState.class);
32
33
34 /**
35 * From this state can only be continued trivially.
36 */
37 @Override
38 protected String getUIProvider() {
39 return "continue";
40 }
41
42
43 /**
44 * Compute result or returned object from cache, create facets.
45 * @param old Object that was cached.
46 */
47 protected Object compute(
48 WINFOArtifact winfo,
49 CallContext cc,
50 String hash,
51 List<Facet> facets,
52 Object old
53 ) {
54 String id = getID();
55
56 CalculationResult res = old instanceof CalculationResult
57 ? (CalculationResult) old
58 : winfo.getWaterlevelData();
59
60 if (facets == null) {
61 return res;
62 }
63
64 boolean debug = logger.isDebugEnabled();
65
66 WQKms [] wqkms = (WQKms []) res.getData();
67
68 for (int i = 0; i < wqkms.length; i++) {
69 String name = wqkms[i].getName();
70
71 String nameW = FLYSUtils.createWspWTitle(winfo, cc, name);
72 String nameQ = FLYSUtils.createWspQTitle(winfo, cc, name);
73
74 // Hotfix for theme names. Themes with the same name cause problems
75 // aggregating chart legend items.
76 if (i > 0 && name.equals(wqkms[i - 1].getName())) {
77 nameW += "; Q=" + wqkms[i].get(0, new double[3])[1];
78 nameQ += " = " + wqkms[i].get(0, new double[3])[1];
79 }
80
81 if (debug) {
82 logger.debug("Create facet: " + nameW);
83 logger.debug("Create facet: " + nameQ);
84 }
85
86 Facet w = new WaterlevelFacet(
87 i, LONGITUDINAL_W, nameW, ComputeType.ADVANCE, id, hash);
88 Facet q = new WaterlevelFacet(
89 i, LONGITUDINAL_Q, nameQ, ComputeType.ADVANCE, id, hash);
90
91 facets.add(new CrossSectionWaterLineFacet(i, nameW));
92
93 facets.add(w);
94 facets.add(q);
95 }
96
97 if (wqkms.length > 0) {
98 Facet wst = new DataFacet(
99 WST, "WST data", ComputeType.ADVANCE, hash, id);
100 Facet csv = new DataFacet(
101 CSV, "CSV data", ComputeType.ADVANCE, hash, id);
102 Facet pdf = new DataFacet(
103 PDF, "PDF data", ComputeType.ADVANCE, hash, id);
104
105 facets.add(wst);
106 facets.add(csv);
107 facets.add(pdf);
108 }
109
110 if (res.getReport().hasProblems()) {
111 facets.add(new ReportFacet(ComputeType.ADVANCE, hash, id));
112 }
113
114 return res;
115 }
116
117
118 /**
119 * @param context Ignored.
120 */
121 @Override
122 public Object computeFeed(
123 FLYSArtifact artifact,
124 String hash,
125 CallContext context,
126 List<Facet> facets,
127 Object old
128 ) {
129 if (artifact instanceof ChartArtifact) {
130 ChartArtifact chart = (ChartArtifact)artifact;
131 facets.add(new EmptyFacet());
132 return null;
133 }
134 return compute((WINFOArtifact) artifact, context, hash, facets, old);
135 }
136
137
138 /**
139 * @param context Ignored.
140 */
141 @Override
142 public Object computeAdvance(
143 FLYSArtifact artifact,
144 String hash,
145 CallContext context,
146 List<Facet> facets,
147 Object old
148 ) {
149 if (artifact instanceof ChartArtifact) {
150 ChartArtifact chart = (ChartArtifact)artifact;
151 facets.add(new EmptyFacet());
152 return null;
153 }
154 return compute((WINFOArtifact) artifact, context, hash, facets, old);
155 }
156 }
157 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org