Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/DifferencesState.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/minfo/DifferencesState.java@c0d6391bec6f |
children |
comparison
equal
deleted
inserted
replaced
5830:160f53ee0870 | 5831:bd047b71ab37 |
---|---|
1 package org.dive4elements.river.artifacts.states.minfo; | |
2 | |
3 import java.text.DateFormat; | |
4 import java.util.ArrayList; | |
5 import java.util.List; | |
6 | |
7 import org.apache.log4j.Logger; | |
8 | |
9 import org.dive4elements.artifactdatabase.state.Facet; | |
10 import org.dive4elements.artifactdatabase.state.FacetActivity; | |
11 import org.dive4elements.artifacts.Artifact; | |
12 import org.dive4elements.artifacts.CallContext; | |
13 import org.dive4elements.artifacts.CallMeta; | |
14 import org.dive4elements.river.artifacts.FLYSArtifact; | |
15 import org.dive4elements.river.artifacts.access.BedDifferencesAccess; | |
16 import org.dive4elements.river.artifacts.model.CalculationResult; | |
17 import org.dive4elements.river.artifacts.model.FacetTypes; | |
18 import org.dive4elements.river.artifacts.model.minfo.BedDiffCalculation; | |
19 import org.dive4elements.river.artifacts.model.minfo.BedDiffEpochFacet; | |
20 import org.dive4elements.river.artifacts.model.minfo.BedDiffEpochFilterFacet; | |
21 import org.dive4elements.river.artifacts.model.minfo.BedDiffEpochResult; | |
22 import org.dive4elements.river.artifacts.model.minfo.BedDiffYearFacet; | |
23 import org.dive4elements.river.artifacts.model.minfo.BedDiffYearFilterFacet; | |
24 import org.dive4elements.river.artifacts.model.minfo.BedDiffYearResult; | |
25 import org.dive4elements.river.artifacts.model.minfo.BedDifferencesResult; | |
26 import org.dive4elements.river.artifacts.resources.Resources; | |
27 import org.dive4elements.river.artifacts.states.DefaultState; | |
28 import org.dive4elements.river.utils.Formatter; | |
29 | |
30 /** | |
31 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | |
32 */ | |
33 public class DifferencesState | |
34 extends DefaultState | |
35 implements FacetTypes | |
36 { | |
37 /** The logger used in this class. */ | |
38 private static Logger logger = Logger.getLogger(DifferencesState.class); | |
39 public static final String I18N_DIFF_YEAR = "beddifference.year"; | |
40 public static final String I18N_DIFF_EPOCH = "beddifference.epoch"; | |
41 | |
42 public static final String I18N_FACET_BED_DIFF_YEAR = "facet.bedheight.diff.year"; | |
43 public static final String I18N_FACET_BED_DIFF_YEAR_RAW = "facet.bedheight.diff.year.raw"; | |
44 public static final String I18N_FACET_BED_DIFF_ABSOLUTE = "facet.bedheight.diff.absolute"; | |
45 public static final String I18N_FACET_BED_DIFF_ABSOLUTE_RAW = "facet.bedheight.diff.absolute.raw"; | |
46 public static final String I18N_FACET_BED_DIFF_MORPH = "facet.bedheight.diff.morph"; | |
47 public static final String I18N_FACET_BED_DIFF_EPOCH = "facet.bedheight.diff.epoch"; | |
48 public static final String I18N_FACET_BED_DIFF_EPOCH_RAW = "facet.bedheight.diff.epoch.raw"; | |
49 public static final String I18N_FACET_BED_DIFF_HEIGHT1 = "facet.bedheight.diff.height1"; | |
50 public static final String I18N_FACET_BED_DIFF_HEIGHT1_RAW = "facet.bedheight.diff.height1.raw"; | |
51 public static final String I18N_FACET_BED_DIFF_HEIGHT2 = "facet.bedheight.diff.height2"; | |
52 public static final String I18N_FACET_BED_DIFF_HEIGHT2_RAW = "facet.bedheight.diff.height2.raw"; | |
53 | |
54 public DifferencesState() { | |
55 } | |
56 | |
57 @Override | |
58 public Object computeAdvance(FLYSArtifact artifact, String hash, | |
59 CallContext context, List<Facet> facets, Object old) { | |
60 logger.debug("BedQualityState.computeAdvance"); | |
61 | |
62 List<Facet> newFacets = new ArrayList<Facet>(); | |
63 | |
64 BedDifferencesAccess access = | |
65 new BedDifferencesAccess(artifact, context); | |
66 | |
67 CalculationResult res = old instanceof CalculationResult ? (CalculationResult) old | |
68 : new BedDiffCalculation().calculate(access); | |
69 | |
70 if (facets == null || res == null) { | |
71 return res; | |
72 } | |
73 | |
74 BedDifferencesResult[] results = (BedDifferencesResult[]) res.getData(); | |
75 | |
76 if (results == null || results.length == 0) { | |
77 logger.warn("Calculation computed no results!"); | |
78 return res; | |
79 } | |
80 | |
81 generateFacets(context, newFacets, results, getID(), hash); | |
82 logger.debug("Created " + newFacets.size() + " new Facets."); | |
83 | |
84 facets.addAll(newFacets); | |
85 | |
86 return res; | |
87 } | |
88 | |
89 protected void generateFacets(CallContext context, List<Facet> newFacets, | |
90 BedDifferencesResult[] results, String stateId, String hash) { | |
91 logger.debug("BedQualityState.generateFacets"); | |
92 | |
93 CallMeta meta = context.getMeta(); | |
94 | |
95 for (int idx = 0; idx < results.length; idx++) { | |
96 if (results[idx] instanceof BedDiffYearResult) { | |
97 newFacets.add(new BedDiffYearFacet( | |
98 idx, | |
99 BED_DIFFERENCE_YEAR, | |
100 createBedDiffYearDescription( | |
101 meta, | |
102 (BedDiffYearResult)results[idx], | |
103 true), | |
104 ComputeType.ADVANCE, | |
105 stateId, | |
106 hash)); | |
107 newFacets.add(new BedDiffYearFacet( | |
108 idx, | |
109 BED_DIFFERENCE_MORPH_WIDTH, | |
110 createBedDiffMorphDescription( | |
111 meta, | |
112 (BedDiffYearResult)results[idx]), | |
113 ComputeType.ADVANCE, | |
114 stateId, | |
115 hash)); | |
116 newFacets.add(new BedDiffYearFacet( | |
117 idx, | |
118 BED_DIFFERENCE_YEAR_HEIGHT1, | |
119 createBedDiffHeightDescription( | |
120 meta, | |
121 (BedDiffYearResult)results[idx], | |
122 0, | |
123 true), | |
124 ComputeType.ADVANCE, | |
125 stateId, | |
126 hash)); | |
127 newFacets.add(new BedDiffYearFacet( | |
128 idx, | |
129 BED_DIFFERENCE_YEAR_HEIGHT2, | |
130 createBedDiffHeightDescription( | |
131 meta, | |
132 (BedDiffYearResult)results[idx], | |
133 1, | |
134 true), | |
135 ComputeType.ADVANCE, | |
136 stateId, | |
137 hash)); | |
138 newFacets.add(new BedDiffYearFacet( | |
139 idx, | |
140 BED_DIFFERENCE_HEIGHT_YEAR, | |
141 createBedDiffAbsoluteDescription( | |
142 meta, | |
143 (BedDiffYearResult)results[idx], | |
144 true), | |
145 ComputeType.ADVANCE, | |
146 stateId, | |
147 hash)); | |
148 newFacets.add(new BedDiffYearFilterFacet( | |
149 idx, | |
150 BED_DIFFERENCE_YEAR_FILTERED, | |
151 createBedDiffYearDescription( | |
152 meta, | |
153 (BedDiffYearResult)results[idx], | |
154 false), | |
155 ComputeType.ADVANCE, | |
156 stateId, | |
157 hash)); | |
158 newFacets.add(new BedDiffYearFilterFacet( | |
159 idx, | |
160 BED_DIFFERENCE_YEAR_HEIGHT1_FILTERED, | |
161 createBedDiffHeightDescription( | |
162 meta, | |
163 (BedDiffYearResult)results[idx], | |
164 0, | |
165 false), | |
166 ComputeType.ADVANCE, | |
167 stateId, | |
168 hash)); | |
169 newFacets.add(new BedDiffYearFilterFacet( | |
170 idx, | |
171 BED_DIFFERENCE_YEAR_HEIGHT2_FILTERED, | |
172 createBedDiffHeightDescription( | |
173 meta, | |
174 (BedDiffYearResult)results[idx], | |
175 1, | |
176 false), | |
177 ComputeType.ADVANCE, | |
178 stateId, | |
179 hash)); | |
180 newFacets.add(new BedDiffYearFilterFacet( | |
181 idx, | |
182 BED_DIFFERENCE_HEIGHT_YEAR_FILTERED, | |
183 createBedDiffAbsoluteDescription( | |
184 meta, | |
185 (BedDiffYearResult)results[idx], | |
186 false), | |
187 ComputeType.ADVANCE, | |
188 stateId, | |
189 hash)); | |
190 } | |
191 if (results[idx] instanceof BedDiffEpochResult) { | |
192 newFacets.add(new BedDiffEpochFacet( | |
193 idx, | |
194 BED_DIFFERENCE_EPOCH, | |
195 createBedDiffEpochDescription( | |
196 meta, | |
197 (BedDiffEpochResult)results[idx], | |
198 true), | |
199 ComputeType.ADVANCE, | |
200 stateId, | |
201 hash)); | |
202 newFacets.add(new BedDiffEpochFacet( | |
203 idx, | |
204 BED_DIFFERENCE_EPOCH_HEIGHT1, | |
205 createBedDiffHeightEpochDescription( | |
206 meta, | |
207 (BedDiffEpochResult)results[idx], | |
208 0, | |
209 true), | |
210 ComputeType.ADVANCE, | |
211 stateId, | |
212 hash)); | |
213 newFacets.add(new BedDiffEpochFacet( | |
214 idx, | |
215 BED_DIFFERENCE_EPOCH_HEIGHT2, | |
216 createBedDiffHeightEpochDescription( | |
217 meta, | |
218 (BedDiffEpochResult)results[idx], | |
219 1, | |
220 true), | |
221 ComputeType.ADVANCE, | |
222 stateId, | |
223 hash)); | |
224 newFacets.add(new BedDiffEpochFilterFacet( | |
225 idx, | |
226 BED_DIFFERENCE_EPOCH_FILTERED, | |
227 createBedDiffEpochDescription( | |
228 meta, | |
229 (BedDiffEpochResult)results[idx], | |
230 false), | |
231 ComputeType.ADVANCE, | |
232 stateId, | |
233 hash)); | |
234 newFacets.add(new BedDiffEpochFilterFacet( | |
235 idx, | |
236 BED_DIFFERENCE_EPOCH_HEIGHT1_FILTERED, | |
237 createBedDiffHeightEpochDescription( | |
238 meta, | |
239 (BedDiffEpochResult)results[idx], | |
240 0, | |
241 false), | |
242 ComputeType.ADVANCE, | |
243 stateId, | |
244 hash)); | |
245 newFacets.add(new BedDiffEpochFilterFacet( | |
246 idx, | |
247 BED_DIFFERENCE_EPOCH_HEIGHT2_FILTERED, | |
248 createBedDiffHeightEpochDescription( | |
249 meta, | |
250 (BedDiffEpochResult)results[idx], | |
251 1, | |
252 false), | |
253 ComputeType.ADVANCE, | |
254 stateId, | |
255 hash)); | |
256 } | |
257 } | |
258 } | |
259 | |
260 private String createBedDiffHeightDescription( | |
261 CallMeta meta, | |
262 BedDiffYearResult result, | |
263 int ndx, | |
264 boolean raw | |
265 ) { | |
266 String range = result.getStart() + " - " + result.getEnd(); | |
267 | |
268 String i18nHeight1 = I18N_FACET_BED_DIFF_HEIGHT1; | |
269 String i18nHeight2 = I18N_FACET_BED_DIFF_HEIGHT2; | |
270 if (raw) { | |
271 i18nHeight1 = I18N_FACET_BED_DIFF_HEIGHT1_RAW; | |
272 i18nHeight2 = I18N_FACET_BED_DIFF_HEIGHT2_RAW; | |
273 } | |
274 if (ndx == 0) { | |
275 return Resources.getMsg(meta, i18nHeight1, | |
276 i18nHeight2, new Object[] { range }); | |
277 } | |
278 else { | |
279 return Resources.getMsg(meta, i18nHeight1, | |
280 i18nHeight2, new Object[] {range}); | |
281 } | |
282 } | |
283 | |
284 private String createBedDiffHeightEpochDescription( | |
285 CallMeta meta, | |
286 BedDiffEpochResult result, | |
287 int ndx, | |
288 boolean raw | |
289 ) { | |
290 DateFormat df = Formatter.getDateFormatter(meta, "yyyy"); | |
291 String range = | |
292 df.format(result.getStart()) | |
293 + " - " + | |
294 df.format(result.getEnd()); | |
295 | |
296 String i18nHeight1 = I18N_FACET_BED_DIFF_HEIGHT1; | |
297 String i18nHeight2 = I18N_FACET_BED_DIFF_HEIGHT2; | |
298 if (raw) { | |
299 i18nHeight1 = I18N_FACET_BED_DIFF_HEIGHT1_RAW; | |
300 i18nHeight2 = I18N_FACET_BED_DIFF_HEIGHT2_RAW; | |
301 } | |
302 if (ndx == 0) { | |
303 return Resources.getMsg(meta, i18nHeight1, | |
304 i18nHeight1, new Object[] { range }); | |
305 } | |
306 else { | |
307 return Resources.getMsg(meta, i18nHeight2, | |
308 i18nHeight2, new Object[] {range}); | |
309 } | |
310 } | |
311 | |
312 protected String createBedDiffYearDescription( | |
313 CallMeta meta, | |
314 BedDiffYearResult result, | |
315 boolean raw | |
316 ) { | |
317 String range = result.getStart() + " - " + result.getEnd(); | |
318 | |
319 String i18n = I18N_FACET_BED_DIFF_YEAR; | |
320 if (raw) { | |
321 i18n = I18N_FACET_BED_DIFF_YEAR_RAW; | |
322 } | |
323 return Resources.getMsg(meta, i18n, i18n, new Object[] { range }); | |
324 } | |
325 | |
326 protected String createBedDiffMorphDescription( | |
327 CallMeta meta, | |
328 BedDiffYearResult result) { | |
329 String range = result.getStart() + " - " + result.getEnd(); | |
330 | |
331 return Resources.getMsg(meta, I18N_FACET_BED_DIFF_MORPH, | |
332 I18N_FACET_BED_DIFF_MORPH, new Object[] { range }); | |
333 } | |
334 | |
335 protected String createBedDiffAbsoluteDescription( | |
336 CallMeta meta, | |
337 BedDiffYearResult result, | |
338 boolean raw | |
339 ) { | |
340 String range = result.getStart() + " - " + result.getEnd(); | |
341 | |
342 String i18n = I18N_FACET_BED_DIFF_ABSOLUTE; | |
343 if (raw) { | |
344 i18n = I18N_FACET_BED_DIFF_ABSOLUTE_RAW; | |
345 } | |
346 return Resources.getMsg(meta, i18n, i18n, new Object[] { range }); | |
347 } | |
348 | |
349 protected String createBedDiffEpochDescription( | |
350 CallMeta meta, | |
351 BedDiffEpochResult result, | |
352 boolean raw) { | |
353 DateFormat df = Formatter.getDateFormatter(meta, "yyyy"); | |
354 String range = | |
355 df.format(result.getStart()) | |
356 + " - " + | |
357 df.format(result.getEnd()); | |
358 | |
359 String i18n = I18N_FACET_BED_DIFF_EPOCH; | |
360 if (raw) { | |
361 i18n = I18N_FACET_BED_DIFF_EPOCH_RAW; | |
362 } | |
363 return Resources.getMsg(meta, i18n, i18n, new Object[] { range }); | |
364 } | |
365 | |
366 static { | |
367 // Active/deactivate facets. | |
368 FacetActivity.Registry.getInstance().register( | |
369 "minfo", | |
370 new FacetActivity() { | |
371 @Override | |
372 public Boolean isInitialActive( | |
373 Artifact artifact, | |
374 Facet facet, | |
375 String output | |
376 ) { | |
377 String name = facet.getName(); | |
378 if (name.equals(BED_DIFFERENCE_EPOCH) || | |
379 name.equals(BED_DIFFERENCE_EPOCH_HEIGHT1) || | |
380 name.equals(BED_DIFFERENCE_EPOCH_HEIGHT2) || | |
381 name.equals(BED_DIFFERENCE_HEIGHT_YEAR) || | |
382 name.equals(BED_DIFFERENCE_YEAR) || | |
383 name.equals(BED_DIFFERENCE_YEAR_HEIGHT1) || | |
384 name.equals(BED_DIFFERENCE_YEAR_HEIGHT2)) { | |
385 return Boolean.FALSE; | |
386 } | |
387 else if (name.equals(BED_DIFFERENCE_MORPH_WIDTH) || | |
388 name.equals(BED_DIFFERENCE_EPOCH_FILTERED) || | |
389 name.equals(BED_DIFFERENCE_EPOCH_HEIGHT1_FILTERED) || | |
390 name.equals(BED_DIFFERENCE_EPOCH_HEIGHT2_FILTERED) || | |
391 name.equals(BED_DIFFERENCE_HEIGHT_YEAR_FILTERED) || | |
392 name.equals(BED_DIFFERENCE_YEAR_FILTERED) || | |
393 name.equals(BED_DIFFERENCE_YEAR_HEIGHT1_FILTERED) || | |
394 name.equals(BED_DIFFERENCE_YEAR_HEIGHT2_FILTERED)){ | |
395 return Boolean.TRUE; | |
396 } | |
397 else { | |
398 return null; | |
399 } | |
400 } | |
401 }); | |
402 } | |
403 } |