Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZonesState.java @ 9556:9b8e8fc1f408
Use facetName in all processors as themeType for legend aggregation.
author | gernotbelger |
---|---|
date | Tue, 23 Oct 2018 16:26:58 +0200 |
parents | 8b7bf26b8782 |
children |
rev | line source |
---|---|
8996 | 1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
9024 | 2 * Software engineering by |
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.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; | |
9506
8b7bf26b8782
Predefined artifact for standard vegetation zones.
gernotbelger
parents:
9499
diff
changeset
|
24 import org.dive4elements.river.artifacts.resources.Resources; |
8996 | 25 import org.dive4elements.river.artifacts.states.DefaultState; |
26 import org.dive4elements.river.artifacts.uinfo.UINFOArtifact; | |
27 | |
28 /** | |
29 * @author Domenico Nardi Tironi | |
30 */ | |
31 public class VegetationZonesState extends DefaultState { | |
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 | |
9506
8b7bf26b8782
Predefined artifact for standard vegetation zones.
gernotbelger
parents:
9499
diff
changeset
|
38 private static final String FACET_VEGETATION_ZONES_CROSS_SECTION_DESCRIPTION = "uinfo_facet_vegetation_zones_cross_section.description"; |
8b7bf26b8782
Predefined artifact for standard vegetation zones.
gernotbelger
parents:
9499
diff
changeset
|
39 |
8996 | 40 /** |
41 * From this state can only be continued trivially. | |
42 */ | |
43 @Override | |
44 protected String getUIProvider() { | |
45 return "continue"; | |
46 } | |
47 | |
48 @Override | |
49 public Object computeFeed(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) { | |
50 // FIXME: why is this necessary? | |
51 if (artifact instanceof ChartArtifact) { | |
52 facets.add(new EmptyFacet()); | |
53 return null; | |
54 } | |
55 return compute((UINFOArtifact) artifact, context, hash, facets, old); | |
56 } | |
57 | |
58 @Override | |
59 public Object computeAdvance(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) { | |
60 if (artifact instanceof ChartArtifact) { | |
61 facets.add(new EmptyFacet()); | |
62 return null; | |
63 } | |
64 return compute((UINFOArtifact) artifact, context, hash, facets, old); | |
65 } | |
66 | |
67 /** | |
68 * Compute result or returned object from cache, create facets. | |
69 * | |
70 * @param old | |
71 * Object that was cached. | |
72 */ | |
73 private Object compute(final UINFOArtifact sinfo, final CallContext context, final String hash, final List<Facet> facets, final Object old) { | |
74 | |
75 final CalculationResult res = doCompute(sinfo, context, old); | |
76 | |
77 if (facets == null) | |
78 return res; | |
79 | |
80 final VegetationZonesCalculationResults results = (VegetationZonesCalculationResults) res.getData(); | |
81 | |
9195 | 82 final List<VegetationZonesCalculationResult> resultList = results.getResults(); |
8996 | 83 |
84 if (!resultList.isEmpty()) { | |
9499 | 85 |
9506
8b7bf26b8782
Predefined artifact for standard vegetation zones.
gernotbelger
parents:
9499
diff
changeset
|
86 final String label = resultList.get(0).getLabel(); |
8b7bf26b8782
Predefined artifact for standard vegetation zones.
gernotbelger
parents:
9499
diff
changeset
|
87 final String facetDescription = Resources.getMsg(context.getMeta(), FACET_VEGETATION_ZONES_CROSS_SECTION_DESCRIPTION, new Object[] { label }); |
8b7bf26b8782
Predefined artifact for standard vegetation zones.
gernotbelger
parents:
9499
diff
changeset
|
88 |
8b7bf26b8782
Predefined artifact for standard vegetation zones.
gernotbelger
parents:
9499
diff
changeset
|
89 facets.add(VegetationZonesCrossSectionProcessor.createVegetationZonesCrossSectionFacet(facetDescription)); |
9499 | 90 |
8996 | 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 return res; | |
104 } | |
105 | |
9069
1ffd38826175
access uinfo.vegetationzones+inundation_duration
gernotbelger
parents:
9024
diff
changeset
|
106 private CalculationResult doCompute(final UINFOArtifact uinfo, final CallContext context, final Object old) { |
8996 | 107 if (old instanceof CalculationResult) |
108 return (CalculationResult) old; | |
109 | |
9069
1ffd38826175
access uinfo.vegetationzones+inundation_duration
gernotbelger
parents:
9024
diff
changeset
|
110 return new VegetationZonesCalculation(context).calculate(uinfo); |
8996 | 111 } |
112 } |