Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZonesState.java @ 8996:fb9430250899
Work on uinfo
author | gernotbelger |
---|---|
date | Thu, 12 Apr 2018 19:13:39 +0200 |
parents | |
children | a6b3421dc2b4 |
comparison
equal
deleted
inserted
replaced
8995:8c3e5682cb60 | 8996:fb9430250899 |
---|---|
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.uinfo.vegetationzones; | |
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 VegetationZonesState 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 VegetationZonesCalculationResults results = (VegetationZonesCalculationResults) res.getData(); | |
79 | |
80 List<VegetationZonesCalculationResult> resultList = results.getResults(); | |
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 VegetationZonesCalculation(context).calculate(sinfo); | |
103 } | |
104 } |