Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/InundationDurationState.java @ 9178:2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
author | gernotbelger |
---|---|
date | Tue, 26 Jun 2018 19:48:35 +0200 |
parents | 23945061daec |
children | 0633f963c5be |
rev | line source |
---|---|
8996 | 1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
9150
23945061daec
gigantic refactoring: exporter, result, results
gernotbelger
parents:
8996
diff
changeset
|
2 * Software engineering by |
23945061daec
gigantic refactoring: exporter, result, results
gernotbelger
parents:
8996
diff
changeset
|
3 * Björnsen Beratende Ingenieure GmbH |
8996 | 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.uinfo.inundationduration; | |
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; | |
9178
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
9150
diff
changeset
|
18 import org.dive4elements.river.artifacts.MapArtifact.MapState; |
9150
23945061daec
gigantic refactoring: exporter, result, results
gernotbelger
parents:
8996
diff
changeset
|
19 import org.dive4elements.river.artifacts.common.AbstractCalculationExportableResult; |
8996 | 20 import org.dive4elements.river.artifacts.model.Calculation; |
21 import org.dive4elements.river.artifacts.model.CalculationResult; | |
22 import org.dive4elements.river.artifacts.model.DataFacet; | |
23 import org.dive4elements.river.artifacts.model.EmptyFacet; | |
24 import org.dive4elements.river.artifacts.model.FacetTypes; | |
25 import org.dive4elements.river.artifacts.model.ReportFacet; | |
26 import org.dive4elements.river.artifacts.uinfo.UINFOArtifact; | |
27 | |
28 /** | |
29 * @author Domenico Nardi Tironi | |
30 */ | |
9178
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
9150
diff
changeset
|
31 public class InundationDurationState extends MapState { |
8996 | 32 |
33 /// ** The log that is used in this state. */ | |
34 // private static Logger log = Logger.getLogger(FlowDepthState.class); | |
35 | |
36 private static final long serialVersionUID = 1L; | |
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(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) { | |
48 // FIXME: why is this necessary? | |
49 if (artifact instanceof ChartArtifact) { | |
50 facets.add(new EmptyFacet()); | |
51 return null; | |
52 } | |
53 | |
54 return compute((UINFOArtifact) artifact, context, hash, facets, old); | |
55 } | |
56 | |
57 @Override | |
58 public Object computeAdvance(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) { | |
59 if (artifact instanceof ChartArtifact) { | |
60 facets.add(new EmptyFacet()); | |
61 return null; | |
62 } | |
9178
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
9150
diff
changeset
|
63 |
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
9150
diff
changeset
|
64 if (facets != null) |
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
9150
diff
changeset
|
65 super.computeAdvance(artifact, hash, context, facets, old); |
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
9150
diff
changeset
|
66 |
8996 | 67 return compute((UINFOArtifact) artifact, context, hash, facets, old); |
68 } | |
69 | |
70 /** | |
71 * Compute result or returned object from cache, create facets. | |
72 * | |
73 * @param old | |
74 * Object that was cached. | |
75 */ | |
76 private Object compute(final UINFOArtifact sinfo, final CallContext context, final String hash, final List<Facet> facets, final Object old) { | |
77 | |
78 final CalculationResult res = doCompute(sinfo, context, old); | |
79 | |
80 if (facets == null) | |
81 return res; | |
82 | |
83 final InundationDurationCalculationResults results = (InundationDurationCalculationResults) res.getData(); | |
84 | |
9150
23945061daec
gigantic refactoring: exporter, result, results
gernotbelger
parents:
8996
diff
changeset
|
85 final List<AbstractCalculationExportableResult<InundationDurationCalculationResults>> resultList = results.getResults(); |
8996 | 86 |
87 if (!resultList.isEmpty()) { | |
88 final Facet csv = new DataFacet(FacetTypes.CSV, "CSV data", ComputeType.ADVANCE, hash, this.id); | |
89 final Facet pdf = new DataFacet(FacetTypes.PDF, "PDF data", ComputeType.ADVANCE, hash, this.id); | |
90 | |
91 facets.add(csv); | |
92 facets.add(pdf); | |
93 } | |
94 | |
95 final Calculation report = res.getReport(); | |
96 | |
97 if (report.hasProblems()) | |
98 facets.add(new ReportFacet(ComputeType.ADVANCE, hash, this.id)); | |
99 | |
100 return res; | |
101 } | |
102 | |
103 private CalculationResult doCompute(final UINFOArtifact sinfo, final CallContext context, final Object old) { | |
104 if (old instanceof CalculationResult) | |
105 return (CalculationResult) old; | |
106 | |
107 return new InundationDurationCalculation(context).calculate(sinfo); | |
108 } | |
109 } |