comparison flys-artifacts/src/main/java/org/dive4elements/river/artifacts/states/FlowVelocityState.java @ 5831:bd047b71ab37

Repaired internal references
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 12:06:39 +0200
parents flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/FlowVelocityState.java@a3dc382bc1ca
children
comparison
equal deleted inserted replaced
5830:160f53ee0870 5831:bd047b71ab37
1 package org.dive4elements.river.artifacts.states;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import org.apache.log4j.Logger;
7
8 import org.dive4elements.artifactdatabase.state.Facet;
9 import org.dive4elements.artifactdatabase.state.FacetActivity;
10
11 import org.dive4elements.artifacts.Artifact;
12 import org.dive4elements.artifacts.CallContext;
13
14 import org.dive4elements.river.artifacts.FLYSArtifact;
15 import org.dive4elements.river.artifacts.access.FlowVelocityAccess;
16 import org.dive4elements.river.artifacts.model.CalculationResult;
17 import org.dive4elements.river.artifacts.model.DataFacet;
18 import org.dive4elements.river.artifacts.model.FacetTypes;
19 import org.dive4elements.river.artifacts.model.FlowVelocityCalculation;
20 import org.dive4elements.river.artifacts.model.FlowVelocityData;
21 import org.dive4elements.river.artifacts.model.FlowVelocityFacet;
22 import org.dive4elements.river.artifacts.model.FlowVelocityFilterFacet;
23 import org.dive4elements.river.artifacts.resources.Resources;
24
25
26 /* State in which flow velocities can/will be calculated. */
27 public class FlowVelocityState extends DefaultState implements FacetTypes {
28
29 private static Logger logger = Logger.getLogger(FlowVelocityState.class);
30
31 public static final String I18N_MAINCHANNEL_FACET =
32 "facet.flow_velocity.mainchannel";
33
34 public static final String I18N_TOTALCHANNEL_FACET =
35 "facet.flow_velocity.totalchannel";
36
37 public static final String I18N_TAU_FACET =
38 "facet.flow_velocity.tauchannel";
39
40 public static final String I18N_MAINCHANNEL_FACET_RAW =
41 "facet.flow_velocity.mainchannel.raw";
42
43 public static final String I18N_TOTALCHANNEL_FACET_RAW =
44 "facet.flow_velocity.totalchannel.raw";
45
46 public static final String I18N_TAU_FACET_RAW =
47 "facet.flow_velocity.tauchannel.raw";
48
49 public static final String I18N_DISCHARGE_FACET =
50 "facet.flow_velocity.discharge";
51
52
53 @Override
54 public Object computeAdvance(
55 FLYSArtifact artifact,
56 String hash,
57 CallContext context,
58 List<Facet> facets,
59 Object old
60 ) {
61 logger.debug("FlowVelocityState.computeAdvance");
62
63 List<Facet> newFacets = new ArrayList<Facet>();
64
65 FlowVelocityAccess access = new FlowVelocityAccess(artifact, context);
66
67 CalculationResult res = old instanceof CalculationResult
68 ? (CalculationResult) old
69 : new FlowVelocityCalculation().calculate(access);
70
71 if (facets == null || res == null) {
72 return res;
73 }
74
75 FlowVelocityData[] data = (FlowVelocityData[]) res.getData();
76
77 logger.debug("Calculated " + data.length + " FlowVelocityData objects");
78
79 String id = getID();
80 int idx = 0;
81
82 for (FlowVelocityData d: data) {
83 if (d.getType().equals("main")) {
84 newFacets.add(new FlowVelocityFacet(
85 idx,
86 FLOW_VELOCITY_MAINCHANNEL,
87 buildFacetName(artifact, context, d, I18N_MAINCHANNEL_FACET_RAW),
88 ComputeType.ADVANCE,
89 id,
90 hash
91 ));
92
93 newFacets.add(new FlowVelocityFacet(
94 idx,
95 FLOW_VELOCITY_TAU,
96 buildFacetName(artifact, context, d, I18N_TAU_FACET_RAW),
97 ComputeType.ADVANCE,
98 id,
99 hash
100 ));
101 newFacets.add(new FlowVelocityFilterFacet(
102 idx,
103 FLOW_VELOCITY_MAINCHANNEL_FILTERED,
104 buildMainChannelName(artifact, context, d),
105 ComputeType.ADVANCE,
106 id,
107 hash
108 ));
109 newFacets.add(new FlowVelocityFilterFacet(
110 idx,
111 FLOW_VELOCITY_TAU_FILTERED,
112 buildTauName(artifact, context, d),
113 ComputeType.ADVANCE,
114 id,
115 hash
116 ));
117 }
118 else if (d.getType().equals("total")) {
119 newFacets.add(new FlowVelocityFacet(
120 idx,
121 FLOW_VELOCITY_TOTALCHANNEL,
122 buildFacetName(artifact, context, d, I18N_TOTALCHANNEL_FACET_RAW),
123 ComputeType.ADVANCE,
124 id,
125 hash
126 ));
127 newFacets.add(new FlowVelocityFilterFacet(
128 idx,
129 FLOW_VELOCITY_TOTALCHANNEL_FILTERED,
130 buildTotalChannelName(artifact, context, d),
131 ComputeType.ADVANCE,
132 id,
133 hash
134 ));
135
136 }
137 else if(d.getType().equals("main_total")) {
138 newFacets.add(new FlowVelocityFacet(
139 idx,
140 FLOW_VELOCITY_MAINCHANNEL,
141 buildFacetName(artifact, context, d, I18N_MAINCHANNEL_FACET_RAW),
142 ComputeType.ADVANCE,
143 id,
144 hash
145 ));
146 newFacets.add(new FlowVelocityFacet(
147 idx,
148 FLOW_VELOCITY_TAU,
149 buildFacetName(artifact, context, d, I18N_TAU_FACET_RAW),
150 ComputeType.ADVANCE,
151 id,
152 hash
153 ));
154 newFacets.add(new FlowVelocityFacet(
155 idx,
156 FLOW_VELOCITY_TOTALCHANNEL,
157 buildFacetName(artifact, context, d, I18N_TOTALCHANNEL_FACET_RAW),
158 ComputeType.ADVANCE,
159 id,
160 hash
161 ));
162 newFacets.add(new FlowVelocityFilterFacet(
163 idx,
164 FLOW_VELOCITY_MAINCHANNEL_FILTERED,
165 buildMainChannelName(artifact, context, d),
166 ComputeType.ADVANCE,
167 id,
168 hash
169 ));
170 newFacets.add(new FlowVelocityFilterFacet(
171 idx,
172 FLOW_VELOCITY_TAU_FILTERED,
173 buildTauName(artifact, context, d),
174 ComputeType.ADVANCE,
175 id,
176 hash
177 ));
178 newFacets.add(new FlowVelocityFilterFacet(
179 idx,
180 FLOW_VELOCITY_TOTALCHANNEL_FILTERED,
181 buildTotalChannelName(artifact, context, d),
182 ComputeType.ADVANCE,
183 id,
184 hash
185 ));
186 }
187
188 newFacets.add(new FlowVelocityFacet(
189 idx,
190 FLOW_VELOCITY_DISCHARGE,
191 buildDischargeName(artifact, context, d),
192 ComputeType.ADVANCE,
193 id,
194 hash
195 ));
196
197 idx++;
198 }
199
200 Facet csv = new DataFacet(
201 CSV, "CSV data", ComputeType.ADVANCE, hash, id);
202
203 // TODO ADD PDF FACET
204
205 newFacets.add(csv);
206
207 logger.debug("Created " + newFacets.size() + " new Facets.");
208
209 facets.addAll(newFacets);
210
211 return res;
212 }
213
214
215 protected String buildFacetName(
216 FLYSArtifact flys,
217 CallContext cc,
218 FlowVelocityData data,
219 String resourceId
220 ) {
221 Object[] args = new Object[] {
222 data.getZone()
223 };
224
225 return Resources.getMsg(
226 cc.getMeta(),
227 resourceId,
228 resourceId,
229 args);
230 }
231
232
233 protected String buildMainChannelName(
234 FLYSArtifact flys,
235 CallContext cc,
236 FlowVelocityData data
237 ) {
238 return buildFacetName(flys, cc, data, I18N_MAINCHANNEL_FACET);
239 }
240
241
242 protected String buildTotalChannelName(
243 FLYSArtifact flys,
244 CallContext cc,
245 FlowVelocityData data
246 ) {
247 return buildFacetName(flys, cc, data, I18N_TOTALCHANNEL_FACET);
248 }
249
250
251 protected String buildDischargeName(
252 FLYSArtifact flys,
253 CallContext cc,
254 FlowVelocityData data
255 ) {
256 return buildFacetName(flys, cc, data, I18N_DISCHARGE_FACET);
257 }
258
259 protected String buildTauName(
260 FLYSArtifact flys,
261 CallContext cc,
262 FlowVelocityData data
263 ) {
264 return buildFacetName(flys, cc, data, I18N_TAU_FACET);
265 }
266
267 static {
268 // Active/deactivate facets.
269 FacetActivity.Registry.getInstance().register(
270 "minfo",
271 new FacetActivity() {
272 @Override
273 public Boolean isInitialActive(
274 Artifact artifact,
275 Facet facet,
276 String output
277 ) {
278 String name = facet.getName();
279 if (name.equals(FLOW_VELOCITY_MAINCHANNEL_FILTERED) ||
280 name.equals(FLOW_VELOCITY_TAU_FILTERED) ||
281 name.equals(FLOW_VELOCITY_DISCHARGE) ||
282 name.equals(FLOW_VELOCITY_TOTALCHANNEL_FILTERED)) {
283 return Boolean.TRUE;
284 }
285 else if (name.equals(FLOW_VELOCITY_MAINCHANNEL) ||
286 name.equals(FLOW_VELOCITY_TAU) ||
287 name.equals(FLOW_VELOCITY_TOTALCHANNEL)) {
288 return Boolean.FALSE;
289 }
290 else {
291 return null;
292 }
293 }
294 });
295 }
296 }
297 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org