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. */ |
8884
|
28 public class FlowDepthState extends DefaultState { |
|
29 |
8854
|
30 /// ** The log that is used in this state. */ |
|
31 // private static Logger log = Logger.getLogger(FlowDepthState.class); |
|
32 |
8877
|
33 private static final long serialVersionUID = 1L; |
|
34 |
8854
|
35 private static final String I18N_FACET_FLOW_DEPTH_FILTERED_DESCRIPTION = "sinfo.facet.flow_depth.filtered.description"; |
|
36 |
8884
|
37 private static final String I18N_FACET_FLOW_DEPTH_TKH_FILTERED_DESCRIPTION = "sinfo.facet.flow_depth.tkh.filtered.description"; |
|
38 |
|
39 private static final String I18N_FACET_TKH_DESCRIPTION = "sinfo.facet.tkh.description"; |
|
40 |
|
41 private static final String SINFO_CHART_FLOW_DEPTH_YAXIS_LABEL = "sinfo.chart.flow_depth.yaxis.label"; |
|
42 |
|
43 private static final String SINFO_CHART_TKX_YAXIS_LABEL = "sinfo.chart.tkh.yaxis.label"; |
|
44 |
8854
|
45 /** |
|
46 * From this state can only be continued trivially. |
|
47 */ |
|
48 @Override |
|
49 protected String getUIProvider() { |
|
50 return "continue"; |
|
51 } |
|
52 |
|
53 @Override |
8884
|
54 public Object computeFeed(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) { |
8879
|
55 // FIXME: why is this necessary? |
|
56 if (artifact instanceof ChartArtifact) { |
|
57 facets.add(new EmptyFacet()); |
|
58 return null; |
|
59 } |
|
60 |
|
61 return compute((SINFOArtifact) artifact, context, hash, facets, old); |
|
62 } |
|
63 |
|
64 @Override |
8884
|
65 public Object computeAdvance(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) { |
8854
|
66 if (artifact instanceof ChartArtifact) { |
|
67 facets.add(new EmptyFacet()); |
|
68 return null; |
|
69 } |
|
70 return compute((SINFOArtifact) artifact, context, hash, facets, old); |
|
71 } |
|
72 |
|
73 /** |
|
74 * Compute result or returned object from cache, create facets. |
8884
|
75 * |
|
76 * @param old |
|
77 * Object that was cached. |
8854
|
78 */ |
8884
|
79 private Object compute(final SINFOArtifact sinfo, final CallContext context, final String hash, final List<Facet> facets, final Object old) { |
8879
|
80 |
8854
|
81 final CalculationResult res; |
8879
|
82 if (old instanceof CalculationResult) |
|
83 res = (CalculationResult) old; |
|
84 else |
|
85 res = new FlowDepthCalculation(context).calculate(sinfo); |
8854
|
86 |
|
87 if (facets == null) { |
|
88 return res; |
|
89 } |
|
90 |
8884
|
91 final FlowDepthCalculationResults results = (FlowDepthCalculationResults) res.getData(); |
8854
|
92 |
|
93 /* add themes for chart, for each result */ |
|
94 final List<FlowDepthCalculationResult> resultList = results.getResults(); |
|
95 for (int index = 0; index < resultList.size(); index++) { |
|
96 |
8879
|
97 final FlowDepthCalculationResult result = resultList.get(index); |
|
98 |
|
99 /* filtered (zoom dependent mean) flow depth */ |
8884
|
100 final String facetFlowDepthFilteredDescription = Resources.getMsg(context.getMeta(), I18N_FACET_FLOW_DEPTH_FILTERED_DESCRIPTION, |
|
101 I18N_FACET_FLOW_DEPTH_FILTERED_DESCRIPTION, result.getLabel()); |
|
102 facets.add(new FlowDepthFacet(index, FlowDepthProcessor.FACET_FLOW_DEPTH_FILTERED, facetFlowDepthFilteredDescription, |
|
103 SINFO_CHART_FLOW_DEPTH_YAXIS_LABEL, ComputeType.ADVANCE, this.id, hash)); |
8879
|
104 |
8884
|
105 if (results.isUseTkh()) { |
|
106 /* filtered (zoom dependent mean) flow depth including tkh */ |
|
107 final String facetFlowDepthTkhFilteredDescription = Resources.getMsg(context.getMeta(), I18N_FACET_FLOW_DEPTH_TKH_FILTERED_DESCRIPTION, |
|
108 I18N_FACET_FLOW_DEPTH_TKH_FILTERED_DESCRIPTION, result.getLabel()); |
|
109 facets.add(new FlowDepthFacet(index, FlowDepthProcessor.FACET_FLOW_DEPTH_TKH_FILTERED, facetFlowDepthTkhFilteredDescription, |
|
110 SINFO_CHART_FLOW_DEPTH_YAXIS_LABEL, ComputeType.ADVANCE, this.id, hash)); |
|
111 |
|
112 // FIXME: add other themes |
|
113 // - Streckenfavoriten |
|
114 |
|
115 // FIXME: |
|
116 // - Gemittelte Linie der Fließtiefe mitsamt TKH |
|
117 // - Transportkörperhöhen (oben/unten/schraffur) |
|
118 final String facetTkhDescription = Resources.getMsg(context.getMeta(), I18N_FACET_TKH_DESCRIPTION, I18N_FACET_TKH_DESCRIPTION, |
|
119 result.getLabel()); |
|
120 facets.add(new FlowDepthFacet(index, TkhProcessor.FACET_TKH, facetTkhDescription, SINFO_CHART_TKX_YAXIS_LABEL, ComputeType.ADVANCE, this.id, |
|
121 hash)); |
|
122 } |
|
123 |
|
124 // FIXME: Datenkorbkonfiguration |
8879
|
125 } |
8854
|
126 |
8884
|
127 if (!resultList.isEmpty()) { |
|
128 final Facet csv = new DataFacet(FacetTypes.CSV, "CSV data", ComputeType.ADVANCE, hash, this.id); |
|
129 final Facet pdf = new DataFacet(FacetTypes.PDF, "PDF data", ComputeType.ADVANCE, hash, this.id); |
8854
|
130 |
|
131 facets.add(csv); |
|
132 facets.add(pdf); |
|
133 } |
|
134 |
|
135 final Calculation report = res.getReport(); |
|
136 |
|
137 if (report.hasProblems()) { |
8879
|
138 facets.add(new ReportFacet(ComputeType.ADVANCE, hash, this.id)); |
8854
|
139 } |
|
140 |
|
141 return res; |
|
142 } |
|
143 } |