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( |
8879
|
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 |
|
60 return compute((SINFOArtifact) artifact, context, hash, facets, old); |
|
61 } |
|
62 |
|
63 @Override |
|
64 public Object computeAdvance( |
|
65 final D4EArtifact artifact, |
|
66 final String hash, |
|
67 final CallContext context, |
|
68 final List<Facet> facets, |
|
69 final Object old |
|
70 ) { |
8854
|
71 if (artifact instanceof ChartArtifact) { |
|
72 facets.add(new EmptyFacet()); |
|
73 return null; |
|
74 } |
|
75 return compute((SINFOArtifact) artifact, context, hash, facets, old); |
|
76 } |
|
77 |
|
78 /** |
|
79 * Compute result or returned object from cache, create facets. |
|
80 * @param old Object that was cached. |
|
81 */ |
|
82 private Object compute( |
8879
|
83 final SINFOArtifact sinfo, |
|
84 final CallContext context, |
|
85 final String hash, |
|
86 final List<Facet> facets, |
|
87 final Object old |
|
88 ) { |
|
89 |
8854
|
90 final CalculationResult res; |
8879
|
91 if (old instanceof CalculationResult) |
|
92 res = (CalculationResult) old; |
|
93 else |
|
94 res = new FlowDepthCalculation(context).calculate(sinfo); |
8854
|
95 |
|
96 if (facets == null) { |
|
97 return res; |
|
98 } |
|
99 |
|
100 final FlowDepthCalculationResults results = (FlowDepthCalculationResults) res.getData(); |
|
101 |
|
102 /* add themes for chart, for each result */ |
|
103 final List<FlowDepthCalculationResult> resultList = results.getResults(); |
|
104 for (int index = 0; index < resultList.size(); index++) { |
|
105 |
8879
|
106 final FlowDepthCalculationResult result = resultList.get(index); |
|
107 |
|
108 /* filtered (zoom dependent mean) flow depth */ |
|
109 final String facetFlowDepthFilteredDescription = Resources.getMsg( context.getMeta(), I18N_FACET_FLOW_DEPTH_FILTERED_DESCRIPTION, I18N_FACET_FLOW_DEPTH_FILTERED_DESCRIPTION, result.getLabel() ); |
|
110 facets.add(new FlowDepthFilterFacet( |
|
111 index, |
|
112 FlowDepthProcessor.FACET_FLOW_DEPTH_FILTERED, |
|
113 facetFlowDepthFilteredDescription, |
|
114 ComputeType.ADVANCE, |
|
115 this.id, |
|
116 hash |
|
117 )); |
|
118 |
|
119 // FIXME: add other themes |
|
120 } |
8854
|
121 |
|
122 if (!resultList.isEmpty() ) { |
8879
|
123 final Facet csv = new DataFacet( |
|
124 FacetTypes.CSV, "CSV data", ComputeType.ADVANCE, hash, this.id); |
|
125 final Facet pdf = new DataFacet( |
|
126 FacetTypes.PDF, "PDF data", ComputeType.ADVANCE, hash, this.id); |
8854
|
127 |
|
128 facets.add(csv); |
|
129 facets.add(pdf); |
|
130 } |
|
131 |
|
132 final Calculation report = res.getReport(); |
|
133 |
|
134 if (report.hasProblems()) { |
8879
|
135 facets.add(new ReportFacet(ComputeType.ADVANCE, hash, this.id)); |
8854
|
136 } |
|
137 |
|
138 return res; |
|
139 } |
|
140 } |