Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/UedauernConfiguration.java @ 9481:787fc085459b
TSV introduced; uinfo.inundationWMS-Config
author | gernotbelger |
---|---|
date | Wed, 12 Sep 2018 10:55:09 +0200 |
parents | artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/UedauernPropertiesHelper.java@6acd22e86951 |
children | ba0561906f81 |
comparison
equal
deleted
inserted
replaced
9480:7228bd10a8cc | 9481:787fc085459b |
---|---|
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 package org.dive4elements.river.artifacts.uinfo.inundationduration; | |
11 | |
12 import java.io.File; | |
13 import java.io.IOException; | |
14 import java.io.UnsupportedEncodingException; | |
15 import java.util.Collection; | |
16 import java.util.HashMap; | |
17 import java.util.LinkedHashMap; | |
18 import java.util.List; | |
19 import java.util.Map; | |
20 | |
21 import org.dive4elements.river.artifacts.sinfo.tkhstate.TsvHelper; | |
22 import org.dive4elements.river.artifacts.sinfo.tkhstate.TsvHelper.TsvReaderException; | |
23 | |
24 /** | |
25 * @author Domenico Nardi Tironi | |
26 * | |
27 */ | |
28 public class UedauernConfiguration { | |
29 | |
30 public final static class WmsConfig { | |
31 private final String label; | |
32 private final String url; | |
33 private final String layer; | |
34 | |
35 public WmsConfig(final String label, final String url, final String layer) { | |
36 this.label = label; | |
37 this.url = url; | |
38 this.layer = layer; | |
39 } | |
40 | |
41 public String getLabel() { | |
42 return this.label; | |
43 } | |
44 | |
45 public String getUrl() { | |
46 return this.url; | |
47 } | |
48 | |
49 public String getLayer() { | |
50 return this.layer; | |
51 } | |
52 } | |
53 | |
54 public static enum YearType { | |
55 jahre, mittel | |
56 } | |
57 | |
58 private static Map<String, UedauernConfiguration> cache = new HashMap<>(); | |
59 | |
60 private final Map<String, WmsConfig> wmsConfigs; | |
61 | |
62 public static synchronized UedauernConfiguration getInstance(final String rivername, final YearType type) throws IOException, TsvReaderException { | |
63 | |
64 final String cacheKey = type.name() + "#" + rivername; | |
65 if (!cache.containsKey(cacheKey)) { | |
66 final UedauernConfiguration instance = loadConfiguration(rivername, type); | |
67 cache.put(cacheKey, instance); | |
68 } | |
69 | |
70 return cache.get(cacheKey); | |
71 } | |
72 | |
73 private UedauernConfiguration(final String rivername, final YearType type, final Map<String, WmsConfig> wmsConfigs) { | |
74 this.wmsConfigs = wmsConfigs; | |
75 } | |
76 | |
77 private static UedauernConfiguration loadConfiguration(final String rivername, final YearType type) throws IOException, TsvReaderException { | |
78 | |
79 final String configFile = makeFileName(rivername, type); | |
80 final File file = TsvHelper.makeFile2(configFile, rivername); | |
81 final List<String[]> tsv = TsvHelper.readTsv(file, 3); | |
82 | |
83 final Map<String, WmsConfig> wmsConfigs = new LinkedHashMap<>(tsv.size()); | |
84 | |
85 for (final String[] line : tsv) { | |
86 final String label = line[0]; | |
87 wmsConfigs.put(label, new WmsConfig(label, line[2], line[1])); | |
88 } | |
89 | |
90 return new UedauernConfiguration(rivername, type, wmsConfigs); | |
91 } | |
92 | |
93 private static final String makeFileName(final String river, final YearType type) { | |
94 return "wms_uedauern_" + String.valueOf(type) + "_" + river + ".tsv"; | |
95 } | |
96 | |
97 public Collection<String> getLabels() throws UnsupportedEncodingException { | |
98 return this.wmsConfigs.keySet(); | |
99 } | |
100 | |
101 public final String getUrl(final String label) throws UnsupportedEncodingException { | |
102 final WmsConfig wmsConfig = this.wmsConfigs.get(label); | |
103 return wmsConfig.getUrl(); | |
104 } | |
105 | |
106 public String getLayer(final String label) { | |
107 final WmsConfig wmsConfig = this.wmsConfigs.get(label); | |
108 return wmsConfig.getLayer(); | |
109 } | |
110 | |
111 public static boolean filesExistsForRiver(final String river) { | |
112 | |
113 final String configFileYears = makeFileName(river, YearType.jahre); | |
114 | |
115 final File fileJahre = TsvHelper.makeFile2(configFileYears, river); | |
116 | |
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; | |
123 } | |
124 | |
125 } |