Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/InundationDurationAccess.java @ 9543:3264c2df4f18
WMS-Config
author | gernotbelger |
---|---|
date | Wed, 17 Oct 2018 17:10:52 +0200 |
parents | bf6b63208f34 |
children | ba0561906f81 |
rev | line source |
---|---|
9069 | 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 | |
11 package org.dive4elements.river.artifacts.uinfo.inundationduration; | |
12 | |
9481 | 13 import java.io.IOException; |
9537
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
14 import java.io.UnsupportedEncodingException; |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
15 import java.net.URLEncoder; |
9481 | 16 |
9537
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
17 import org.dive4elements.artifacts.CallContext; |
9069 | 18 import org.dive4elements.river.artifacts.access.RangeAccess; |
9070
611a523fc42f
VegetationZoneAccessHelper, VegetationTablePanels verbessert
gernotbelger
parents:
9069
diff
changeset
|
19 import org.dive4elements.river.artifacts.common.EpochYearAccessHelper; |
9481 | 20 import org.dive4elements.river.artifacts.resources.Resources; |
21 import org.dive4elements.river.artifacts.sinfo.tkhstate.TsvHelper.TsvReaderException; | |
9069 | 22 import org.dive4elements.river.artifacts.uinfo.UINFOArtifact; |
23 import org.dive4elements.river.artifacts.uinfo.UinfoCalcMode; | |
9481 | 24 import org.dive4elements.river.artifacts.uinfo.inundationduration.InundationDurationCalculationResult.WmsLayer; |
25 import org.dive4elements.river.artifacts.uinfo.inundationduration.UedauernConfiguration.YearType; | |
9069 | 26 |
27 /** | |
28 * Access to the flow depth calculation type specific SInfo artifact data. | |
29 * REMARK: this class is NOT intended to be hold in the results (or anywhere else), in order to avoid a permanent | |
30 * reference to the artifact instance. | |
31 * Hence we do NOT cache any data. | |
32 * | |
33 * @author Gernot Belger | |
34 */ | |
35 final class InundationDurationAccess extends RangeAccess { | |
36 | |
37 // IMMER ABGLEICHEN MIT SuperVegZonesTablePanel.TABLE_CELL_SEPARATOR | |
38 public static final String TABLE_CELL_SEPARATOR = "TABLE_CELL_SEPARATOR"; | |
39 public static final String TABLE_ROW_SEPARATOR = "TABLE_ROW_SEPARATOR"; | |
9070
611a523fc42f
VegetationZoneAccessHelper, VegetationTablePanels verbessert
gernotbelger
parents:
9069
diff
changeset
|
40 |
611a523fc42f
VegetationZoneAccessHelper, VegetationTablePanels verbessert
gernotbelger
parents:
9069
diff
changeset
|
41 private final EpochYearAccessHelper helper; |
9069 | 42 |
9537
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
43 public static enum WmsClassification { |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
44 asIs { |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
45 @Override |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
46 public String configureAddress(final String serverAddress, final String url, final String vegetationZoneId) { |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
47 return url; |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
48 } |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
49 }, |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
50 vegetationZone { |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
51 @Override |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
52 public String configureAddress(final String serverAddress, final String url, final String vegetationZoneId) { |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
53 |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
54 try { |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
55 final String urlEncoded = URLEncoder.encode(url, "UTF-8"); |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
56 final String vegZoneIdEncoded = URLEncoder.encode(vegetationZoneId, "UTF-8"); |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
57 |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
58 return String.format("%s/%s/%s/%s", serverAddress, VegetationWmsResource.BASE_PATH, vegZoneIdEncoded, urlEncoded); |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
59 } |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
60 catch (final UnsupportedEncodingException e) { |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
61 /* should never happen */ |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
62 e.printStackTrace(); |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
63 return null; |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
64 } |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
65 } |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
66 }; |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
67 |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
68 public abstract String configureAddress(String serverAddress, String url, String vegetationZoneId); |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
69 } |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
70 |
9069 | 71 // Fields from state: |
72 // | |
73 // calculation_mode (String) | |
74 // ld_from, ld_to | |
75 // ye_select (String; state.uinfo.totalepoch oder state.uinfo.year) | |
9481 | 76 // year_epoch_select |
9069 | 77 // totalepoch (String; TODO: minmax totalEpoch herausfinden und setzen (nicht hier.. aber trotzdem die Erinnerung hier)) |
78 // use_scenario boolean (danach kommt kein radioBtn, sondern sedimentheight-Eingabe) | |
79 // sedimentheight String | |
80 // | |
81 // vegzones (String) TODO: MIT VegetationzonesAccess zusammenlegen | |
82 | |
83 public InundationDurationAccess(final UINFOArtifact uinfo) { | |
84 super(uinfo); | |
85 /* assert calculation mode */ | |
86 final UinfoCalcMode calculationMode = uinfo.getCalculationMode(); | |
9070
611a523fc42f
VegetationZoneAccessHelper, VegetationTablePanels verbessert
gernotbelger
parents:
9069
diff
changeset
|
87 this.helper = new EpochYearAccessHelper(uinfo); |
9069 | 88 assert (calculationMode == UinfoCalcMode.uinfo_inundation_duration); |
89 } | |
90 | |
9481 | 91 public boolean isUseYear() { |
92 if (this.helper.getYearEpoch().equals("state.uinfo.year")) | |
93 return true; | |
94 return false; | |
9069 | 95 } |
96 | |
9537
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
97 public WmsLayer createWMSLayer(final CallContext context, final String i10nKey, final WmsClassification classification, final String vegZoneId) |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
98 throws IOException, TsvReaderException { |
9178
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
9155
diff
changeset
|
99 |
9481 | 100 final YearType type = isUseYear() ? YearType.jahre : YearType.mittel; |
101 final String selectedElement = getSelectedLabel(); | |
102 | |
9537
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
103 final String layerLabel = Resources.getMsg(context.getMeta(), i10nKey, new Object[] { selectedElement }); |
9481 | 104 |
9537
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
105 return createWMSLayer(context, layerLabel, type, selectedElement, classification, vegZoneId); |
9069 | 106 } |
107 | |
9537
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
108 public WmsLayer createScenarioWMSLayer(final CallContext context, final String i10nKey, final WmsClassification classification, final String vegZoneId) |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
109 throws IOException, TsvReaderException { |
9481 | 110 |
111 // FIXME: use scenario-cm as label, and scenario-type | |
112 final YearType type = YearType.jahre; | |
113 | |
9537
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
114 final String selectedElement = Integer.toString(getDwspl()); |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
115 final String layerLabel = Resources.getMsg(context.getMeta(), i10nKey, new Object[] { selectedElement }); |
9481 | 116 |
9537
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
117 return createWMSLayer(context, layerLabel, type, selectedElement, classification, vegZoneId); |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
118 } |
9481 | 119 |
9537
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
120 private WmsLayer createWMSLayer(final CallContext context, final String layerLabel, final YearType type, final String selectedElement, |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
121 final WmsClassification classification, final String vegZoneId) |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
122 throws IOException, TsvReaderException { |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
123 |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
124 final String serverAddress = context.getDatabase().getServerAddress(); |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
125 |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
126 final UedauernConfiguration config = UedauernConfiguration.getInstance(getRiverName(), type); |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
127 final String url = config.getUrl(selectedElement); |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
128 final String layer = config.getLayer(selectedElement); |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
129 |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
130 final String realUrl = classification.configureAddress(serverAddress, url, vegZoneId); |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
131 |
bf6b63208f34
Work on uinfo inundation duration calculation.
gernotbelger
parents:
9481
diff
changeset
|
132 return new WmsLayer(layerLabel, realUrl, layer, classification == WmsClassification.asIs); |
9184 | 133 } |
134 | |
9481 | 135 private String getSelectedLabel() { |
136 return this.getString("year_epoch_select"); | |
137 } | |
138 | |
139 private Integer getDwspl() { | |
140 if (getIsUseScenario()) | |
9184 | 141 return super.getInteger("sedimentheight"); |
9481 | 142 |
9184 | 143 return null; |
144 } | |
145 | |
9070
611a523fc42f
VegetationZoneAccessHelper, VegetationTablePanels verbessert
gernotbelger
parents:
9069
diff
changeset
|
146 public String getVegZones() { |
9184 | 147 // mit VegetationzonesAccess zusammenlegen (eine Zeile sparen...) |
9070
611a523fc42f
VegetationZoneAccessHelper, VegetationTablePanels verbessert
gernotbelger
parents:
9069
diff
changeset
|
148 return super.getString("vegzones"); |
9069 | 149 } |
150 | |
9190 | 151 public boolean getIsUseScenario() { |
152 return super.getBoolean("use_scenario"); | |
153 } | |
9069 | 154 } |