Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/UedauernConfiguration.java @ 9559:ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
author | gernotbelger |
---|---|
date | Wed, 24 Oct 2018 18:40:38 +0200 |
parents | 787fc085459b |
children | 63bbd5e45839 |
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; |
9178
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
diff
changeset
|
35 |
9481 | 36 public WmsConfig(final String label, final String url, final String layer) { |
37 this.label = label; | |
38 this.url = url; | |
9559
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
39 this.layer_default = layer; |
9178
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
diff
changeset
|
40 } |
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
diff
changeset
|
41 |
9481 | 42 public String getLabel() { |
43 return this.label; | |
44 } | |
9178
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
diff
changeset
|
45 |
9481 | 46 public String getUrl() { |
47 return this.url; | |
9198 | 48 } |
9481 | 49 |
50 public String getLayer() { | |
9559
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
51 return this.layer_default; |
9198 | 52 } |
9178
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
diff
changeset
|
53 } |
9184 | 54 |
9481 | 55 public static enum YearType { |
9559
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
56 jahre, mittel, szenario |
9184 | 57 } |
58 | |
9559
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
59 private final int DEFAULT_WMS_INDEX = 0; |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
60 private final int VEGETATIONZONE_WMS_INDEX = 1; |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
61 |
9481 | 62 private static Map<String, UedauernConfiguration> cache = new HashMap<>(); |
63 | |
9559
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
64 private final Map<String, WmsConfig[]> wmsConfigs; |
9481 | 65 |
66 public static synchronized UedauernConfiguration getInstance(final String rivername, final YearType type) throws IOException, TsvReaderException { | |
67 | |
68 final String cacheKey = type.name() + "#" + rivername; | |
69 if (!cache.containsKey(cacheKey)) { | |
70 final UedauernConfiguration instance = loadConfiguration(rivername, type); | |
71 cache.put(cacheKey, instance); | |
72 } | |
73 | |
74 return cache.get(cacheKey); | |
9184 | 75 } |
9481 | 76 |
9559
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
77 private UedauernConfiguration(final String rivername, final YearType type, final Map<String, WmsConfig[]> wmsConfigs) { |
9481 | 78 this.wmsConfigs = wmsConfigs; |
79 } | |
80 | |
81 private static UedauernConfiguration loadConfiguration(final String rivername, final YearType type) throws IOException, TsvReaderException { | |
82 | |
83 final String configFile = makeFileName(rivername, type); | |
84 final File file = TsvHelper.makeFile2(configFile, rivername); | |
9559
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
85 final List<String[]> tsv = TsvHelper.readTsv(file, 5); |
9481 | 86 |
9559
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
87 final Map<String, WmsConfig[]> wmsConfigs = new LinkedHashMap<>(tsv.size()); |
9481 | 88 |
89 for (final String[] line : tsv) { | |
9559
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
90 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
|
91 final String label = line[0]; |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
92 WmsConfig defaultConfig = null; |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
93 WmsConfig vegZoneConfig = null; |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
94 |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
95 if (line.length > 2 && !StringUtils.isEmpty(line[1]) && !StringUtils.isEmpty(line[2])) { |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
96 defaultConfig = new WmsConfig(label, line[2], line[1]); |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
97 |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
98 if (line.length > 4 && !StringUtils.isEmpty(line[3]) && !StringUtils.isEmpty(line[4])) { |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
99 vegZoneConfig = new WmsConfig(label, line[4], line[3]); |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
100 } |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
101 } |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
102 wmsConfigs.put(label, new WmsConfig[] { defaultConfig, vegZoneConfig }); |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
103 } |
9481 | 104 } |
105 return new UedauernConfiguration(rivername, type, wmsConfigs); | |
106 } | |
107 | |
108 private static final String makeFileName(final String river, final YearType type) { | |
109 return "wms_uedauern_" + String.valueOf(type) + "_" + river + ".tsv"; | |
110 } | |
111 | |
112 public Collection<String> getLabels() throws UnsupportedEncodingException { | |
113 return this.wmsConfigs.keySet(); | |
114 } | |
115 | |
9559
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
116 public WmsConfig getDefaultWmsConfig(final String label) { |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
117 return this.getConfig(label, this.DEFAULT_WMS_INDEX); |
9481 | 118 } |
119 | |
9559
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
120 public WmsConfig getVegWmsConfig(final String label) { |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
121 return this.getConfig(label, this.VEGETATIONZONE_WMS_INDEX); |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
122 } |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
123 |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
124 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
|
125 if (this.wmsConfigs.containsKey(label)) |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
126 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
|
127 return this.wmsConfigs.get(label)[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 return null; |
9481 | 130 } |
131 | |
132 public static boolean filesExistsForRiver(final String river) { | |
133 | |
9559
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
134 for (final YearType t : YearType.values()) { |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
135 final String configFile = makeFileName(river, t); |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
136 final File file = TsvHelper.makeFile2(configFile, river); |
9481 | 137 |
9559
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
138 if (TsvHelper.checkFile(file) == null) |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
139 return false; |
ba0561906f81
Uinfo inundation duration workflow (vegetation zones, scenario), wms-config changed
gernotbelger
parents:
9481
diff
changeset
|
140 } |
9481 | 141 |
142 return true; | |
143 } | |
144 | |
9178
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
diff
changeset
|
145 } |