Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/importer/sinfo/SInfoImporter.java @ 8971:50416a0df385
Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
author | mschaefer |
---|---|
date | Tue, 03 Apr 2018 10:18:30 +0200 |
parents | |
children | d046997281bc |
comparison
equal
deleted
inserted
replaced
8970:da5dc7446652 | 8971:50416a0df385 |
---|---|
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.importer.sinfo; | |
12 | |
13 import java.io.File; | |
14 import java.io.IOException; | |
15 import java.util.ArrayList; | |
16 import java.util.List; | |
17 | |
18 import org.apache.log4j.Logger; | |
19 import org.dive4elements.river.importer.ImportRiver; | |
20 import org.dive4elements.river.importer.common.ImportParser; | |
21 import org.dive4elements.river.importer.sinfo.parsers.BedMobilityParser; | |
22 import org.dive4elements.river.importer.sinfo.parsers.ChannelParser; | |
23 import org.dive4elements.river.importer.sinfo.parsers.CollisionParser; | |
24 import org.dive4elements.river.importer.sinfo.parsers.DailyDischargeParser; | |
25 import org.dive4elements.river.importer.sinfo.parsers.DepthEvolutionParser; | |
26 import org.dive4elements.river.importer.sinfo.parsers.FlowDepthParser; | |
27 import org.dive4elements.river.importer.sinfo.parsers.InfrastructureParser; | |
28 import org.dive4elements.river.importer.sinfo.parsers.SelectedAdditionalParser; | |
29 import org.dive4elements.river.importer.sinfo.parsers.TkhParser; | |
30 | |
31 /** | |
32 * Import all S-INFO files of a river from its import directory and subdirectories<br /> | |
33 * <br /> | |
34 * Requires river and its gauges to exist in the database already | |
35 * | |
36 * @author Matthias Schäfer | |
37 * | |
38 */ | |
39 public class SInfoImporter | |
40 { | |
41 /***** FIELDS *****/ | |
42 | |
43 private static final Logger log = Logger.getLogger(SInfoImporter.class); | |
44 | |
45 private static final String SINFO_DIR = "Schifffahrt"; | |
46 | |
47 private enum SInfoDirName { | |
48 BASICS("Basisdaten"), // | |
49 SELECTED_ADDITIONAL("Selektierte_Zusaetzliche_Laengsschnitte"), // | |
50 INFRASTRUCTURE("Infrastrukturen_BWaStr"), // | |
51 CHANNEL("Fahrrinnenverhaeltnisse"), // | |
52 COLLISION_EINZEL("Grundberuehrungen" + File.separator + "Einzeljahre"), // | |
53 COLLISION_EPOCHE("Grundberuehrungen" + File.separator + "Epoche"), // | |
54 TKH_EINZEL("Transportkoerperhoehen" + File.separator + "Einzeljahre"), // | |
55 TKH_EPOCHE("Transportkoerperhoehen" + File.separator + "Epochen"), // | |
56 TKH_MODELL("Transportkoerperhoehen" + File.separator + "Modellergebnisse"), // | |
57 FLOW_DEPTH("Modellierte_Datensaetze" + File.separator + "Fliesstiefen"), // | |
58 DEPTH_EVOLUTION_AKTUELL("Fliesstiefenentwicklung" + File.separator + "Bezug_aktueller_GlW"), // | |
59 DEPTH_EVOLUTION_ETAPPEN("Fliesstiefenentwicklung" + File.separator + "GlW-Etappen"); | |
60 | |
61 private final String dirname; | |
62 | |
63 SInfoDirName(final String dirname) { | |
64 this.dirname = dirname; | |
65 } | |
66 | |
67 public String getDir() { | |
68 return this.dirname; | |
69 } | |
70 public File getFile() { | |
71 return new File(getDir()); | |
72 } | |
73 | |
74 public File buildPath(final File rootDir) { | |
75 return new File(rootDir, getDir()); | |
76 } | |
77 } | |
78 | |
79 /** | |
80 * Series of river's stations with bed mobility flag. | |
81 */ | |
82 private final List<ImportParser> parsers; | |
83 | |
84 /** | |
85 * Path of the S-INFO data directory of the importing river. | |
86 */ | |
87 private File rootDir; | |
88 | |
89 | |
90 /***** CONSTRUCTOR *****/ | |
91 | |
92 public SInfoImporter() { | |
93 this.parsers = new ArrayList<>(); | |
94 } | |
95 | |
96 /***** METHODS *****/ | |
97 | |
98 /** | |
99 * Inits the parser list regarding the skip flags. | |
100 */ | |
101 public void setup(final File riverDir, final ImportRiver river) { | |
102 this.rootDir = new File(riverDir, SINFO_DIR); | |
103 log.info("Parse S-INFO files from " + this.rootDir); | |
104 this.parsers.clear(); | |
105 if (!BedMobilityParser.shallSkip()) { | |
106 if (!this.parsers.addAll(BedMobilityParser.createParsers(SInfoDirName.BASICS.buildPath(this.rootDir), SInfoDirName.BASICS.getFile(), river))) | |
107 log.info("Bed mobility: no files found"); | |
108 } | |
109 else { | |
110 log.info("Bed mobility: skipped"); | |
111 } | |
112 if (!SelectedAdditionalParser.shallSkip()) { | |
113 if (!this.parsers.addAll(SelectedAdditionalParser.createParsers(SInfoDirName.SELECTED_ADDITIONAL.buildPath(this.rootDir), | |
114 SInfoDirName.SELECTED_ADDITIONAL.getFile(), river))) | |
115 log.info("Selected additionals: no files found"); | |
116 } | |
117 else { | |
118 log.info("Selected additionals: skipped"); | |
119 } | |
120 if (!InfrastructureParser.shallSkip()) { | |
121 if (!this.parsers.addAll(InfrastructureParser.createParsers(SInfoDirName.INFRASTRUCTURE.buildPath(this.rootDir), | |
122 SInfoDirName.INFRASTRUCTURE.getFile(), river))) | |
123 log.info("Infrastructure: no files found"); | |
124 } | |
125 else { | |
126 log.info("Infrastructure: skipped"); | |
127 } | |
128 if (!ChannelParser.shallSkip()) { | |
129 if (!this.parsers.addAll(ChannelParser.createParsers(SInfoDirName.CHANNEL.buildPath(this.rootDir), SInfoDirName.CHANNEL.getFile(), river))) | |
130 log.info("Channel: no files found"); | |
131 } | |
132 else { | |
133 log.info("Channel: skipped"); | |
134 } | |
135 if (!CollisionParser.shallSkip()) { | |
136 boolean added = false; | |
137 added = this.parsers.addAll(CollisionParser.createParsers(SInfoDirName.COLLISION_EINZEL.buildPath(this.rootDir), | |
138 SInfoDirName.COLLISION_EINZEL.getFile(), river)); | |
139 added |= this.parsers.addAll(CollisionParser.createParsers(SInfoDirName.COLLISION_EPOCHE.buildPath(this.rootDir), | |
140 SInfoDirName.COLLISION_EPOCHE.getFile(), river)); | |
141 if (!added) | |
142 log.info("Collision: no files found"); | |
143 } | |
144 else { | |
145 log.info("Collision: skipped"); | |
146 } | |
147 if (!DailyDischargeParser.shallSkip()) { | |
148 if (!this.parsers.addAll(DailyDischargeParser.createParsers(SInfoDirName.BASICS.buildPath(this.rootDir), SInfoDirName.BASICS.getFile(), river))) | |
149 log.info("Daily discharge: no files found"); | |
150 } | |
151 else { | |
152 log.info("Daily discharge: skipped"); | |
153 } | |
154 if (!TkhParser.shallSkip()) { | |
155 boolean added = false; | |
156 added = this.parsers.addAll(TkhParser.createParsers(SInfoDirName.TKH_EINZEL.buildPath(this.rootDir), | |
157 SInfoDirName.TKH_EINZEL.getFile(), river)); | |
158 added |= this.parsers.addAll(TkhParser.createParsers(SInfoDirName.TKH_EPOCHE.buildPath(this.rootDir), | |
159 SInfoDirName.TKH_EPOCHE.getFile(), river)); | |
160 added |= this.parsers.addAll(TkhParser.createParsers(SInfoDirName.TKH_MODELL.buildPath(this.rootDir), | |
161 SInfoDirName.TKH_MODELL.getFile(), river)); | |
162 if (!added) | |
163 log.info("Tkh: no files found"); | |
164 } | |
165 else { | |
166 log.info("Tkh: skipped"); | |
167 } | |
168 if (!FlowDepthParser.shallSkip()) { | |
169 if (!this.parsers.addAll(FlowDepthParser.createParsers(SInfoDirName.FLOW_DEPTH.buildPath(this.rootDir), SInfoDirName.FLOW_DEPTH.getFile(), river))) | |
170 log.info("FlowDepth: no files found"); | |
171 } | |
172 else { | |
173 log.info("FlowDepth: skipped"); | |
174 } | |
175 if (!DepthEvolutionParser.shallSkip()) { | |
176 boolean added = false; | |
177 added = this.parsers.addAll(DepthEvolutionParser.createParsers(SInfoDirName.DEPTH_EVOLUTION_AKTUELL.buildPath(this.rootDir), | |
178 SInfoDirName.DEPTH_EVOLUTION_AKTUELL.getFile(), river)); | |
179 added |= this.parsers.addAll(DepthEvolutionParser.createParsers(SInfoDirName.DEPTH_EVOLUTION_ETAPPEN.buildPath(this.rootDir), | |
180 SInfoDirName.DEPTH_EVOLUTION_ETAPPEN.getFile(), river)); | |
181 if (!added) | |
182 log.info("Depth evolution: no files found"); | |
183 } | |
184 else { | |
185 log.info("Depth evolution: skipped"); | |
186 } | |
187 } | |
188 | |
189 /** | |
190 * Imports the files according to the active parser list | |
191 */ | |
192 public void parse() throws IOException { | |
193 for (final ImportParser parser : this.parsers) | |
194 parser.parse(); | |
195 } | |
196 | |
197 /** | |
198 * Stores all pending import objects | |
199 */ | |
200 public void store() { | |
201 for (final ImportParser parser : this.parsers) | |
202 parser.store(); | |
203 } | |
204 | |
205 } |