Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepthminmax/FlowDepthMinMaxState.java @ 9150:23945061daec
gigantic refactoring: exporter, result, results
to support multiple jaspers -> collisions
author | gernotbelger |
---|---|
date | Thu, 14 Jun 2018 16:56:31 +0200 |
parents | 0adc6d04de95 |
children | a4121ec450d6 |
rev | line source |
---|---|
8946 | 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.flowdepthminmax; | |
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; | |
9150
23945061daec
gigantic refactoring: exporter, result, results
gernotbelger
parents:
8993
diff
changeset
|
17 import org.dive4elements.river.artifacts.common.AbstractCalculationExportableResult; |
8946 | 18 import org.dive4elements.river.artifacts.model.Calculation; |
19 import org.dive4elements.river.artifacts.model.CalculationResult; | |
20 import org.dive4elements.river.artifacts.model.DataFacet; | |
21 import org.dive4elements.river.artifacts.model.EmptyFacet; | |
22 import org.dive4elements.river.artifacts.model.FacetTypes; | |
23 import org.dive4elements.river.artifacts.model.ReportFacet; | |
24 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact; | |
8950
b0aeed4c97c1
Implemented chart output for sinfo flow depth min/max calculation
gernotbelger
parents:
8946
diff
changeset
|
25 import org.dive4elements.river.artifacts.sinfo.common.FlowDepthProcessor; |
8946 | 26 import org.dive4elements.river.artifacts.states.DefaultState; |
27 | |
28 /** State in which a waterlevel has been calculated. */ | |
29 public class FlowDepthMinMaxState extends DefaultState { | |
30 | |
31 /// ** The log that is used in this state. */ | |
32 // private static Logger log = Logger.getLogger(FlowDepthState.class); | |
33 | |
34 private static final long serialVersionUID = 1L; | |
35 | |
36 /** | |
37 * From this state can only be continued trivially. | |
38 */ | |
39 @Override | |
40 protected String getUIProvider() { | |
41 return "continue"; | |
42 } | |
43 | |
44 @Override | |
45 public Object computeFeed(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) { | |
46 // FIXME: why is this necessary? | |
47 if (artifact instanceof ChartArtifact) { | |
48 facets.add(new EmptyFacet()); | |
49 return null; | |
50 } | |
51 | |
52 return compute((SINFOArtifact) artifact, context, hash, facets, old); | |
53 } | |
54 | |
55 @Override | |
56 public Object computeAdvance(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) { | |
57 if (artifact instanceof ChartArtifact) { | |
58 facets.add(new EmptyFacet()); | |
59 return null; | |
60 } | |
61 return compute((SINFOArtifact) artifact, context, hash, facets, old); | |
62 } | |
63 | |
64 /** | |
65 * Compute result or returned object from cache, create facets. | |
66 * | |
67 * @param old | |
68 * Object that was cached. | |
69 */ | |
70 private Object compute(final SINFOArtifact sinfo, final CallContext context, final String hash, final List<Facet> facets, final Object old) { | |
71 | |
72 final CalculationResult res = doCompute(sinfo, context, old); | |
73 | |
74 if (facets == null) | |
75 return res; | |
76 | |
77 final FlowDepthMinMaxCalculationResults results = (FlowDepthMinMaxCalculationResults) res.getData(); | |
78 | |
79 /* add themes for chart, for each result */ | |
9150
23945061daec
gigantic refactoring: exporter, result, results
gernotbelger
parents:
8993
diff
changeset
|
80 final List<AbstractCalculationExportableResult<FlowDepthMinMaxCalculationResults>> resultList = results.getResults(); |
8946 | 81 for (int index = 0; index < resultList.size(); index++) { |
82 | |
9150
23945061daec
gigantic refactoring: exporter, result, results
gernotbelger
parents:
8993
diff
changeset
|
83 final FlowDepthMinMaxCalculationResult result = (FlowDepthMinMaxCalculationResult) resultList.get(index); |
8946 | 84 |
85 /* filtered (zoom dependent mean) flow depth */ | |
8993
0adc6d04de95
SInfo - FlowDepthMinMax: choosing bed heights, not bed height min and max separately
gernotbelger
parents:
8980
diff
changeset
|
86 facets.add(FlowDepthProcessor.createFlowDepthMinFilteredFacet(context, hash, this.id, result, index)); |
0adc6d04de95
SInfo - FlowDepthMinMax: choosing bed heights, not bed height min and max separately
gernotbelger
parents:
8980
diff
changeset
|
87 facets.add(FlowDepthProcessor.createFlowDepthMinRawFacet(context, hash, this.id, result, index)); |
0adc6d04de95
SInfo - FlowDepthMinMax: choosing bed heights, not bed height min and max separately
gernotbelger
parents:
8980
diff
changeset
|
88 facets.add(FlowDepthProcessor.createFlowDepthMaxFilteredFacet(context, hash, this.id, result, index)); |
0adc6d04de95
SInfo - FlowDepthMinMax: choosing bed heights, not bed height min and max separately
gernotbelger
parents:
8980
diff
changeset
|
89 facets.add(FlowDepthProcessor.createFlowDepthMaxRawFacet(context, hash, this.id, result, index)); |
8946 | 90 } |
91 | |
92 if (!resultList.isEmpty()) { | |
8950
b0aeed4c97c1
Implemented chart output for sinfo flow depth min/max calculation
gernotbelger
parents:
8946
diff
changeset
|
93 facets.add(new DataFacet(FacetTypes.CSV, "CSV data", ComputeType.ADVANCE, hash, this.id)); |
b0aeed4c97c1
Implemented chart output for sinfo flow depth min/max calculation
gernotbelger
parents:
8946
diff
changeset
|
94 facets.add(new DataFacet(FacetTypes.PDF, "PDF data", ComputeType.ADVANCE, hash, this.id)); |
8946 | 95 } |
96 | |
97 final Calculation report = res.getReport(); | |
98 if (report.hasProblems()) | |
99 facets.add(new ReportFacet(ComputeType.ADVANCE, hash, this.id)); | |
100 | |
101 return res; | |
102 } | |
103 | |
104 private CalculationResult doCompute(final SINFOArtifact sinfo, final CallContext context, final Object old) { | |
105 if (old instanceof CalculationResult) | |
106 return (CalculationResult) old; | |
107 | |
108 return new FlowDepthMinMaxCalculation(context).calculate(sinfo); | |
109 } | |
110 } |