Mercurial > dive4elements > river
comparison 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 |
comparison
equal
deleted
inserted
replaced
9558:709a73badd48 | 9559:ba0561906f81 |
---|---|
16 import java.util.HashMap; | 16 import java.util.HashMap; |
17 import java.util.LinkedHashMap; | 17 import java.util.LinkedHashMap; |
18 import java.util.List; | 18 import java.util.List; |
19 import java.util.Map; | 19 import java.util.Map; |
20 | 20 |
21 import org.apache.commons.lang.StringUtils; | |
21 import org.dive4elements.river.artifacts.sinfo.tkhstate.TsvHelper; | 22 import org.dive4elements.river.artifacts.sinfo.tkhstate.TsvHelper; |
22 import org.dive4elements.river.artifacts.sinfo.tkhstate.TsvHelper.TsvReaderException; | 23 import org.dive4elements.river.artifacts.sinfo.tkhstate.TsvHelper.TsvReaderException; |
23 | 24 |
24 /** | 25 /** |
25 * @author Domenico Nardi Tironi | 26 * @author Domenico Nardi Tironi |
28 public class UedauernConfiguration { | 29 public class UedauernConfiguration { |
29 | 30 |
30 public final static class WmsConfig { | 31 public final static class WmsConfig { |
31 private final String label; | 32 private final String label; |
32 private final String url; | 33 private final String url; |
33 private final String layer; | 34 private final String layer_default; |
34 | 35 |
35 public WmsConfig(final String label, final String url, final String layer) { | 36 public WmsConfig(final String label, final String url, final String layer) { |
36 this.label = label; | 37 this.label = label; |
37 this.url = url; | 38 this.url = url; |
38 this.layer = layer; | 39 this.layer_default = layer; |
39 } | 40 } |
40 | 41 |
41 public String getLabel() { | 42 public String getLabel() { |
42 return this.label; | 43 return this.label; |
43 } | 44 } |
45 public String getUrl() { | 46 public String getUrl() { |
46 return this.url; | 47 return this.url; |
47 } | 48 } |
48 | 49 |
49 public String getLayer() { | 50 public String getLayer() { |
50 return this.layer; | 51 return this.layer_default; |
51 } | 52 } |
52 } | 53 } |
53 | 54 |
54 public static enum YearType { | 55 public static enum YearType { |
55 jahre, mittel | 56 jahre, mittel, szenario |
56 } | 57 } |
58 | |
59 private final int DEFAULT_WMS_INDEX = 0; | |
60 private final int VEGETATIONZONE_WMS_INDEX = 1; | |
57 | 61 |
58 private static Map<String, UedauernConfiguration> cache = new HashMap<>(); | 62 private static Map<String, UedauernConfiguration> cache = new HashMap<>(); |
59 | 63 |
60 private final Map<String, WmsConfig> wmsConfigs; | 64 private final Map<String, WmsConfig[]> wmsConfigs; |
61 | 65 |
62 public static synchronized UedauernConfiguration getInstance(final String rivername, final YearType type) throws IOException, TsvReaderException { | 66 public static synchronized UedauernConfiguration getInstance(final String rivername, final YearType type) throws IOException, TsvReaderException { |
63 | 67 |
64 final String cacheKey = type.name() + "#" + rivername; | 68 final String cacheKey = type.name() + "#" + rivername; |
65 if (!cache.containsKey(cacheKey)) { | 69 if (!cache.containsKey(cacheKey)) { |
68 } | 72 } |
69 | 73 |
70 return cache.get(cacheKey); | 74 return cache.get(cacheKey); |
71 } | 75 } |
72 | 76 |
73 private UedauernConfiguration(final String rivername, final YearType type, final Map<String, WmsConfig> wmsConfigs) { | 77 private UedauernConfiguration(final String rivername, final YearType type, final Map<String, WmsConfig[]> wmsConfigs) { |
74 this.wmsConfigs = wmsConfigs; | 78 this.wmsConfigs = wmsConfigs; |
75 } | 79 } |
76 | 80 |
77 private static UedauernConfiguration loadConfiguration(final String rivername, final YearType type) throws IOException, TsvReaderException { | 81 private static UedauernConfiguration loadConfiguration(final String rivername, final YearType type) throws IOException, TsvReaderException { |
78 | 82 |
79 final String configFile = makeFileName(rivername, type); | 83 final String configFile = makeFileName(rivername, type); |
80 final File file = TsvHelper.makeFile2(configFile, rivername); | 84 final File file = TsvHelper.makeFile2(configFile, rivername); |
81 final List<String[]> tsv = TsvHelper.readTsv(file, 3); | 85 final List<String[]> tsv = TsvHelper.readTsv(file, 5); |
82 | 86 |
83 final Map<String, WmsConfig> wmsConfigs = new LinkedHashMap<>(tsv.size()); | 87 final Map<String, WmsConfig[]> wmsConfigs = new LinkedHashMap<>(tsv.size()); |
84 | 88 |
85 for (final String[] line : tsv) { | 89 for (final String[] line : tsv) { |
86 final String label = line[0]; | 90 if (line != null && line.length > 0 && !StringUtils.isEmpty(line[0])) { |
87 wmsConfigs.put(label, new WmsConfig(label, line[2], line[1])); | 91 final String label = line[0]; |
92 WmsConfig defaultConfig = null; | |
93 WmsConfig vegZoneConfig = null; | |
94 | |
95 if (line.length > 2 && !StringUtils.isEmpty(line[1]) && !StringUtils.isEmpty(line[2])) { | |
96 defaultConfig = new WmsConfig(label, line[2], line[1]); | |
97 | |
98 if (line.length > 4 && !StringUtils.isEmpty(line[3]) && !StringUtils.isEmpty(line[4])) { | |
99 vegZoneConfig = new WmsConfig(label, line[4], line[3]); | |
100 } | |
101 } | |
102 wmsConfigs.put(label, new WmsConfig[] { defaultConfig, vegZoneConfig }); | |
103 } | |
88 } | 104 } |
89 | |
90 return new UedauernConfiguration(rivername, type, wmsConfigs); | 105 return new UedauernConfiguration(rivername, type, wmsConfigs); |
91 } | 106 } |
92 | 107 |
93 private static final String makeFileName(final String river, final YearType type) { | 108 private static final String makeFileName(final String river, final YearType type) { |
94 return "wms_uedauern_" + String.valueOf(type) + "_" + river + ".tsv"; | 109 return "wms_uedauern_" + String.valueOf(type) + "_" + river + ".tsv"; |
96 | 111 |
97 public Collection<String> getLabels() throws UnsupportedEncodingException { | 112 public Collection<String> getLabels() throws UnsupportedEncodingException { |
98 return this.wmsConfigs.keySet(); | 113 return this.wmsConfigs.keySet(); |
99 } | 114 } |
100 | 115 |
101 public final String getUrl(final String label) throws UnsupportedEncodingException { | 116 public WmsConfig getDefaultWmsConfig(final String label) { |
102 final WmsConfig wmsConfig = this.wmsConfigs.get(label); | 117 return this.getConfig(label, this.DEFAULT_WMS_INDEX); |
103 return wmsConfig.getUrl(); | |
104 } | 118 } |
105 | 119 |
106 public String getLayer(final String label) { | 120 public WmsConfig getVegWmsConfig(final String label) { |
107 final WmsConfig wmsConfig = this.wmsConfigs.get(label); | 121 return this.getConfig(label, this.VEGETATIONZONE_WMS_INDEX); |
108 return wmsConfig.getLayer(); | 122 } |
123 | |
124 private WmsConfig getConfig(final String label, final int index) { | |
125 if (this.wmsConfigs.containsKey(label)) | |
126 if (this.wmsConfigs.get(label) != null && index < this.wmsConfigs.get(label).length) | |
127 return this.wmsConfigs.get(label)[index]; | |
128 | |
129 return null; | |
109 } | 130 } |
110 | 131 |
111 public static boolean filesExistsForRiver(final String river) { | 132 public static boolean filesExistsForRiver(final String river) { |
112 | 133 |
113 final String configFileYears = makeFileName(river, YearType.jahre); | 134 for (final YearType t : YearType.values()) { |
135 final String configFile = makeFileName(river, t); | |
136 final File file = TsvHelper.makeFile2(configFile, river); | |
114 | 137 |
115 final File fileJahre = TsvHelper.makeFile2(configFileYears, river); | 138 if (TsvHelper.checkFile(file) == null) |
139 return false; | |
140 } | |
116 | 141 |
117 final String configFileMittel = makeFileName(river, YearType.mittel); | |
118 final File fileMittel = TsvHelper.makeFile2(configFileMittel, river); | |
119 | |
120 if (TsvHelper.checkFile(fileJahre) == null || TsvHelper.checkFile(fileMittel) == null) | |
121 return false; | |
122 return true; | 142 return true; |
123 } | 143 } |
124 | 144 |
125 } | 145 } |