9050
|
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.inundation; |
|
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.CalculationResult; |
|
18 import org.dive4elements.river.artifacts.model.EmptyFacet; |
|
19 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact; |
|
20 import org.dive4elements.river.artifacts.states.DefaultState; |
|
21 |
|
22 /** State in which a waterlevel has been calculated. */ |
|
23 public class InundationState extends DefaultState { |
|
24 |
|
25 /// ** The log that is used in this state. */ |
|
26 // private static Logger log = Logger.getLogger(FlowDepthState.class); |
|
27 |
|
28 private static final long serialVersionUID = 1L; |
|
29 |
|
30 /** |
|
31 * From this state can only be continued trivially. |
|
32 */ |
|
33 @Override |
|
34 protected String getUIProvider() { |
|
35 return "continue"; |
|
36 } |
|
37 |
|
38 @Override |
|
39 public Object computeFeed(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) { |
|
40 if (artifact instanceof ChartArtifact) { |
|
41 facets.add(new EmptyFacet()); |
|
42 return null; |
|
43 } |
|
44 |
|
45 return compute((SINFOArtifact) artifact, context, hash, facets, old); |
|
46 } |
|
47 |
|
48 @Override |
|
49 public Object computeAdvance(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) { |
|
50 if (artifact instanceof ChartArtifact) { |
|
51 facets.add(new EmptyFacet()); |
|
52 return null; |
|
53 } |
|
54 return compute((SINFOArtifact) artifact, context, hash, facets, old); |
|
55 } |
|
56 |
|
57 /** |
|
58 * Compute result or returned object from cache, create facets. |
|
59 * |
|
60 * @param old |
|
61 * Object that was cached. |
|
62 */ |
|
63 private Object compute(final SINFOArtifact sinfo, final CallContext context, final String hash, final List<Facet> facets, final Object old) { |
|
64 |
|
65 final CalculationResult res = doCompute(sinfo, context, old); |
|
66 |
|
67 if (facets == null) |
|
68 return res; |
|
69 // |
|
70 // final FlowDepthCalculationResults results = (FlowDepthCalculationResults) res.getData(); |
|
71 // |
|
72 // /* add themes for chart, for each result */ |
|
73 // final List<FlowDepthCalculationResult> resultList = results.getResults(); |
|
74 // for (int index = 0; index < resultList.size(); index++) { |
|
75 // |
|
76 // final FlowDepthCalculationResult result = resultList.get(index); |
|
77 // |
|
78 // /* filtered (zoom dependent mean) flow depth */ |
|
79 // facets.add(FlowDepthProcessor.createFlowDepthFilteredFacet(context, hash, this.id, result, index)); |
|
80 // facets.add(FlowDepthProcessor.createFlowDepthRawFacet(context, hash, this.id, result, index)); |
|
81 // |
|
82 // if (results.isUseTkh()) { |
|
83 // /* filtered (zoom dependent mean) flow depth including tkh */ |
|
84 // facets.add(FlowDepthProcessor.createFlowDepthTkhFilteredFacet(context, hash, this.id, result, index)); |
|
85 // facets.add(FlowDepthProcessor.createFlowDepthTkhRawFacet(context, hash, this.id, result, index)); |
|
86 // |
|
87 // facets.add(TkhProcessor.createTkhFacet(context, hash, this.id, result, index)); |
|
88 // } |
|
89 // } |
|
90 |
|
91 // if (!resultList.isEmpty()) { |
|
92 // final Facet csv = new DataFacet(FacetTypes.CSV, "CSV data", ComputeType.ADVANCE, hash, this.id); |
|
93 // final Facet pdf = new DataFacet(FacetTypes.PDF, "PDF data", ComputeType.ADVANCE, hash, this.id); |
|
94 // |
|
95 // facets.add(csv); |
|
96 // facets.add(pdf); |
|
97 // } |
|
98 // |
|
99 // final Calculation report = res.getReport(); |
|
100 // |
|
101 // if (report.hasProblems()) { |
|
102 // facets.add(new ReportFacet(ComputeType.ADVANCE, hash, this.id)); |
|
103 // } |
|
104 |
|
105 return res; |
|
106 } |
|
107 |
|
108 private CalculationResult doCompute(final SINFOArtifact sinfo, final CallContext context, final Object old) { |
|
109 if (old instanceof CalculationResult) |
|
110 return (CalculationResult) old; |
|
111 |
|
112 return null; // new FlowDepthCalculation(context).calculate(sinfo); |
|
113 } |
|
114 } |