Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/UedauernConfiguration.java @ 9619:63bbd5e45839
#21 WMS Legend
author | dnt_bjoernsen <d.tironi@bjoernsen.de> |
---|---|
date | Thu, 10 Oct 2019 16:08:47 +0200 |
parents | ba0561906f81 |
children |
rev | line source |
---|---|
9178
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
diff
changeset
|
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
diff
changeset
|
2 * Software engineering by |
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
diff
changeset
|
3 * Björnsen Beratende Ingenieure GmbH |
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
diff
changeset
|
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt |
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
diff
changeset
|
5 * |
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
diff
changeset
|
6 * This file is Free Software under the GNU AGPL (>=v3) |
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
diff
changeset
|
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
diff
changeset
|
8 * documentation coming with Dive4Elements River for details. |
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
diff
changeset
|
9 */ |
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
diff
changeset
|
10 package org.dive4elements.river.artifacts.uinfo.inundationduration; |
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
diff
changeset
|
11 |
9481 | 12 import java.io.File; |
9198 | 13 import java.io.IOException; |
9481 | 14 import java.io.UnsupportedEncodingException; |
15 import java.util.Collection; | |
9178
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
diff
changeset
|
16 import java.util.HashMap; |
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
diff
changeset
|
17 import java.util.LinkedHashMap; |
9481 | 18 import java.util.List; |
9178
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
diff
changeset
|
19 import java.util.Map; |
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
diff
changeset
|
20 |
9559
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
21 import org.apache.commons.lang.StringUtils; |
9481 | 22 import org.dive4elements.river.artifacts.sinfo.tkhstate.TsvHelper; |
23 import org.dive4elements.river.artifacts.sinfo.tkhstate.TsvHelper.TsvReaderException; | |
9178
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
diff
changeset
|
24 |
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
diff
changeset
|
25 /** |
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
diff
changeset
|
26 * @author Domenico Nardi Tironi |
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
diff
changeset
|
27 * |
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
diff
changeset
|
28 */ |
9481 | 29 public class UedauernConfiguration { |
9178
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
diff
changeset
|
30 |
9481 | 31 public final static class WmsConfig { |
32 private final String label; | |
33 private final String url; | |
9559
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
34 private final String layer_default; |
9619 | 35 private final String legend_image; |
9178
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
diff
changeset
|
36 |
9619 | 37 public WmsConfig(final String label, final String url, final String layer, final String legendImage) { |
9481 | 38 this.label = label; |
39 this.url = url; | |
9559
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
40 this.layer_default = layer; |
9619 | 41 this.legend_image = legendImage; |
9178
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
diff
changeset
|
42 } |
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
diff
changeset
|
43 |
9481 | 44 public String getLabel() { |
45 return this.label; | |
46 } | |
9178
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
diff
changeset
|
47 |
9481 | 48 public String getUrl() { |
49 return this.url; | |
9198 | 50 } |
9481 | 51 |
52 public String getLayer() { | |
9559
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
53 return this.layer_default; |
9198 | 54 } |
9619 | 55 |
56 public String getLegend() { | |
57 return this.legend_image; | |
58 } | |
9178
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
diff
changeset
|
59 } |
9184 | 60 |
9481 | 61 public static enum YearType { |
9559
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
62 jahre, mittel, szenario |
9184 | 63 } |
64 | |
9559
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
65 private final int DEFAULT_WMS_INDEX = 0; |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
66 private final int VEGETATIONZONE_WMS_INDEX = 1; |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
67 |
9481 | 68 private static Map<String, UedauernConfiguration> cache = new HashMap<>(); |
69 | |
9559
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
70 private final Map<String, WmsConfig[]> wmsConfigs; |
9481 | 71 |
72 public static synchronized UedauernConfiguration getInstance(final String rivername, final YearType type) throws IOException, TsvReaderException { | |
73 | |
74 final String cacheKey = type.name() + "#" + rivername; | |
75 if (!cache.containsKey(cacheKey)) { | |
76 final UedauernConfiguration instance = loadConfiguration(rivername, type); | |
77 cache.put(cacheKey, instance); | |
78 } | |
79 | |
80 return cache.get(cacheKey); | |
9184 | 81 } |
9481 | 82 |
9559
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
83 private UedauernConfiguration(final String rivername, final YearType type, final Map<String, WmsConfig[]> wmsConfigs) { |
9481 | 84 this.wmsConfigs = wmsConfigs; |
85 } | |
86 | |
87 private static UedauernConfiguration loadConfiguration(final String rivername, final YearType type) throws IOException, TsvReaderException { | |
88 | |
89 final String configFile = makeFileName(rivername, type); | |
90 final File file = TsvHelper.makeFile2(configFile, rivername); | |
9619 | 91 final List<String[]> tsv = TsvHelper.readTsv(file, 7); // changed to 7 |
9481 | 92 |
9559
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
93 final Map<String, WmsConfig[]> wmsConfigs = new LinkedHashMap<>(tsv.size()); |
9481 | 94 |
95 for (final String[] line : tsv) { | |
9559
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
96 if (line != null && line.length > 0 && !StringUtils.isEmpty(line[0])) { |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
97 final String label = line[0]; |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
98 WmsConfig defaultConfig = null; |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
99 WmsConfig vegZoneConfig = null; |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
100 |
9619 | 101 if (line.length > 3 && !StringUtils.isEmpty(line[1]) && !StringUtils.isEmpty(line[2]) && !StringUtils.isEmpty(line[3])) { |
102 defaultConfig = new WmsConfig(label, line[2], line[1], line[3]); | |
9559
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
103 |
9619 | 104 if (line.length > 6 && !StringUtils.isEmpty(line[4]) && !StringUtils.isEmpty(line[5]) && !StringUtils.isEmpty(line[6])) { |
105 vegZoneConfig = new WmsConfig(label, line[5], line[4], line[6]); | |
9559
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
106 } |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
107 } |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
108 wmsConfigs.put(label, new WmsConfig[] { defaultConfig, vegZoneConfig }); |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
109 } |
9481 | 110 } |
111 return new UedauernConfiguration(rivername, type, wmsConfigs); | |
112 } | |
113 | |
114 private static final String makeFileName(final String river, final YearType type) { | |
115 return "wms_uedauern_" + String.valueOf(type) + "_" + river + ".tsv"; | |
116 } | |
117 | |
118 public Collection<String> getLabels() throws UnsupportedEncodingException { | |
119 return this.wmsConfigs.keySet(); | |
120 } | |
121 | |
9559
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
122 public WmsConfig getDefaultWmsConfig(final String label) { |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
123 return this.getConfig(label, this.DEFAULT_WMS_INDEX); |
9481 | 124 } |
125 | |
9559
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
126 public WmsConfig getVegWmsConfig(final String label) { |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
127 return this.getConfig(label, this.VEGETATIONZONE_WMS_INDEX); |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
128 } |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
129 |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
130 private WmsConfig getConfig(final String label, final int index) { |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
131 if (this.wmsConfigs.containsKey(label)) |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
132 if (this.wmsConfigs.get(label) != null && index < this.wmsConfigs.get(label).length) |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
133 return this.wmsConfigs.get(label)[index]; |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
134 |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
135 return null; |
9481 | 136 } |
137 | |
138 public static boolean filesExistsForRiver(final String river) { | |
139 | |
9559
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
140 for (final YearType t : YearType.values()) { |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
141 final String configFile = makeFileName(river, t); |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
142 final File file = TsvHelper.makeFile2(configFile, river); |
9481 | 143 |
9559
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
144 if (TsvHelper.checkFile(file) == null) |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
145 return false; |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
146 } |
9481 | 147 |
148 return true; | |
149 } | |
150 | |
9178
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
diff
changeset
|
151 } |