8854
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
|
2 * Software engineering by Intevation GmbH |
|
3 * |
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
|
6 * documentation coming with Dive4Elements River for details. |
|
7 */ |
|
8 |
|
9 package org.dive4elements.river.artifacts.sinfo.flowdepth; |
|
10 |
|
11 import java.util.List; |
|
12 |
|
13 import org.dive4elements.artifactdatabase.state.Facet; |
|
14 import org.dive4elements.artifacts.CallContext; |
|
15 import org.dive4elements.river.artifacts.ChartArtifact; |
|
16 import org.dive4elements.river.artifacts.D4EArtifact; |
|
17 import org.dive4elements.river.artifacts.model.Calculation; |
|
18 import org.dive4elements.river.artifacts.model.CalculationResult; |
|
19 import org.dive4elements.river.artifacts.model.DataFacet; |
|
20 import org.dive4elements.river.artifacts.model.EmptyFacet; |
|
21 import org.dive4elements.river.artifacts.model.FacetTypes; |
|
22 import org.dive4elements.river.artifacts.model.ReportFacet; |
|
23 import org.dive4elements.river.artifacts.resources.Resources; |
|
24 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact; |
|
25 import org.dive4elements.river.artifacts.states.DefaultState; |
|
26 |
|
27 /** State in which a waterlevel has been calculated. */ |
|
28 public class FlowDepthState |
|
29 extends DefaultState |
|
30 { |
|
31 /// ** The log that is used in this state. */ |
|
32 // private static Logger log = Logger.getLogger(FlowDepthState.class); |
|
33 |
8877
|
34 private static final long serialVersionUID = 1L; |
|
35 |
8854
|
36 private static final String I18N_FACET_FLOW_DEPTH_FILTERED_DESCRIPTION = "sinfo.facet.flow_depth.filtered.description"; |
|
37 |
|
38 /** |
|
39 * From this state can only be continued trivially. |
|
40 */ |
|
41 @Override |
|
42 protected String getUIProvider() { |
|
43 return "continue"; |
|
44 } |
|
45 |
|
46 @Override |
|
47 public Object computeFeed( |
|
48 final D4EArtifact artifact, |
|
49 final String hash, |
|
50 final CallContext context, |
|
51 final List<Facet> facets, |
|
52 final Object old |
|
53 ) { |
|
54 // FIXME: why is this necessary? |
|
55 if (artifact instanceof ChartArtifact) { |
|
56 facets.add(new EmptyFacet()); |
|
57 return null; |
|
58 } |
|
59 return compute((SINFOArtifact) artifact, context, hash, facets, old); |
|
60 } |
|
61 |
|
62 @Override |
|
63 public Object computeAdvance( |
|
64 final D4EArtifact artifact, |
|
65 final String hash, |
|
66 final CallContext context, |
|
67 final List<Facet> facets, |
|
68 final Object old |
|
69 ) { |
|
70 if (artifact instanceof ChartArtifact) { |
|
71 facets.add(new EmptyFacet()); |
|
72 return null; |
|
73 } |
|
74 return compute((SINFOArtifact) artifact, context, hash, facets, old); |
|
75 } |
|
76 |
|
77 /** |
|
78 * Compute result or returned object from cache, create facets. |
|
79 * @param old Object that was cached. |
|
80 */ |
|
81 private Object compute( |
|
82 final SINFOArtifact sinfo, |
|
83 final CallContext context, |
|
84 final String hash, |
|
85 final List<Facet> facets, |
|
86 final Object old |
|
87 ) { |
|
88 final CalculationResult res; |
|
89 if (old instanceof CalculationResult) |
|
90 res = (CalculationResult) old; |
|
91 else |
|
92 res = new FlowDepthCalculation(context).calculate(sinfo); |
|
93 |
|
94 if (facets == null) { |
|
95 return res; |
|
96 } |
|
97 |
|
98 final FlowDepthCalculationResults results = (FlowDepthCalculationResults) res.getData(); |
|
99 |
|
100 /* add themes for chart, for each result */ |
|
101 final List<FlowDepthCalculationResult> resultList = results.getResults(); |
|
102 for (int index = 0; index < resultList.size(); index++) { |
|
103 |
|
104 final FlowDepthCalculationResult result = resultList.get(index); |
|
105 |
|
106 /* filtered (zoom dependent mean) flow depth */ |
8877
|
107 final String facetFlowDepthFilteredDescription = Resources.getMsg( context.getMeta(), I18N_FACET_FLOW_DEPTH_FILTERED_DESCRIPTION, I18N_FACET_FLOW_DEPTH_FILTERED_DESCRIPTION, result.getLabel() ); |
8854
|
108 facets.add(new FlowDepthFilterFacet( |
|
109 index, |
|
110 FlowDepthProcessor.FACET_FLOW_DEPTH_FILTERED, |
|
111 facetFlowDepthFilteredDescription, |
|
112 ComputeType.ADVANCE, |
|
113 id, |
|
114 hash |
|
115 )); |
|
116 |
|
117 // FIXME: add other themes |
|
118 } |
|
119 |
|
120 if (!resultList.isEmpty() ) { |
|
121 Facet csv = new DataFacet( |
|
122 FacetTypes.CSV, "CSV data", ComputeType.ADVANCE, hash, id); |
|
123 Facet pdf = new DataFacet( |
|
124 FacetTypes.PDF, "PDF data", ComputeType.ADVANCE, hash, id); |
|
125 |
|
126 facets.add(csv); |
|
127 facets.add(pdf); |
|
128 } |
|
129 |
|
130 final Calculation report = res.getReport(); |
|
131 |
|
132 if (report.hasProblems()) { |
|
133 facets.add(new ReportFacet(ComputeType.ADVANCE, hash, id)); |
|
134 } |
|
135 |
|
136 return res; |
|
137 } |
|
138 } |