8951
|
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
|
2 * Software engineering by |
|
3 * Björnsen Beratende Ingenieure GmbH |
|
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt |
|
5 * |
|
6 * This file is Free Software under the GNU AGPL (>=v3) |
|
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
|
8 * documentation coming with Dive4Elements River for details. |
|
9 */ |
|
10 package org.dive4elements.river.artifacts.sinfo.flowdepthdev; |
|
11 |
|
12 import java.util.List; |
|
13 |
|
14 import org.dive4elements.artifactdatabase.state.Facet; |
|
15 import org.dive4elements.artifacts.CallContext; |
|
16 import org.dive4elements.river.artifacts.ChartArtifact; |
|
17 import org.dive4elements.river.artifacts.D4EArtifact; |
|
18 import org.dive4elements.river.artifacts.model.CalculationResult; |
|
19 import org.dive4elements.river.artifacts.model.EmptyFacet; |
|
20 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact; |
|
21 import org.dive4elements.river.artifacts.states.DefaultState; |
|
22 |
|
23 /** |
|
24 * @author Gernot Belger |
|
25 */ |
|
26 public class FlowDepthDevelopmentState extends DefaultState { |
|
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 // FIXME: why is this necessary? |
|
41 if (artifact instanceof ChartArtifact) { |
|
42 facets.add(new EmptyFacet()); |
|
43 return null; |
|
44 } |
|
45 |
|
46 return compute((SINFOArtifact) artifact, context, hash, facets, old); |
|
47 } |
|
48 |
|
49 @Override |
|
50 public Object computeAdvance(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) { |
|
51 if (artifact instanceof ChartArtifact) { |
|
52 facets.add(new EmptyFacet()); |
|
53 return null; |
|
54 } |
|
55 return compute((SINFOArtifact) artifact, context, hash, facets, old); |
|
56 } |
|
57 |
|
58 /** |
|
59 * Compute result or returned object from cache, create facets. |
|
60 * |
|
61 * @param old |
|
62 * Object that was cached. |
|
63 */ |
|
64 private Object compute(final SINFOArtifact sinfo, final CallContext context, final String hash, final List<Facet> facets, final Object old) { |
|
65 |
|
66 final CalculationResult res = doCompute(sinfo, context, old); |
|
67 |
|
68 if (facets == null) |
|
69 return res; |
|
70 |
|
71 // final FlowDepthCalculationResults results = (FlowDepthCalculationResults) res.getData(); |
|
72 // |
|
73 // /* add themes for chart, for each result */ |
|
74 // final List<FlowDepthCalculationResult> resultList = results.getResults(); |
|
75 // for (int index = 0; index < resultList.size(); index++) { |
|
76 // |
|
77 // final FlowDepthCalculationResult result = resultList.get(index); |
|
78 // |
|
79 // /* filtered (zoom dependent mean) flow depth */ |
|
80 // facets.add(FlowDepthProcessor.createFlowDepthFacet(context, hash, this.id, result, index)); |
|
81 // |
|
82 // if (results.isUseTkh()) { |
|
83 // /* filtered (zoom dependent mean) flow depth including tkh */ |
|
84 // facets.add(FlowDepthProcessor.createFlowDepthTkhFacet(context, hash, this.id, result, index)); |
|
85 // |
|
86 // facets.add(TkhProcessor.createTkhFacet(context, hash, this.id, result, index)); |
|
87 // } |
|
88 // } |
|
89 // |
|
90 // if (!resultList.isEmpty()) { |
|
91 // final Facet csv = new DataFacet(FacetTypes.CSV, "CSV data", ComputeType.ADVANCE, hash, this.id); |
|
92 // final Facet pdf = new DataFacet(FacetTypes.PDF, "PDF data", ComputeType.ADVANCE, hash, this.id); |
|
93 // |
|
94 // facets.add(csv); |
|
95 // facets.add(pdf); |
|
96 // } |
|
97 // |
|
98 // final Calculation report = res.getReport(); |
|
99 // |
|
100 // if (report.hasProblems()) { |
|
101 // facets.add(new ReportFacet(ComputeType.ADVANCE, hash, this.id)); |
|
102 // } |
|
103 |
|
104 return res; |
|
105 } |
|
106 |
|
107 private CalculationResult doCompute(final SINFOArtifact sinfo, final CallContext context, final Object old) { |
|
108 if (old instanceof CalculationResult) |
|
109 return (CalculationResult) old; |
|
110 |
|
111 return new FlowDepthDevelopmentCalculation(context).calculate(sinfo); |
|
112 } |
|
113 } |