Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/InundationDurationState.java @ 9537:bf6b63208f34
Work on uinfo inundation duration calculation.
Using proxy-wms to induce additional style information (work in progress).
author | gernotbelger |
---|---|
date | Wed, 17 Oct 2018 11:23:17 +0200 |
parents | 992c188b7330 |
children | 3955ecc1a516 |
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; |
8996 | 19 import org.dive4elements.river.artifacts.model.Calculation; |
20 import org.dive4elements.river.artifacts.model.CalculationResult; | |
21 import org.dive4elements.river.artifacts.model.DataFacet; | |
22 import org.dive4elements.river.artifacts.model.EmptyFacet; | |
23 import org.dive4elements.river.artifacts.model.ReportFacet; | |
9190 | 24 import org.dive4elements.river.artifacts.model.map.WMSLayerFacet; |
8996 | 25 import org.dive4elements.river.artifacts.uinfo.UINFOArtifact; |
9190 | 26 import org.dive4elements.river.artifacts.uinfo.inundationduration.InundationDurationCalculationResult.WmsLayer; |
8996 | 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 | |
9481 | 38 private static final String LABEL_URL_SEPARATOR = ";LABEL_URL_SEPARATOR;";// always sync with client (ExportPanel) |
9190 | 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 | |
9190 | 56 return compute((UINFOArtifact) artifact, context, ComputeType.FEED, hash, facets, old); |
8996 | 57 } |
58 | |
59 @Override | |
60 public Object computeAdvance(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) { | |
61 if (artifact instanceof ChartArtifact) { | |
62 facets.add(new EmptyFacet()); | |
63 return null; | |
64 } | |
9178
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
9150
diff
changeset
|
65 |
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
9150
diff
changeset
|
66 if (facets != null) |
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
9150
diff
changeset
|
67 super.computeAdvance(artifact, hash, context, facets, old); |
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
9150
diff
changeset
|
68 |
9190 | 69 return compute((UINFOArtifact) artifact, context, ComputeType.ADVANCE, hash, facets, old); |
70 | |
8996 | 71 } |
72 | |
73 /** | |
74 * Compute result or returned object from cache, create facets. | |
75 * | |
76 * @param old | |
77 * Object that was cached. | |
78 */ | |
9190 | 79 private Object compute(final UINFOArtifact sinfo, final CallContext context, final ComputeType type, final String hash, final List<Facet> facets, |
80 final Object old) { | |
8996 | 81 |
82 final CalculationResult res = doCompute(sinfo, context, old); | |
83 | |
84 if (facets == null) | |
85 return res; | |
86 | |
9190 | 87 final InundationDurationCalculationResult result = (InundationDurationCalculationResult) res.getData(); |
88 final List<WmsLayer> layers = result.getLayers(); | |
8996 | 89 |
9190 | 90 int index = 1; // 1 because super.computeAdvance adds the river theme with index 0 |
91 for (final WmsLayer layer : layers) { | |
8996 | 92 |
9190 | 93 final String label = layer.getLabel(); |
94 final String url = layer.getUrl(); | |
95 | |
96 final WMSLayerFacet wmsFacet = new WMSLayerFacet(index, FLOODMAP_EXTERNAL_WMS_INUNDATIONDUR + index, label, type, getID(), hash, url); | |
9481 | 97 wmsFacet.addLayer(layer.getLayer()); |
98 | |
9190 | 99 facets.add(wmsFacet); |
9483 | 100 // TODO: |
9190 | 101 // wmsFacet.setExtent(getExtent(false)); |
102 // wmsFacet.setOriginalExtent(getExtent(true)); | |
103 wmsFacet.setSrid(getSrid()); | |
104 | |
105 if (layer.isShowLayerLink()) | |
106 facets.add(new DataFacet("wms_url", label + LABEL_URL_SEPARATOR + url, ComputeType.ADVANCE, hash, this.id)); | |
107 | |
108 index++; // because super.computeAdvance adds the river theme with index 0 | |
8996 | 109 } |
110 | |
111 final Calculation report = res.getReport(); | |
112 if (report.hasProblems()) | |
113 facets.add(new ReportFacet(ComputeType.ADVANCE, hash, this.id)); | |
114 | |
115 return res; | |
116 } | |
117 | |
9481 | 118 private CalculationResult doCompute(final UINFOArtifact artifact, final CallContext context, final Object old) { |
8996 | 119 if (old instanceof CalculationResult) |
120 return (CalculationResult) old; | |
121 | |
9481 | 122 return new InundationDurationCalculation(context).calculate(artifact); |
8996 | 123 } |
124 } |