Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/SalixLineState.java @ 9244:b9505aa78cdd
commit error
author | gernotbelger |
---|---|
date | Wed, 11 Jul 2018 13:42:29 +0200 |
parents | da0bdbcd6f09 |
children | 385b52ccde23 |
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.salix; | |
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.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.states.DefaultState; | |
25 import org.dive4elements.river.artifacts.uinfo.UINFOArtifact; | |
26 | |
27 /** | |
28 * @author Domenico Nardi Tironi | |
29 */ | |
30 public class SalixLineState extends DefaultState { | |
31 | |
32 /// ** The log that is used in this state. */ | |
33 // private static Logger log = Logger.getLogger(FlowDepthState.class); | |
34 | |
35 private static final long serialVersionUID = 1L; | |
36 | |
37 /** | |
38 * From this state can only be continued trivially. | |
39 */ | |
40 @Override | |
41 protected String getUIProvider() { | |
42 return "continue"; | |
43 } | |
44 | |
45 @Override | |
46 public Object computeFeed(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) { | |
47 // FIXME: why is this necessary? | |
48 if (artifact instanceof ChartArtifact) { | |
49 facets.add(new EmptyFacet()); | |
50 return null; | |
51 } | |
52 | |
53 return compute((UINFOArtifact) artifact, context, hash, facets, old); | |
54 } | |
55 | |
56 @Override | |
57 public Object computeAdvance(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) { | |
58 if (artifact instanceof ChartArtifact) { | |
59 facets.add(new EmptyFacet()); | |
60 return null; | |
61 } | |
62 return compute((UINFOArtifact) artifact, context, hash, facets, old); | |
63 } | |
64 | |
65 /** | |
66 * Compute result or returned object from cache, create facets. | |
67 * | |
68 * @param old | |
69 * Object that was cached. | |
70 */ | |
71 private Object compute(final UINFOArtifact sinfo, final CallContext context, final String hash, final List<Facet> facets, final Object old) { | |
72 | |
73 final CalculationResult res = doCompute(sinfo, context, old); | |
74 | |
75 if (facets == null) | |
76 return res; | |
77 | |
78 final SalixLineCalculationResults results = (SalixLineCalculationResults) res.getData(); | |
79 | |
9243 | 80 final List<SalixLineCalculationNoScenarioResult> resultList = results.getResults(); |
8996 | 81 |
82 if (!resultList.isEmpty()) { | |
83 final Facet csv = new DataFacet(FacetTypes.CSV, "CSV data", ComputeType.ADVANCE, hash, this.id); | |
84 final Facet pdf = new DataFacet(FacetTypes.PDF, "PDF data", ComputeType.ADVANCE, hash, this.id); | |
85 | |
86 facets.add(csv); | |
87 facets.add(pdf); | |
88 } | |
89 | |
90 final Calculation report = res.getReport(); | |
91 | |
92 if (report.hasProblems()) | |
93 facets.add(new ReportFacet(ComputeType.ADVANCE, hash, this.id)); | |
94 | |
95 return res; | |
96 } | |
97 | |
98 private CalculationResult doCompute(final UINFOArtifact sinfo, final CallContext context, final Object old) { | |
99 if (old instanceof CalculationResult) | |
100 return (CalculationResult) old; | |
101 | |
102 return new SalixLineCalculation(context).calculate(sinfo); | |
103 } | |
104 } |