Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/SedimentLoadCalculate.java @ 5838:5aa05a7a34b7
Rename modules to more fitting names.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 15:23:37 +0200 |
parents | flys-artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/SedimentLoadCalculate.java@bd047b71ab37 |
children | 4897a58c8746 |
comparison
equal
deleted
inserted
replaced
5837:d9901a08d0a6 | 5838:5aa05a7a34b7 |
---|---|
1 package org.dive4elements.river.artifacts.states.minfo; | |
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.artifacts.CallContext; | |
10 import org.dive4elements.artifacts.CallMeta; | |
11 import org.dive4elements.river.artifacts.FLYSArtifact; | |
12 import org.dive4elements.river.artifacts.access.SedimentLoadAccess; | |
13 import org.dive4elements.river.artifacts.model.CalculationResult; | |
14 import org.dive4elements.river.artifacts.model.DataFacet; | |
15 import org.dive4elements.river.artifacts.model.FacetTypes; | |
16 import org.dive4elements.river.artifacts.model.ReportFacet; | |
17 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadCalculation; | |
18 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadFacet; | |
19 import org.dive4elements.river.artifacts.model.minfo.SedimentLoadResult; | |
20 import org.dive4elements.river.artifacts.resources.Resources; | |
21 import org.dive4elements.river.artifacts.states.DefaultState; | |
22 | |
23 | |
24 public class SedimentLoadCalculate | |
25 extends DefaultState | |
26 implements FacetTypes | |
27 { | |
28 | |
29 private static final long serialVersionUID = 1L; | |
30 | |
31 private static final Logger logger = Logger | |
32 .getLogger(SedimentLoadCalculate.class); | |
33 | |
34 public static final String I18N_FACET_SEDIMENTLOAD_COARSE = "facet.sedimentload.coarse"; | |
35 public static final String I18N_FACET_SEDIMENTLOAD_SAND = "facet.sedimentload.sand"; | |
36 public static final String I18N_FACET_SEDIMENTLOAD_FINE_MIDDLE = "facet.sedimentload.fine_middle"; | |
37 public static final String I18N_FACET_SEDIMENTLOAD_SUSPSAND = "facet.sedimentload.susp_sand"; | |
38 public static final String I18N_FACET_SEDIMENTLOAD_SUSPSANDBED = "facet.sediemntload.susp_sand_bed"; | |
39 public static final String I18N_FACET_SEDIMENTLOAD_SUSPSEDIMENT = "facet.sedimentload.susp_sediment"; | |
40 public static final String I18N_FACET_SEDIMENTLOAD_TOTAL_LOAD = "facet.sedimentload.total_load"; | |
41 public static final String I18N_FACET_SEDIMENTLOAD_TOTAL = "facet.sedimentload.total"; | |
42 | |
43 @Override | |
44 public Object computeAdvance(FLYSArtifact artifact, String hash, | |
45 CallContext context, List<Facet> facets, Object old) { | |
46 logger.debug("SedimentLoadCalculate.computeAdvance"); | |
47 | |
48 List<Facet> newFacets = new ArrayList<Facet>(); | |
49 | |
50 SedimentLoadAccess access = new SedimentLoadAccess(artifact, context); | |
51 | |
52 CalculationResult res = old instanceof CalculationResult ? (CalculationResult) old | |
53 : new SedimentLoadCalculation().calculate(access); | |
54 | |
55 if (facets == null || res == null) { | |
56 return res; | |
57 } | |
58 | |
59 SedimentLoadResult[] results = (SedimentLoadResult[]) res.getData(); | |
60 | |
61 if (results == null || results.length == 0) { | |
62 logger.warn("Calculation computed no results!"); | |
63 return res; | |
64 } | |
65 | |
66 String type = access.getYearEpoch(); | |
67 if (type.equals("year")) { | |
68 generateYearFacets(context, newFacets, results, getID(), hash); | |
69 } | |
70 else if (type.equals("epoch")) { | |
71 generateEpochFacets(context, newFacets, results, getID(), hash); | |
72 } | |
73 else if (type.equals("off_epoch")) { | |
74 generateOffEpochFacets(context, newFacets, results, getID(), hash); | |
75 } | |
76 logger.debug("Created " + newFacets.size() + " new Facets."); | |
77 if (res.getReport().hasProblems()) { | |
78 newFacets.add(new ReportFacet(ComputeType.ADVANCE, hash, id)); | |
79 } | |
80 facets.addAll(newFacets); | |
81 | |
82 return res; | |
83 } | |
84 | |
85 protected void generateYearFacets(CallContext context, List<Facet> newFacets, | |
86 SedimentLoadResult[] results, String stateId, String hash) { | |
87 logger.debug("SedimentLoadCalculate.generateFacets"); | |
88 | |
89 CallMeta meta = context.getMeta(); | |
90 | |
91 // newFacets.add(new DataFacet(CSV, "CSV data", ComputeType.ADVANCE, hash, id)); | |
92 for (int idx = 0; idx < results.length; idx++) { | |
93 SedimentLoadResult res = results[idx]; | |
94 if (res.hasCoarseData()) { | |
95 newFacets.add(new SedimentLoadFacet( | |
96 idx, | |
97 SEDIMENT_LOAD_COARSE, | |
98 Resources.getMsg( | |
99 meta, | |
100 I18N_FACET_SEDIMENTLOAD_COARSE, | |
101 I18N_FACET_SEDIMENTLOAD_COARSE) + | |
102 " - " + res.getStartYear(), | |
103 ComputeType.ADVANCE, | |
104 stateId, | |
105 hash)); | |
106 } | |
107 if (res.hasSandData()) { | |
108 newFacets.add(new SedimentLoadFacet( | |
109 idx, | |
110 SEDIMENT_LOAD_SAND, | |
111 Resources.getMsg( | |
112 meta, | |
113 I18N_FACET_SEDIMENTLOAD_SAND, | |
114 I18N_FACET_SEDIMENTLOAD_SAND) + | |
115 " - " + res.getStartYear(), | |
116 ComputeType.ADVANCE, | |
117 stateId, | |
118 hash)); | |
119 } | |
120 if (res.hasFineMiddleData()) { | |
121 newFacets.add(new SedimentLoadFacet( | |
122 idx, | |
123 SEDIMENT_LOAD_FINEMIDDLE, | |
124 Resources.getMsg( | |
125 meta, | |
126 I18N_FACET_SEDIMENTLOAD_FINE_MIDDLE, | |
127 I18N_FACET_SEDIMENTLOAD_FINE_MIDDLE) + | |
128 " - " + res.getStartYear(), | |
129 ComputeType.ADVANCE, | |
130 stateId, | |
131 hash)); | |
132 } | |
133 if (res.hasSuspSandData()) { | |
134 newFacets.add(new SedimentLoadFacet( | |
135 idx, | |
136 SEDIMENT_LOAD_SUSP_SAND, | |
137 Resources.getMsg( | |
138 meta, | |
139 I18N_FACET_SEDIMENTLOAD_SUSPSAND, | |
140 I18N_FACET_SEDIMENTLOAD_SUSPSAND) | |
141 + " - " + res.getStartYear(), | |
142 ComputeType.ADVANCE, | |
143 stateId, | |
144 hash)); | |
145 } | |
146 if (res.hasSuspSandBedData()) { | |
147 newFacets.add(new SedimentLoadFacet( | |
148 idx, | |
149 SEDIMENT_LOAD_SUSP_SAND_BED, | |
150 Resources.getMsg( | |
151 meta, | |
152 I18N_FACET_SEDIMENTLOAD_SUSPSANDBED, | |
153 I18N_FACET_SEDIMENTLOAD_SUSPSANDBED) + | |
154 " - " + res.getStartYear(), | |
155 ComputeType.ADVANCE, | |
156 stateId, | |
157 hash)); | |
158 } | |
159 if (res.hasSuspSedimentData()) { | |
160 newFacets.add(new SedimentLoadFacet( | |
161 idx, | |
162 SEDIMENT_LOAD_SUSP_SEDIMENT, | |
163 Resources.getMsg( | |
164 meta, | |
165 I18N_FACET_SEDIMENTLOAD_SUSPSEDIMENT, | |
166 I18N_FACET_SEDIMENTLOAD_SUSPSEDIMENT) + | |
167 " - " + res.getStartYear(), | |
168 ComputeType.ADVANCE, | |
169 stateId, | |
170 hash)); | |
171 | |
172 } | |
173 if (res.hasTotalData()) { | |
174 newFacets.add(new SedimentLoadFacet( | |
175 idx, | |
176 SEDIMENT_LOAD_TOTAL, | |
177 Resources.getMsg( | |
178 meta, | |
179 I18N_FACET_SEDIMENTLOAD_TOTAL, | |
180 I18N_FACET_SEDIMENTLOAD_TOTAL) + | |
181 " - " + res.getStartYear(), | |
182 ComputeType.ADVANCE, | |
183 stateId, | |
184 hash)); | |
185 } | |
186 } | |
187 } | |
188 | |
189 protected void generateEpochFacets( | |
190 CallContext context, | |
191 List<Facet> newFacets, | |
192 SedimentLoadResult[] results, | |
193 String stateId, | |
194 String hash | |
195 ) { | |
196 logger.debug("SedimentLoadCalculate.generateEpochFacets"); | |
197 | |
198 CallMeta meta = context.getMeta(); | |
199 | |
200 // newFacets.add(new DataFacet(CSV, "CSV data", ComputeType.ADVANCE, hash, id)); | |
201 for (int idx = 0; idx < results.length; idx++) { | |
202 SedimentLoadResult res = results[idx]; | |
203 if (res.hasCoarseData()) { | |
204 newFacets.add(new SedimentLoadFacet( | |
205 idx, | |
206 SEDIMENT_LOAD_COARSE, | |
207 Resources.getMsg( | |
208 meta, | |
209 I18N_FACET_SEDIMENTLOAD_COARSE, | |
210 I18N_FACET_SEDIMENTLOAD_COARSE) + | |
211 " - " + res.getStartYear() + "-" + res.getEndYear(), | |
212 ComputeType.ADVANCE, | |
213 stateId, | |
214 hash)); | |
215 } | |
216 if (res.hasSandData()) { | |
217 newFacets.add(new SedimentLoadFacet( | |
218 idx, | |
219 SEDIMENT_LOAD_SAND, | |
220 Resources.getMsg( | |
221 meta, | |
222 I18N_FACET_SEDIMENTLOAD_SAND, | |
223 I18N_FACET_SEDIMENTLOAD_SAND) + | |
224 " - " + res.getStartYear() + "-" + res.getEndYear(), | |
225 ComputeType.ADVANCE, | |
226 stateId, | |
227 hash)); | |
228 } | |
229 if (res.hasFineMiddleData()) { | |
230 newFacets.add(new SedimentLoadFacet( | |
231 idx, | |
232 SEDIMENT_LOAD_FINEMIDDLE, | |
233 Resources.getMsg( | |
234 meta, | |
235 I18N_FACET_SEDIMENTLOAD_FINE_MIDDLE, | |
236 I18N_FACET_SEDIMENTLOAD_FINE_MIDDLE) + | |
237 " - " + res.getStartYear(), | |
238 ComputeType.ADVANCE, | |
239 stateId, | |
240 hash)); | |
241 } | |
242 if (res.hasSuspSandData()) { | |
243 newFacets.add(new SedimentLoadFacet( | |
244 idx, | |
245 SEDIMENT_LOAD_SUSP_SAND, | |
246 Resources.getMsg( | |
247 meta, | |
248 I18N_FACET_SEDIMENTLOAD_SUSPSAND, | |
249 I18N_FACET_SEDIMENTLOAD_SUSPSAND) | |
250 + " - " + res.getStartYear() + "-" + res.getEndYear(), | |
251 ComputeType.ADVANCE, | |
252 stateId, | |
253 hash)); | |
254 } | |
255 if (res.hasSuspSandBedData()) { | |
256 newFacets.add(new SedimentLoadFacet( | |
257 idx, | |
258 SEDIMENT_LOAD_SUSP_SAND_BED, | |
259 Resources.getMsg( | |
260 meta, | |
261 I18N_FACET_SEDIMENTLOAD_SUSPSANDBED, | |
262 I18N_FACET_SEDIMENTLOAD_SUSPSANDBED) + | |
263 " - " + res.getStartYear() + "-" + res.getEndYear(), | |
264 ComputeType.ADVANCE, | |
265 stateId, | |
266 hash)); | |
267 } | |
268 if (res.hasSuspSedimentData()) { | |
269 newFacets.add(new SedimentLoadFacet( | |
270 idx, | |
271 SEDIMENT_LOAD_SUSP_SEDIMENT, | |
272 Resources.getMsg( | |
273 meta, | |
274 I18N_FACET_SEDIMENTLOAD_SUSPSEDIMENT, | |
275 I18N_FACET_SEDIMENTLOAD_SUSPSEDIMENT) + | |
276 " - " + res.getStartYear() + "-" + res.getEndYear(), | |
277 ComputeType.ADVANCE, | |
278 stateId, | |
279 hash)); | |
280 | |
281 } | |
282 if (res.hasTotalLoadData()) { | |
283 newFacets.add(new SedimentLoadFacet( | |
284 idx, | |
285 SEDIMENT_LOAD_TOTAL_LOAD, | |
286 Resources.getMsg( | |
287 meta, | |
288 I18N_FACET_SEDIMENTLOAD_TOTAL_LOAD, | |
289 I18N_FACET_SEDIMENTLOAD_TOTAL_LOAD) + | |
290 " - " + res.getStartYear() + "-" + res.getEndYear(), | |
291 ComputeType.ADVANCE, | |
292 stateId, | |
293 hash)); | |
294 } | |
295 if (res.hasTotalData()) { | |
296 newFacets.add(new SedimentLoadFacet( | |
297 idx, | |
298 SEDIMENT_LOAD_TOTAL, | |
299 Resources.getMsg( | |
300 meta, | |
301 I18N_FACET_SEDIMENTLOAD_TOTAL, | |
302 I18N_FACET_SEDIMENTLOAD_TOTAL) + | |
303 " - " + res.getStartYear() + "-" + res.getEndYear(), | |
304 ComputeType.ADVANCE, | |
305 stateId, | |
306 hash)); | |
307 } | |
308 } | |
309 } | |
310 | |
311 protected void generateOffEpochFacets( | |
312 CallContext context, | |
313 List<Facet> newFacets, | |
314 SedimentLoadResult[] results, | |
315 String stateId, | |
316 String hash | |
317 ) { | |
318 logger.debug("SedimentLoadCalculate.generateOffEpochFacets"); | |
319 | |
320 CallMeta meta = context.getMeta(); | |
321 | |
322 // newFacets.add(new DataFacet(CSV, "CSV data", ComputeType.ADVANCE, hash, id)); | |
323 for (int idx = 0; idx < results.length; idx++) { | |
324 SedimentLoadResult res = results[idx]; | |
325 if (res.hasCoarseData()) { | |
326 newFacets.add(new SedimentLoadFacet( | |
327 idx, | |
328 SEDIMENT_LOAD_COARSE, | |
329 Resources.getMsg( | |
330 meta, | |
331 I18N_FACET_SEDIMENTLOAD_COARSE, | |
332 I18N_FACET_SEDIMENTLOAD_COARSE) + | |
333 " - " + res.getStartYear() + "-" + res.getEndYear(), | |
334 ComputeType.ADVANCE, | |
335 stateId, | |
336 hash)); | |
337 } | |
338 if (res.hasSandData()) { | |
339 newFacets.add(new SedimentLoadFacet( | |
340 idx, | |
341 SEDIMENT_LOAD_SAND, | |
342 Resources.getMsg( | |
343 meta, | |
344 I18N_FACET_SEDIMENTLOAD_SAND, | |
345 I18N_FACET_SEDIMENTLOAD_SAND) + | |
346 " - " + res.getStartYear() + "-" + res.getEndYear(), | |
347 ComputeType.ADVANCE, | |
348 stateId, | |
349 hash)); | |
350 } | |
351 if (res.hasFineMiddleData()) { | |
352 newFacets.add(new SedimentLoadFacet( | |
353 idx, | |
354 SEDIMENT_LOAD_FINEMIDDLE, | |
355 Resources.getMsg( | |
356 meta, | |
357 I18N_FACET_SEDIMENTLOAD_FINE_MIDDLE, | |
358 I18N_FACET_SEDIMENTLOAD_FINE_MIDDLE) + | |
359 " - " + res.getStartYear() + "-" + res.getEndYear(), | |
360 ComputeType.ADVANCE, | |
361 stateId, | |
362 hash)); | |
363 } | |
364 if (res.hasSuspSandData()) { | |
365 newFacets.add(new SedimentLoadFacet( | |
366 idx, | |
367 SEDIMENT_LOAD_SUSP_SAND, | |
368 Resources.getMsg( | |
369 meta, | |
370 I18N_FACET_SEDIMENTLOAD_SUSPSAND, | |
371 I18N_FACET_SEDIMENTLOAD_SUSPSAND) + | |
372 " - " + res.getStartYear() + "-" + res.getEndYear(), | |
373 ComputeType.ADVANCE, | |
374 stateId, | |
375 hash)); | |
376 } | |
377 if (res.hasSuspSandBedData()) { | |
378 newFacets.add(new SedimentLoadFacet( | |
379 idx, | |
380 SEDIMENT_LOAD_SUSP_SAND_BED, | |
381 Resources.getMsg( | |
382 meta, | |
383 I18N_FACET_SEDIMENTLOAD_SUSPSANDBED, | |
384 I18N_FACET_SEDIMENTLOAD_SUSPSANDBED) + | |
385 " - " + res.getStartYear() + "-" + res.getEndYear(), | |
386 ComputeType.ADVANCE, | |
387 stateId, | |
388 hash)); | |
389 } | |
390 if (res.hasSuspSedimentData()) { | |
391 newFacets.add(new SedimentLoadFacet( | |
392 idx, | |
393 SEDIMENT_LOAD_SUSP_SEDIMENT, | |
394 Resources.getMsg( | |
395 meta, | |
396 I18N_FACET_SEDIMENTLOAD_SUSPSEDIMENT, | |
397 I18N_FACET_SEDIMENTLOAD_SUSPSEDIMENT) + | |
398 " - " + res.getStartYear() + "-" + res.getEndYear(), | |
399 ComputeType.ADVANCE, | |
400 stateId, | |
401 hash)); | |
402 | |
403 } | |
404 if (res.hasTotalLoadData()) { | |
405 newFacets.add(new SedimentLoadFacet( | |
406 idx, | |
407 SEDIMENT_LOAD_TOTAL_LOAD, | |
408 Resources.getMsg( | |
409 meta, | |
410 I18N_FACET_SEDIMENTLOAD_TOTAL_LOAD, | |
411 I18N_FACET_SEDIMENTLOAD_TOTAL_LOAD) + | |
412 " - " + res.getStartYear() + "-" + res.getEndYear(), | |
413 ComputeType.ADVANCE, | |
414 stateId, | |
415 hash)); | |
416 } | |
417 if (res.hasTotalData()) { | |
418 newFacets.add(new SedimentLoadFacet( | |
419 idx, | |
420 SEDIMENT_LOAD_TOTAL, | |
421 Resources.getMsg( | |
422 meta, | |
423 I18N_FACET_SEDIMENTLOAD_TOTAL, | |
424 I18N_FACET_SEDIMENTLOAD_TOTAL) + | |
425 " - " + res.getStartYear() + "-" + res.getEndYear(), | |
426 ComputeType.ADVANCE, | |
427 stateId, | |
428 hash)); | |
429 } | |
430 } | |
431 } | |
432 } |