comparison backend/src/main/java/org/dive4elements/river/importer/ImportRiver.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 5e38e2924c07
children ae76f618d990
comparison
equal deleted inserted replaced
8970:da5dc7446652 8971:50416a0df385
6 * documentation coming with Dive4Elements River for details. 6 * documentation coming with Dive4Elements River for details.
7 */ 7 */
8 8
9 package org.dive4elements.river.importer; 9 package org.dive4elements.river.importer;
10 10
11 import java.io.File;
12 import java.io.FilenameFilter;
13 import java.io.IOException;
14 import java.util.ArrayList;
15 import java.util.Calendar;
16 import java.util.Date;
17 import java.util.HashSet;
18 import java.util.Iterator;
19 import java.util.List;
20 import java.util.Map;
21 import java.util.Set;
22
23 import org.apache.log4j.Logger;
24 import org.dive4elements.artifacts.common.utils.FileTools;
11 import org.dive4elements.artifacts.common.utils.FileTools.HashedFile; 25 import org.dive4elements.artifacts.common.utils.FileTools.HashedFile;
12 26 import org.dive4elements.river.backend.utils.DouglasPeuker;
13 import org.dive4elements.artifacts.common.utils.FileTools; 27 import org.dive4elements.river.importer.parsers.AbstractSedimentLoadParser;
14
15 import org.dive4elements.river.importer.parsers.AnnotationClassifier; 28 import org.dive4elements.river.importer.parsers.AnnotationClassifier;
16 import org.dive4elements.river.importer.parsers.AnnotationsParser; 29 import org.dive4elements.river.importer.parsers.AnnotationsParser;
17 import org.dive4elements.river.importer.parsers.BedHeightParser; 30 import org.dive4elements.river.importer.parsers.BedHeightParser;
18 import org.dive4elements.river.importer.parsers.CrossSectionParser; 31 import org.dive4elements.river.importer.parsers.CrossSectionParser;
19 import org.dive4elements.river.importer.parsers.DA50Parser; 32 import org.dive4elements.river.importer.parsers.DA50Parser;
27 import org.dive4elements.river.importer.parsers.PRFParser; 40 import org.dive4elements.river.importer.parsers.PRFParser;
28 import org.dive4elements.river.importer.parsers.PegelGltParser; 41 import org.dive4elements.river.importer.parsers.PegelGltParser;
29 import org.dive4elements.river.importer.parsers.PorosityParser; 42 import org.dive4elements.river.importer.parsers.PorosityParser;
30 import org.dive4elements.river.importer.parsers.SQRelationParser; 43 import org.dive4elements.river.importer.parsers.SQRelationParser;
31 import org.dive4elements.river.importer.parsers.SedimentDensityParser; 44 import org.dive4elements.river.importer.parsers.SedimentDensityParser;
32 import org.dive4elements.river.importer.parsers.AbstractSedimentLoadParser;
33 import org.dive4elements.river.importer.parsers.SedimentLoadLSParser; 45 import org.dive4elements.river.importer.parsers.SedimentLoadLSParser;
34 import org.dive4elements.river.importer.parsers.SedimentLoadParser; 46 import org.dive4elements.river.importer.parsers.SedimentLoadParser;
47 import org.dive4elements.river.importer.parsers.W80CSVParser;
35 import org.dive4elements.river.importer.parsers.W80Parser; 48 import org.dive4elements.river.importer.parsers.W80Parser;
36 import org.dive4elements.river.importer.parsers.W80CSVParser;
37 import org.dive4elements.river.importer.parsers.WaterlevelDifferencesParser; 49 import org.dive4elements.river.importer.parsers.WaterlevelDifferencesParser;
38 import org.dive4elements.river.importer.parsers.WaterlevelParser; 50 import org.dive4elements.river.importer.parsers.WaterlevelParser;
39 import org.dive4elements.river.importer.parsers.WstParser; 51 import org.dive4elements.river.importer.parsers.WstParser;
40 52 import org.dive4elements.river.importer.sinfo.SInfoImporter;
53 import org.dive4elements.river.importer.uinfo.UInfoImporter;
41 import org.dive4elements.river.model.River; 54 import org.dive4elements.river.model.River;
42 import org.dive4elements.river.model.Unit; 55 import org.dive4elements.river.model.Unit;
43
44 import org.dive4elements.river.backend.utils.DouglasPeuker;
45
46 import java.io.File;
47 import java.io.IOException;
48
49 import java.util.ArrayList;
50 import java.util.Calendar;
51 import java.util.Date;
52 import java.util.HashSet;
53 import java.util.List;
54 import java.util.Map;
55 import java.util.Set;
56 import java.util.Iterator;
57
58 import org.apache.log4j.Logger;
59
60 import org.hibernate.Query; 56 import org.hibernate.Query;
61 import org.hibernate.Session; 57 import org.hibernate.Session;
62 58
63 /** Import all river-related data (files) that can be found. */ 59 /** Import all river-related data (files) that can be found. */
64 public class ImportRiver 60 public class ImportRiver
69 public static final String PEGEL_GLT = "PEGEL.GLT"; 65 public static final String PEGEL_GLT = "PEGEL.GLT";
70 66
71 public static final String FIXATIONS = "Fixierungen"; 67 public static final String FIXATIONS = "Fixierungen";
72 68
73 public static final String EXTRA_LONGITUDINALS = 69 public static final String EXTRA_LONGITUDINALS =
74 "Zus.Laengsschnitte"; 70 "Zus.Laengsschnitte";
75 71
76 public static final String [] OFFICIAL_LINES_FOLDERS = { 72 public static final String [] OFFICIAL_LINES_FOLDERS = {
77 "Basisdaten", 73 "Basisdaten",
78 "Fixierungen" }; 74 "Fixierungen" };
79 75
80 public static final String OFFICIAL_LINES = 76 public static final String OFFICIAL_LINES =
81 "Amtl_Linien.wst"; 77 "Amtl_Linien.wst";
82 78
83 public static final String OFFICIAL_LINES_CONFIG = 79 public static final String OFFICIAL_LINES_CONFIG =
84 "Amtl_Linien.config"; 80 "Amtl_Linien.config";
85 81
86 public static final String FLOOD_WATER = "HW-Marken"; 82 public static final String FLOOD_WATER = "HW-Marken";
87 83
88 public static final String FLOOD_PROTECTION = 84 public static final String FLOOD_PROTECTION =
89 "HW-Schutzanlagen"; 85 "HW-Schutzanlagen";
90 86
91 public static final String MINFO_DIR = "Morphologie"; 87 public static final String MINFO_DIR = "Morphologie";
92 88
93 public static final String BED_HEIGHT_DIR = "Sohlhoehen"; 89 public static final String BED_HEIGHT_DIR = "Sohlhoehen";
94 90
97 public static final String SEDIMENT_DENSITY_DIR = "Sedimentdichte"; 93 public static final String SEDIMENT_DENSITY_DIR = "Sedimentdichte";
98 94
99 public static final String POROSITY_DIR = "Porositaet"; 95 public static final String POROSITY_DIR = "Porositaet";
100 96
101 public static final String MORPHOLOGICAL_WIDTH_DIR = 97 public static final String MORPHOLOGICAL_WIDTH_DIR =
102 "morphologische_Breite"; 98 "morphologische_Breite";
103 99
104 public static final String FLOW_VELOCITY_DIR = 100 public static final String FLOW_VELOCITY_DIR =
105 "Geschwindigkeit_Schubspannung"; 101 "Geschwindigkeit_Schubspannung";
106 102
107 public static final String FLOW_VELOCITY_MODEL = "Modellrechnungen"; 103 public static final String FLOW_VELOCITY_MODEL = "Modellrechnungen";
108 104
109 public static final String FLOW_VELOCITY_MEASUREMENTS = "v-Messungen"; 105 public static final String FLOW_VELOCITY_MEASUREMENTS = "v-Messungen";
110 106
117 public static final String SEDIMENT_LOAD_SINGLE_DIR = "Einzeljahre"; 113 public static final String SEDIMENT_LOAD_SINGLE_DIR = "Einzeljahre";
118 114
119 public static final String SEDIMENT_LOAD_EPOCH_DIR = "Epochen"; 115 public static final String SEDIMENT_LOAD_EPOCH_DIR = "Epochen";
120 116
121 public static final String SEDIMENT_LOAD_OFF_EPOCH_DIR = 117 public static final String SEDIMENT_LOAD_OFF_EPOCH_DIR =
122 "amtliche Epochen"; 118 "amtliche Epochen";
123 119
124 public static final String MINFO_FIXATIONS_DIR = "Fixierungsanalyse"; 120 public static final String MINFO_FIXATIONS_DIR = "Fixierungsanalyse";
125 121
126 public static final String MINFO_WATERLEVELS_DIR = "Wasserspiegellagen"; 122 public static final String MINFO_WATERLEVELS_DIR = "Wasserspiegellagen";
127 123
128 public static final String MINFO_WATERLEVEL_DIFF_DIR = 124 public static final String MINFO_WATERLEVEL_DIFF_DIR =
129 "Wasserspiegeldifferenzen"; 125 "Wasserspiegeldifferenzen";
130 126
131 public static final String MINFO_BASE_DIR = "Basisdaten"; 127 public static final String MINFO_BASE_DIR = "Basisdaten";
132 128
133 public static final String MINFO_CORE_DATA_FILE = 129 public static final String MINFO_CORE_DATA_FILE =
134 "Stammdaten_Messstellen.csv"; 130 "Stammdaten_Messstellen.csv";
135 131
136 public static final String MINFO_SQ_DIR = 132 public static final String MINFO_SQ_DIR =
137 "Feststofftransport-Abfluss-Beziehung"; 133 "Feststofftransport-Abfluss-Beziehung";
138 134
139 protected String name; 135 protected String name;
140 136
141 protected String modelUuid; 137 protected String modelUuid;
142 138
143 protected Long officialNumber; 139 protected Long officialNumber;
144 140
141 /**
142 * Path of the river/Hydrologie/Basisdaten/river.wst file from which all other file paths are derived
143 */
145 protected File wstFile; 144 protected File wstFile;
146 145
147 protected File bbInfoFile; 146 protected File bbInfoFile;
148 147
149 protected List<ImportGauge> gauges; 148 protected List<ImportGauge> gauges;
197 protected AnnotationClassifier annotationClassifier; 196 protected AnnotationClassifier annotationClassifier;
198 197
199 /** Database-mapped River instance. */ 198 /** Database-mapped River instance. */
200 protected River peer; 199 protected River peer;
201 200
201 /**
202 * Importer for a river's S-INFO files.
203 */
204 private final SInfoImporter sinfoImporter;
205
206 /**
207 * Importer for a river's U-INFO files.
208 */
209 private final UInfoImporter uinfoImporter;
202 210
203 /** Callback-implementation for CrossSectionParsers. */ 211 /** Callback-implementation for CrossSectionParsers. */
204 private class ImportRiverCrossSectionParserCallback 212 private class ImportRiverCrossSectionParserCallback
205 implements CrossSectionParser.Callback { 213 implements CrossSectionParser.Callback {
206 214
207 private Set<HashedFile> files = new HashSet<HashedFile>(); 215 private final Set<HashedFile> files = new HashSet<>();
208 private String type; 216 private final String type;
209 217
210 /** 218 /**
211 * Create new Callback, given type which is used for logging 219 * Create new Callback, given type which is used for logging
212 * purposes only. 220 * purposes only.
213 */ 221 */
214 public ImportRiverCrossSectionParserCallback(String type) { 222 public ImportRiverCrossSectionParserCallback(final String type) {
215 this.type = type; 223 this.type = type;
216 } 224 }
217 225
218 226
219 /** Accept file if not duplicate. */ 227 /** Accept file if not duplicate. */
220 @Override 228 @Override
221 public boolean accept(File file) { 229 public boolean accept(final File file) {
222 HashedFile hf = new HashedFile(file); 230 final HashedFile hf = new HashedFile(file);
223 boolean success = files.add(hf); 231 final boolean success = this.files.add(hf);
224 if (!success) { 232 if (!success) {
225 log.warn(type + " file '" + file 233 log.warn(this.type + " file '" + file
226 + "' seems to be a duplicate."); 234 + "' seems to be a duplicate.");
227 } 235 }
228 return success; 236 return success;
229 } 237 }
230 238
231 239
232 /** Add crosssection. */ 240 /** Add crosssection. */
233 @Override 241 @Override
234 public void parsed(CrossSectionParser parser) { 242 public void parsed(final CrossSectionParser parser) {
235 log.debug("callback from " + type + " parser"); 243 log.debug("callback from " + this.type + " parser");
236 244
237 String description = parser.getDescription(); 245 final String description = parser.getDescription();
238 Integer year = parser.getYear(); 246 final Integer year = parser.getYear();
239 ImportTimeInterval ti = year != null 247 final ImportTimeInterval ti = year != null
240 ? new ImportTimeInterval(yearToDate(year)) 248 ? new ImportTimeInterval(yearToDate(year))
241 : null; 249 : null;
242 250
243 Map<Double, List<XY>> data = parser.getData(); 251 final Map<Double, List<XY>> data = parser.getData();
244 252
245 List<ImportCrossSectionLine> lines = 253 final List<ImportCrossSectionLine> lines =
246 new ArrayList<ImportCrossSectionLine>(data.size()); 254 new ArrayList<>(data.size());
247 255
248 Double simplificationEpsilon = 256 final Double simplificationEpsilon =
249 Config.INSTANCE.getCrossSectionSimplificationEpsilon(); 257 Config.INSTANCE.getCrossSectionSimplificationEpsilon();
250 258
251 long numReadPoints = 0L; 259 long numReadPoints = 0L;
252 long numRemainingPoints = 0L; 260 long numRemainingPoints = 0L;
253 261
254 for (Map.Entry<Double, List<XY>> entry: data.entrySet()) { 262 for (final Map.Entry<Double, List<XY>> entry: data.entrySet()) {
255 Double km = entry.getKey(); 263 final Double km = entry.getKey();
256 List<XY> points = entry.getValue(); 264 List<XY> points = entry.getValue();
257 numReadPoints += points.size(); 265 numReadPoints += points.size();
258 if (simplificationEpsilon != null) { 266 if (simplificationEpsilon != null) {
259 points = DouglasPeuker.simplify( 267 points = DouglasPeuker.simplify(
260 points, simplificationEpsilon); 268 points, simplificationEpsilon);
261 } 269 }
262 numRemainingPoints += points.size(); 270 numRemainingPoints += points.size();
263 lines.add(new ImportCrossSectionLine(km, points)); 271 lines.add(new ImportCrossSectionLine(km, points));
264 } 272 }
265 273
266 ImportRiver.this.addCrossSections(description, ti, lines); 274 ImportRiver.this.addCrossSections(description, ti, lines);
267 275
268 if (simplificationEpsilon != null) { 276 if (simplificationEpsilon != null) {
269 double percent = numReadPoints > 0L 277 final double percent = numReadPoints > 0L
270 ? ((double)numRemainingPoints/numReadPoints)*100d 278 ? ((double)numRemainingPoints/numReadPoints)*100d
271 : 0d; 279 : 0d;
272 280
273 log.info(String.format( 281 log.info(String.format(
274 "Number of points in cross section: %d / %d (%.2f%%)", 282 "Number of points in cross section: %d / %d (%.2f%%)",
275 numReadPoints, numRemainingPoints, percent)); 283 numReadPoints, numRemainingPoints, percent));
276 } 284 }
277 } 285 }
278 } // ImportRiverCrossSectionParserCallback 286 } // ImportRiverCrossSectionParserCallback
279 287
280 288
281 private void addCrossSections( 289 private void addCrossSections(
282 String description, 290 final String description,
283 ImportTimeInterval ti, 291 final ImportTimeInterval ti,
284 List<ImportCrossSectionLine> lines 292 final List<ImportCrossSectionLine> lines
285 ) { 293 ) {
286 crossSections.add( 294 this.crossSections.add(
287 new ImportCrossSection(this, description, ti, lines)); 295 new ImportCrossSection(this, description, ti, lines));
288 } 296 }
289 297
290 298
291 public ImportRiver() { 299 public ImportRiver() {
292 hyks = new ArrayList<ImportHYK>(); 300 this.hyks = new ArrayList<>();
293 crossSections = new ArrayList<ImportCrossSection>(); 301 this.crossSections = new ArrayList<>();
294 extraWsts = new ArrayList<ImportWst>(); 302 this.extraWsts = new ArrayList<>();
295 fixations = new ArrayList<ImportWst>(); 303 this.fixations = new ArrayList<>();
296 officialLines = new ArrayList<ImportWst>(); 304 this.officialLines = new ArrayList<>();
297 floodWater = new ArrayList<ImportWst>(); 305 this.floodWater = new ArrayList<>();
298 waterlevels = new ArrayList<ImportWst>(); 306 this.waterlevels = new ArrayList<>();
299 waterlevelDifferences = new ArrayList<ImportWst>(); 307 this.waterlevelDifferences = new ArrayList<>();
300 floodProtection = new ArrayList<ImportWst>(); 308 this.floodProtection = new ArrayList<>();
301 sedimentDensities = new ArrayList<ImportSedimentDensity>(); 309 this.sedimentDensities = new ArrayList<>();
302 porosities = new ArrayList<ImportPorosity>(); 310 this.porosities = new ArrayList<>();
303 morphologicalWidths = new ArrayList<ImportMorphWidth>(); 311 this.morphologicalWidths = new ArrayList<>();
304 flowVelocityModels = new ArrayList<ImportFlowVelocityModel>(); 312 this.flowVelocityModels = new ArrayList<>();
305 flowVelocityMeasurements = 313 this.flowVelocityMeasurements =
306 new ArrayList<ImportFlowVelocityMeasurement>(); 314 new ArrayList<>();
307 sedimentLoadLSs = new ArrayList<ImportSedimentLoadLS>(); 315 this.sedimentLoadLSs = new ArrayList<>();
308 sedimentLoads = new ArrayList<ImportSedimentLoad>(); 316 this.sedimentLoads = new ArrayList<>();
309 measurementStations = new ArrayList<ImportMeasurementStation>(); 317 this.measurementStations = new ArrayList<>();
310 sqRelations = new ArrayList<ImportSQRelation>(); 318 this.sqRelations = new ArrayList<>();
319 this.sinfoImporter = new SInfoImporter();
320 this.uinfoImporter = new UInfoImporter();
311 } 321 }
312 322
313 public ImportRiver( 323 public ImportRiver(
314 String name, 324 final String name,
315 String modelUuid, 325 final String modelUuid,
316 File wstFile, 326 final File wstFile,
317 File bbInfoFile, 327 final File bbInfoFile,
318 AnnotationClassifier annotationClassifier 328 final AnnotationClassifier annotationClassifier
319 ) { 329 ) {
320 this(); 330 this();
321 this.name = name; 331 this.name = name;
322 this.modelUuid = modelUuid; 332 this.modelUuid = modelUuid;
323 this.wstFile = wstFile; 333 this.wstFile = wstFile;
324 this.bbInfoFile = bbInfoFile; 334 this.bbInfoFile = bbInfoFile;
325 this.annotationClassifier = annotationClassifier; 335 this.annotationClassifier = annotationClassifier;
326 } 336 }
327 337
328 public String getName() { 338 public String getName() {
329 return name; 339 return this.name;
330 } 340 }
331 341
332 public void setName(String name) { 342 public void setName(final String name) {
333 this.name = name; 343 this.name = name;
334 } 344 }
335 345
336 public String getModelUuid() { 346 public String getModelUuid() {
337 return modelUuid; 347 return this.modelUuid;
338 } 348 }
339 349
340 public void setModelUuid(String modelUuid) { 350 public void setModelUuid(final String modelUuid) {
341 this.modelUuid = modelUuid; 351 this.modelUuid = modelUuid;
342 } 352 }
343 353
344 public Long getOfficialNumber() { 354 public Long getOfficialNumber() {
345 return this.officialNumber; 355 return this.officialNumber;
346 } 356 }
347 357
348 public void setOfficialNumber(Long officialNumber) { 358 public void setOfficialNumber(final Long officialNumber) {
349 this.officialNumber = officialNumber; 359 this.officialNumber = officialNumber;
350 } 360 }
351 361
352 public File getWstFile() { 362 public File getWstFile() {
353 return wstFile; 363 return this.wstFile;
354 } 364 }
355 365
356 public void setWstFile(File wstFile) { 366 public void setWstFile(final File wstFile) {
357 this.wstFile = wstFile; 367 this.wstFile = wstFile;
358 } 368 }
359 369
360 public File getBBInfo() { 370 public File getBBInfo() {
361 return bbInfoFile; 371 return this.bbInfoFile;
362 } 372 }
363 373
364 public void setBBInfo(File bbInfoFile) { 374 public void setBBInfo(final File bbInfoFile) {
365 this.bbInfoFile = bbInfoFile; 375 this.bbInfoFile = bbInfoFile;
366 } 376 }
367 377
368 public ImportWst getWst() { 378 public ImportWst getWst() {
369 return wst; 379 return this.wst;
370 } 380 }
371 381
372 public void setWst(ImportWst wst) { 382 public void setWst(final ImportWst wst) {
373 this.wst = wst; 383 this.wst = wst;
374 } 384 }
375 385
376 public File getMinfoDir() { 386 private File getMinfoDir() {
377 File riverDir = wstFile 387 return new File(getRiverDir(), MINFO_DIR);
378 .getParentFile().getParentFile().getParentFile(); 388 }
379 return new File(riverDir, MINFO_DIR); 389
390 private File getRiverDir() {
391 return this.wstFile.getParentFile().getParentFile().getParentFile();
380 } 392 }
381 393
382 public void parseDependencies() throws IOException { 394 public void parseDependencies() throws IOException {
395 log.info("Root dir is '" + getRiverDir() + "'");
383 parseGauges(); 396 parseGauges();
384 parseAnnotations(); 397 parseAnnotations();
385 parsePRFs(); 398 parsePRFs();
386 parseDA66s(); 399 parseDA66s();
387 parseDA50s(); 400 parseDA50s();
403 parseSedimentLoadLS(); 416 parseSedimentLoadLS();
404 parseSedimentLoad(); 417 parseSedimentLoad();
405 parseWaterlevels(); 418 parseWaterlevels();
406 parseWaterlevelDifferences(); 419 parseWaterlevelDifferences();
407 parseSQRelation(); 420 parseSQRelation();
421 this.sinfoImporter.setup(getRiverDir(), this);
422 this.sinfoImporter.parse();
423 this.uinfoImporter.setup(getRiverDir(), this);
424 this.uinfoImporter.parse();
408 } 425 }
409 426
410 public void parseFloodProtection() throws IOException { 427 public void parseFloodProtection() throws IOException {
411 if (Config.INSTANCE.skipFloodProtection()) { 428 if (Config.INSTANCE.skipFloodProtection()) {
412 log.info("skip parsing flood protection"); 429 log.info("skip parsing flood protection");
413 return; 430 return;
414 } 431 }
415 432
416 log.info("Parse flood protection wst file"); 433 log.info("Parse flood protection wst file");
417 434
418 File riverDir = wstFile.getParentFile().getParentFile(); 435 final File riverDir = this.wstFile.getParentFile().getParentFile();
419 436
420 File dir = FileTools.repair(new File(riverDir, FLOOD_PROTECTION)); 437 final File dir = FileTools.repair(new File(riverDir, FLOOD_PROTECTION));
421 438
422 if (!dir.isDirectory() || !dir.canRead()) { 439 if (!dir.isDirectory() || !dir.canRead()) {
423 log.info("no directory '" + dir + "' found"); 440 log.info("no directory '" + dir + "' found");
424 return; 441 return;
425 } 442 }
426 443
427 File [] files = dir.listFiles(); 444 final File [] files = dir.listFiles();
428 445
429 if (files == null) { 446 if (files == null) {
430 log.warn("cannot read '" + dir + "'"); 447 log.warn("cannot read '" + dir + "'");
431 return; 448 return;
432 } 449 }
433 450
434 for (File file: files) { 451 for (final File file: files) {
435 if (!file.isFile() || !file.canRead()) { 452 if (!file.isFile() || !file.canRead()) {
436 continue; 453 continue;
437 } 454 }
438 String name = file.getName().toLowerCase(); 455 final String name = file.getName().toLowerCase();
439 if (!(name.endsWith(".zus") || name.endsWith(".wst"))) { 456 if (!(name.endsWith(".zus") || name.endsWith(".wst"))) {
440 continue; 457 continue;
441 } 458 }
442 log.info("found file '" + file.getName() + "'"); 459 log.info("found file '" + file.getName() + "'");
443 try { 460 try {
444 WstParser wstParser = new WstParser(); 461 final WstParser wstParser = new WstParser();
445 wstParser.parse(file); 462 wstParser.parse(file);
446 ImportWst iw = wstParser.getWst(); 463 final ImportWst iw = wstParser.getWst();
447 iw.setKind(5); 464 iw.setKind(5);
448 iw.setDescription( 465 iw.setDescription(
449 FLOOD_PROTECTION + "/" + iw.getDescription()); 466 FLOOD_PROTECTION + "/" + iw.getDescription());
450 floodProtection.add(iw); 467 this.floodProtection.add(iw);
451 } 468 }
452 catch (WstParser.ParseException e) { 469 catch (final WstParser.ParseException e) {
453 log.error(e.getMessage()); 470 log.error(e.getMessage());
454 } 471 }
455 } 472 }
456 } 473 }
457 474
458 public void storeOfficialNumber() { 475 public void storeOfficialNumber() {
459 if (Config.INSTANCE.skipBWASTR()) { 476 if (Config.INSTANCE.skipBWASTR()) {
460 log.info("skip storing official number."); 477 log.info("skip storing official number.");
461 return; 478 return;
462 } 479 }
463 getPeer().setOfficialNumber(officialNumber); 480 getPeer().setOfficialNumber(this.officialNumber);
464 } 481 }
465 482
466 public void parseBedHeight() throws IOException { 483 public void parseBedHeight() throws IOException {
467 File minfoDir = getMinfoDir(); 484 final File minfoDir = getMinfoDir();
468 File bedHeightDir = new File(minfoDir, BED_HEIGHT_DIR); 485 final File bedHeightDir = new File(minfoDir, BED_HEIGHT_DIR);
469 File singlesDir = new File(bedHeightDir, BED_HEIGHT_SINGLE_DIR); 486 final File singlesDir = new File(bedHeightDir, BED_HEIGHT_SINGLE_DIR);
470 487
471 if (Config.INSTANCE.skipBedHeight()) { 488 if (Config.INSTANCE.skipBedHeight()) {
472 log.info("skip parsing bed heights."); 489 log.info("skip parsing bed heights.");
473 } 490 }
474 else { 491 else {
484 return; 501 return;
485 } 502 }
486 503
487 log.debug("Parse sediment density"); 504 log.debug("Parse sediment density");
488 505
489 File minfoDir = getMinfoDir(); 506 final File minfoDir = getMinfoDir();
490 File sediment = new File(minfoDir, SEDIMENT_DENSITY_DIR); 507 final File sediment = new File(minfoDir, SEDIMENT_DENSITY_DIR);
491 508
492 File[] files = sediment.listFiles(); 509 final File[] files = sediment.listFiles();
493 510
494 if (files == null) { 511 if (files == null) {
495 log.warn("Cannot read directory '" + sediment + "'"); 512 log.warn("Cannot read directory '" + sediment + "'");
496 return; 513 return;
497 } 514 }
498 515
499 SedimentDensityParser parser = new SedimentDensityParser(); 516 final SedimentDensityParser parser = new SedimentDensityParser();
500 517
501 for (File file: files) { 518 for (final File file: files) {
502 parser.parse(file); 519 parser.parse(file);
503 } 520 }
504 521
505 sedimentDensities = parser.getSedimentDensities(); 522 this.sedimentDensities = parser.getSedimentDensities();
506 523
507 log.info("Parsed " + sedimentDensities.size() 524 log.info("Parsed " + this.sedimentDensities.size()
508 + " sediment densities."); 525 + " sediment densities.");
509 } 526 }
510 527
511 protected void parsePorosity() throws IOException { 528 protected void parsePorosity() throws IOException {
512 if (Config.INSTANCE.skipPorosity()) { 529 if (Config.INSTANCE.skipPorosity()) {
513 log.info("skip parsing porosity."); 530 log.info("skip parsing porosity.");
514 return; 531 return;
515 } 532 }
516 533
517 log.debug("Parse porosity"); 534 log.debug("Parse porosity");
518 535
519 File minfoDir = getMinfoDir(); 536 final File minfoDir = getMinfoDir();
520 File porosity = new File(minfoDir, POROSITY_DIR); 537 final File porosity = new File(minfoDir, POROSITY_DIR);
521 538
522 File[] files = porosity.listFiles(); 539 final File[] files = porosity.listFiles();
523 540
524 if (files == null) { 541 if (files == null) {
525 log.warn("Cannot read directory '" + porosity + "'"); 542 log.warn("Cannot read directory '" + porosity + "'");
526 return; 543 return;
527 } 544 }
528 545
529 PorosityParser parser = new PorosityParser(); 546 final PorosityParser parser = new PorosityParser();
530 547
531 for (File file: files) { 548 for (final File file: files) {
532 parser.parse(file); 549 parser.parse(file);
533 } 550 }
534 551
535 porosities = parser.getPorosities(); 552 this.porosities = parser.getPorosities();
536 553
537 log.info("Parsed " + porosities.size() + " porosities."); 554 log.info("Parsed " + this.porosities.size() + " porosities.");
538 } 555 }
539 556
540 protected void parseMorphologicalWidth() throws IOException { 557 protected void parseMorphologicalWidth() throws IOException {
541 if (Config.INSTANCE.skipMorphologicalWidth()) { 558 if (Config.INSTANCE.skipMorphologicalWidth()) {
542 log.info("skip parsing morphological width."); 559 log.info("skip parsing morphological width.");
543 return; 560 return;
544 } 561 }
545 562
546 log.debug("Parse morphological width"); 563 log.debug("Parse morphological width");
547 564
548 File minfoDir = getMinfoDir(); 565 final File minfoDir = getMinfoDir();
549 File morphDir = new File(minfoDir, MORPHOLOGICAL_WIDTH_DIR); 566 final File morphDir = new File(minfoDir, MORPHOLOGICAL_WIDTH_DIR);
550 567
551 File[] files = morphDir.listFiles(); 568 final File[] files = morphDir.listFiles();
552 569
553 if (files == null) { 570 if (files == null) {
554 log.warn("Cannot read directory '" + morphDir + "'"); 571 log.warn("Cannot read directory '" + morphDir + "'");
555 return; 572 return;
556 } 573 }
557 574
558 MorphologicalWidthParser parser = new MorphologicalWidthParser(); 575 final MorphologicalWidthParser parser = new MorphologicalWidthParser();
559 576
560 for (File file: files) { 577 for (final File file: files) {
561 parser.parse(file); 578 parser.parse(file);
562 } 579 }
563 580
564 morphologicalWidths = parser.getMorphologicalWidths(); 581 this.morphologicalWidths = parser.getMorphologicalWidths();
565 582
566 log.info("Parsed " + morphologicalWidths.size() 583 log.info("Parsed " + this.morphologicalWidths.size()
567 + " morph. widths files."); 584 + " morph. widths files.");
568 } 585 }
569 586
570 587
571 protected void parseFlowVelocity() throws IOException { 588 protected void parseFlowVelocity() throws IOException {
572 if (Config.INSTANCE.skipFlowVelocity()) { 589 if (Config.INSTANCE.skipFlowVelocity()) {
574 return; 591 return;
575 } 592 }
576 593
577 log.debug("Parse flow velocity"); 594 log.debug("Parse flow velocity");
578 595
579 File minfoDir = getMinfoDir(); 596 final File minfoDir = getMinfoDir();
580 File flowDir = new File(minfoDir, FLOW_VELOCITY_DIR); 597 final File flowDir = new File(minfoDir, FLOW_VELOCITY_DIR);
581 File modelDir = new File(flowDir, FLOW_VELOCITY_MODEL); 598 final File modelDir = new File(flowDir, FLOW_VELOCITY_MODEL);
582 File measureDir = new File(flowDir, FLOW_VELOCITY_MEASUREMENTS); 599 final File measureDir = new File(flowDir, FLOW_VELOCITY_MEASUREMENTS);
583 600
584 File[] modelFiles = modelDir.listFiles(); 601 final File[] modelFiles = modelDir.listFiles();
585 File[] measureFiles = measureDir.listFiles(); 602 final File[] measureFiles = measureDir.listFiles();
586 603
587 if (modelFiles == null) { 604 if (modelFiles == null) {
588 log.warn("Cannot read directory '" + modelDir + "'"); 605 log.warn("Cannot read directory '" + modelDir + "'");
589 } 606 }
590 else { 607 else {
591 FlowVelocityModelParser parser = new FlowVelocityModelParser(); 608 final FlowVelocityModelParser parser = new FlowVelocityModelParser();
592 609
593 for (File model: modelFiles) { 610 for (final File model: modelFiles) {
594 log.debug("Parse file '" + model + "'"); 611 log.debug("Parse file '" + model + "'");
595 parser.parse(model); 612 parser.parse(model);
596 } 613 }
597 614
598 flowVelocityModels = parser.getModels(); 615 this.flowVelocityModels = parser.getModels();
599 } 616 }
600 617
601 if (measureFiles == null) { 618 if (measureFiles == null) {
602 log.warn("Cannot read directory '" + measureDir + "'"); 619 log.warn("Cannot read directory '" + measureDir + "'");
603 } 620 }
604 else { 621 else {
605 FlowVelocityMeasurementParser parser = 622 final FlowVelocityMeasurementParser parser =
606 new FlowVelocityMeasurementParser(); 623 new FlowVelocityMeasurementParser();
607 624
608 for (File measurement: measureFiles) { 625 for (final File measurement: measureFiles) {
609 log.debug("Parse file '" + measurement + "'"); 626 log.debug("Parse file '" + measurement + "'");
610 parser.parse(measurement); 627 parser.parse(measurement);
611 } 628 }
612 629
613 flowVelocityMeasurements = parser.getMeasurements(); 630 this.flowVelocityMeasurements = parser.getMeasurements();
614 } 631 }
615 } 632 }
616 633
617 634
618 private void parseSedimentLoadFiles( 635 private void parseSedimentLoadFiles(
619 File[] files, 636 final File[] files,
620 AbstractSedimentLoadParser parser 637 final AbstractSedimentLoadParser parser
621 ) throws IOException { 638 ) throws IOException {
622 for (File file: files) { 639 for (final File file: files) {
623 if (file.isDirectory()) { 640 if (file.isDirectory()) {
624 for (File child: file.listFiles()) { 641 for (final File child: file.listFiles()) {
625 parser.parse(child); 642 parser.parse(child);
626 } 643 }
627 } 644 }
628 else { 645 else {
629 parser.parse(file); 646 parser.parse(file);
630 } 647 }
631 } 648 }
632 } 649 }
633 650
634 651
635 private void parseSedimentLoadDir( 652 private void parseSedimentLoadDir(
636 File sedimentLoadDir, 653 final File sedimentLoadDir,
637 AbstractSedimentLoadParser parser 654 final AbstractSedimentLoadParser parser
638 ) throws IOException { 655 ) throws IOException {
639 656
640 File[] sedimentLoadSubDirs = { 657 final File[] sedimentLoadSubDirs = {
641 new File(sedimentLoadDir, 658 new File(sedimentLoadDir,
642 SEDIMENT_LOAD_SINGLE_DIR), 659 SEDIMENT_LOAD_SINGLE_DIR),
643 new File(sedimentLoadDir, 660 new File(sedimentLoadDir,
644 SEDIMENT_LOAD_EPOCH_DIR), 661 SEDIMENT_LOAD_EPOCH_DIR),
645 new File(sedimentLoadDir, 662 new File(sedimentLoadDir,
646 SEDIMENT_LOAD_OFF_EPOCH_DIR), 663 SEDIMENT_LOAD_OFF_EPOCH_DIR),
647 }; 664 };
648 665
649 for (File subDir : sedimentLoadSubDirs) { 666 for (final File subDir : sedimentLoadSubDirs) {
650 File[] files = subDir.listFiles(); 667 final File[] files = subDir.listFiles();
651 668
652 if (files == null || files.length == 0) { 669 if (files == null || files.length == 0) {
653 log.warn("Cannot read directory '" + subDir + "'"); 670 log.warn("Cannot read directory '" + subDir + "'");
654 } 671 }
655 else { 672 else {
665 return; 682 return;
666 } 683 }
667 684
668 log.debug("Parse sediment load longitudinal section data"); 685 log.debug("Parse sediment load longitudinal section data");
669 686
670 SedimentLoadLSParser parser = new SedimentLoadLSParser(); 687 final SedimentLoadLSParser parser = new SedimentLoadLSParser();
671 688
672 File minfoDir = getMinfoDir(); 689 final File minfoDir = getMinfoDir();
673 File sedimentLoadDir = new File(minfoDir, SEDIMENT_LOAD_DIR); 690 final File sedimentLoadDir = new File(minfoDir, SEDIMENT_LOAD_DIR);
674 File sedimentLoadLSDir = new File(sedimentLoadDir, 691 final File sedimentLoadLSDir = new File(sedimentLoadDir,
675 SEDIMENT_LOAD_LS_DIR); 692 SEDIMENT_LOAD_LS_DIR);
676 693
677 parseSedimentLoadDir(sedimentLoadLSDir, parser); 694 parseSedimentLoadDir(sedimentLoadLSDir, parser);
678 695
679 sedimentLoadLSs = parser.getSedimentLoadLSs(); 696 this.sedimentLoadLSs = parser.getSedimentLoadLSs();
680 } 697 }
681 698
682 699
683 protected void parseSedimentLoad() throws IOException { 700 protected void parseSedimentLoad() throws IOException {
684 if (Config.INSTANCE.skipSedimentLoad()) { 701 if (Config.INSTANCE.skipSedimentLoad()) {
685 log.info( 702 log.info(
686 "skip parsing sediment load data at measurement stations"); 703 "skip parsing sediment load data at measurement stations");
687 return; 704 return;
688 } 705 }
689 706
690 log.debug("Parse sediment load data at measurement stations"); 707 log.debug("Parse sediment load data at measurement stations");
691 708
692 SedimentLoadParser parser = new SedimentLoadParser(getPeer()); 709 final SedimentLoadParser parser = new SedimentLoadParser(getPeer());
693 710
694 File minfoDir = getMinfoDir(); 711 final File minfoDir = getMinfoDir();
695 File sedimentLoadDir = new File(minfoDir, SEDIMENT_LOAD_DIR); 712 final File sedimentLoadDir = new File(minfoDir, SEDIMENT_LOAD_DIR);
696 File sedimentLoadMSDir = new File(sedimentLoadDir, 713 final File sedimentLoadMSDir = new File(sedimentLoadDir,
697 SEDIMENT_LOAD_MS_DIR); 714 SEDIMENT_LOAD_MS_DIR);
698 715
699 parseSedimentLoadDir(sedimentLoadMSDir, parser); 716 parseSedimentLoadDir(sedimentLoadMSDir, parser);
700 717
701 sedimentLoads = parser.getSedimentLoads(); 718 this.sedimentLoads = parser.getSedimentLoads();
702 } 719 }
703 720
704 721
705 protected void parseWaterlevels() throws IOException { 722 protected void parseWaterlevels() throws IOException {
706 if (Config.INSTANCE.skipWaterlevels()) { 723 if (Config.INSTANCE.skipWaterlevels()) {
708 return; 725 return;
709 } 726 }
710 727
711 log.info("Parse waterlevels"); 728 log.info("Parse waterlevels");
712 729
713 File minfo = getMinfoDir(); 730 final File minfo = getMinfoDir();
714 File fixDir = new File(minfo, MINFO_FIXATIONS_DIR); 731 final File fixDir = new File(minfo, MINFO_FIXATIONS_DIR);
715 File wspDir = new File(fixDir, MINFO_WATERLEVELS_DIR); 732 final File wspDir = new File(fixDir, MINFO_WATERLEVELS_DIR);
716 733
717 File[] files = wspDir.listFiles(); 734 final File[] files = wspDir.listFiles();
718 735
719 if (files == null) { 736 if (files == null) {
720 log.warn("Cannot read directory for wl '" + wspDir + "'"); 737 log.warn("Cannot read directory for wl '" + wspDir + "'");
721 return; 738 return;
722 } 739 }
723 740
724 WaterlevelParser parser = new WaterlevelParser(); 741 final WaterlevelParser parser = new WaterlevelParser();
725 742
726 for (File file: files) { 743 for (final File file: files) {
727 parser.parse(file); 744 parser.parse(file);
728 } 745 }
729 746
730 // The parsed ImportWaterlevels are converted to 747 // The parsed ImportWaterlevels are converted to
731 // 'fixation'-wsts now. 748 // 'fixation'-wsts now.
732 for(ImportWst iw: parser.getWaterlevels()) { 749 for(final ImportWst iw: parser.getWaterlevels()) {
733 iw.setDescription("CSV/" + iw.getDescription()); 750 iw.setDescription("CSV/" + iw.getDescription());
734 iw.setKind(7); 751 iw.setKind(7);
735 waterlevels.add(iw); 752 this.waterlevels.add(iw);
736 } 753 }
737 } 754 }
738 755
739 protected void parseMeasurementStations() throws IOException { 756 protected void parseMeasurementStations() throws IOException {
740 if (Config.INSTANCE.skipMeasurementStations()) { 757 if (Config.INSTANCE.skipMeasurementStations()) {
742 return; 759 return;
743 } 760 }
744 761
745 log.info("Parse measurement stations"); 762 log.info("Parse measurement stations");
746 763
747 File minfo = getMinfoDir(); 764 final File minfo = getMinfoDir();
748 File minfoBaseDir = new File(minfo, MINFO_BASE_DIR); 765 final File minfoBaseDir = new File(minfo, MINFO_BASE_DIR);
749 File coredataFile = new File(minfoBaseDir, MINFO_CORE_DATA_FILE); 766 final File coredataFile = new File(minfoBaseDir, MINFO_CORE_DATA_FILE);
750 767
751 if (coredataFile == null || !coredataFile.exists()) { 768 if (coredataFile == null || !coredataFile.exists()) {
752 log.warn("No core data file '" 769 log.warn("No core data file '"
753 + coredataFile.getAbsolutePath() + "' found"); 770 + coredataFile.getAbsolutePath() + "' found");
754 return; 771 return;
755 } 772 }
756 773
757 MeasurementStationsParser parser = new MeasurementStationsParser(); 774 final MeasurementStationsParser parser = new MeasurementStationsParser();
758 try { 775 try {
759 parser.parse(coredataFile); 776 parser.parse(coredataFile);
760 measurementStations = parser.getMeasurementStations(); 777 this.measurementStations = parser.getMeasurementStations();
761 778
762 log.info("Successfully parsed " + measurementStations.size() 779 log.info("Successfully parsed " + this.measurementStations.size()
763 + " measurement stations."); 780 + " measurement stations.");
764 } 781 }
765 catch (IOException ioe) { 782 catch (final IOException ioe) {
766 log.error("unable to parse file '" + coredataFile.getName() + 783 log.error("unable to parse file '" + coredataFile.getName() +
767 ": " + ioe.getMessage()); 784 ": " + ioe.getMessage());
768 } 785 }
769 } 786 }
770 787
771 788
772 protected void parseWaterlevelDifferences() throws IOException { 789 protected void parseWaterlevelDifferences() throws IOException {
775 return; 792 return;
776 } 793 }
777 794
778 log.info("Parse waterlevel differences"); 795 log.info("Parse waterlevel differences");
779 796
780 File minfo = getMinfoDir(); 797 final File minfo = getMinfoDir();
781 File fixDir = new File(minfo, MINFO_FIXATIONS_DIR); 798 final File fixDir = new File(minfo, MINFO_FIXATIONS_DIR);
782 File diffDir = new File(fixDir, MINFO_WATERLEVEL_DIFF_DIR); 799 final File diffDir = new File(fixDir, MINFO_WATERLEVEL_DIFF_DIR);
783 800
784 File[] files = diffDir.listFiles(); 801 final File[] files = diffDir.listFiles();
785 802
786 if (files == null) { 803 if (files == null) {
787 log.warn("Cannot read directory '" + diffDir + "'"); 804 log.warn("Cannot read directory '" + diffDir + "'");
788 return; 805 return;
789 } 806 }
790 807
791 WaterlevelDifferencesParser parser = new WaterlevelDifferencesParser(); 808 final WaterlevelDifferencesParser parser = new WaterlevelDifferencesParser();
792 809
793 for (File file: files) { 810 for (final File file: files) {
794 parser.parse(file); 811 parser.parse(file);
795 } 812 }
796 813
797 // WaterlevelDifferences become Wsts now. 814 // WaterlevelDifferences become Wsts now.
798 for(ImportWst iw: parser.getDifferences()) { 815 for(final ImportWst iw: parser.getDifferences()) {
799 iw.setDescription("CSV/" + iw.getDescription()); 816 iw.setDescription("CSV/" + iw.getDescription());
800 iw.setKind(6); 817 iw.setKind(6);
801 waterlevelDifferences.add(iw); 818 this.waterlevelDifferences.add(iw);
802 } 819 }
803 } 820 }
804 821
805 822
806 protected void parseSQRelation() throws IOException { 823 protected void parseSQRelation() throws IOException {
809 return; 826 return;
810 } 827 }
811 828
812 log.info("Parse sq relations"); 829 log.info("Parse sq relations");
813 830
814 File minfo = getMinfoDir(); 831 final File minfo = getMinfoDir();
815 File sqDir = new File(minfo, MINFO_SQ_DIR); 832 final File sqDir = new File(minfo, MINFO_SQ_DIR);
816 833
817 File[] files = sqDir.listFiles(); 834 final File[] files = sqDir.listFiles();
818 835
819 if (files == null) { 836 if (files == null) {
820 log.warn("Cannot read directory '" + sqDir + "'"); 837 log.warn("Cannot read directory '" + sqDir + "'");
821 return; 838 return;
822 } 839 }
823 840
824 SQRelationParser parser = new SQRelationParser(getPeer()); 841 final SQRelationParser parser = new SQRelationParser(getPeer());
825 842
826 for (File file: files) { 843 for (final File file: files) {
827 parser.parse(file); 844 parser.parse(file);
828 } 845 }
829 846
830 sqRelations = parser.getSQRelations(); 847 this.sqRelations = parser.getSQRelations();
831 848
832 log.debug("Parsed " + sqRelations.size() + " SQ relations."); 849 log.debug("Parsed " + this.sqRelations.size() + " SQ relations.");
833 } 850 }
834 851
835 852
836 protected void parseBedHeights(File dir) throws IOException { 853 protected void parseBedHeights(final File dir) throws IOException {
837 log.debug("Parse bed height singles"); 854 log.debug("Parse bed height singles");
838 855
839 File[] files = dir.listFiles(); 856 final File[] files = dir.listFiles(new FilenameFilter() {
857 @Override
858 public boolean accept(final File dir, final String name) {
859 return name.toLowerCase().endsWith(".csv");
860 }
861 });
840 862
841 if (files == null) { 863 if (files == null) {
842 log.warn("Cannot read directory '" + dir + "'"); 864 log.warn("Cannot read directory '" + dir + "'");
843 return; 865 return;
844 } 866 }
845 867
846 BedHeightParser parser = new BedHeightParser(); 868 final BedHeightParser parser = new BedHeightParser();
847 869
848 for (File file: files) { 870 for (final File file: files) {
849 parser.parse(file); 871 parser.parse(file);
850 } 872 }
851 873
852 bedHeights = parser.getBedHeights(); 874 this.bedHeights = parser.getBedHeights();
853 } 875 }
854 876
855 public void parseFloodWater() throws IOException { 877 public void parseFloodWater() throws IOException {
856 if (Config.INSTANCE.skipFloodWater()) { 878 if (Config.INSTANCE.skipFloodWater()) {
857 log.info("skip parsing flod water"); 879 log.info("skip parsing flod water");
858 return; 880 return;
859 } 881 }
860 882
861 log.info("Parse flood water wst file"); 883 log.info("Parse flood water wst file");
862 884
863 File riverDir = wstFile.getParentFile().getParentFile(); 885 final File riverDir = this.wstFile.getParentFile().getParentFile();
864 886
865 File dir = FileTools.repair(new File(riverDir, FLOOD_WATER)); 887 final File dir = FileTools.repair(new File(riverDir, FLOOD_WATER));
866 888
867 if (!dir.isDirectory() || !dir.canRead()) { 889 if (!dir.isDirectory() || !dir.canRead()) {
868 log.info("no directory '" + dir + "' found"); 890 log.info("no directory '" + dir + "' found");
869 return; 891 return;
870 } 892 }
871 893
872 File [] files = dir.listFiles(); 894 final File [] files = dir.listFiles();
873 895
874 if (files == null) { 896 if (files == null) {
875 log.warn("cannot read '" + dir + "'"); 897 log.warn("cannot read '" + dir + "'");
876 return; 898 return;
877 } 899 }
878 900
879 for (File file: files) { 901 for (final File file: files) {
880 if (!file.isFile() || !file.canRead()) { 902 if (!file.isFile() || !file.canRead()) {
881 continue; 903 continue;
882 } 904 }
883 String name = file.getName().toLowerCase(); 905 final String name = file.getName().toLowerCase();
884 if (!(name.endsWith(".zus") || name.endsWith(".wst"))) { 906 if (!(name.endsWith(".zus") || name.endsWith(".wst"))) {
885 continue; 907 continue;
886 } 908 }
887 log.info("found file '" + file.getName() + "'"); 909 log.info("found file '" + file.getName() + "'");
888 try { 910 try {
889 WstParser wstParser = new WstParser(); 911 final WstParser wstParser = new WstParser();
890 wstParser.parse(file); 912 wstParser.parse(file);
891 ImportWst iw = wstParser.getWst(); 913 final ImportWst iw = wstParser.getWst();
892 iw.setKind(4); 914 iw.setKind(4);
893 iw.setDescription(FLOOD_WATER + "/" + iw.getDescription()); 915 iw.setDescription(FLOOD_WATER + "/" + iw.getDescription());
894 floodWater.add(iw); 916 this.floodWater.add(iw);
895 } 917 }
896 catch (WstParser.ParseException e) { 918 catch (final WstParser.ParseException e) {
897 log.error(e.getMessage()); 919 log.error(e.getMessage());
898 } 920 }
899 } 921 }
900 } 922 }
901 923
905 return; 927 return;
906 } 928 }
907 929
908 log.info("Parse official wst files"); 930 log.info("Parse official wst files");
909 931
910 File riverDir = wstFile.getParentFile().getParentFile(); 932 final File riverDir = this.wstFile.getParentFile().getParentFile();
911 933
912 for (String folder: OFFICIAL_LINES_FOLDERS) { 934 for (final String folder: OFFICIAL_LINES_FOLDERS) {
913 File dir = FileTools.repair(new File(riverDir, folder)); 935 final File dir = FileTools.repair(new File(riverDir, folder));
914 936
915 if (!dir.isDirectory() || !dir.canRead()) { 937 if (!dir.isDirectory() || !dir.canRead()) {
916 log.info("no directory '" + folder + "' found"); 938 log.info("no directory '" + folder + "' found");
917 continue; 939 continue;
918 } 940 }
919 941
920 File file = FileTools.repair(new File(dir, OFFICIAL_LINES)); 942 final File file = FileTools.repair(new File(dir, OFFICIAL_LINES));
921 if (!file.isFile() || !file.canRead()) { 943 if (!file.isFile() || !file.canRead()) {
922 log.warn("no official lines wst file found"); 944 log.warn("no official lines wst file found");
923 continue; 945 continue;
924 } 946 }
925 log.debug("Found WST file: " + file); 947 log.debug("Found WST file: " + file);
926 948
927 ImportWst iw = new ImportWst( 949 final ImportWst iw = new ImportWst(
928 ImportOfficialWstColumn.COLUMN_FACTORY); 950 ImportOfficialWstColumn.COLUMN_FACTORY);
929 951
930 WstParser wstParser = new WstParser(iw); 952 final WstParser wstParser = new WstParser(iw);
931 try { 953 try {
932 wstParser.parse(file); 954 wstParser.parse(file);
933 } 955 }
934 catch (WstParser.ParseException e) { 956 catch (final WstParser.ParseException e) {
935 log.error(e.getMessage()); 957 log.error(e.getMessage());
936 continue; 958 continue;
937 } 959 }
938 960
939 iw.setKind(3); 961 iw.setKind(3);
940 iw.setDescription(folder + "/" + iw.getDescription()); 962 iw.setDescription(folder + "/" + iw.getDescription());
941 963
942 File configFile = FileTools.repair( 964 final File configFile = FileTools.repair(
943 new File(dir, OFFICIAL_LINES_CONFIG)); 965 new File(dir, OFFICIAL_LINES_CONFIG));
944 if (!configFile.isFile() || !configFile.canRead()) { 966 if (!configFile.isFile() || !configFile.canRead()) {
945 log.warn("no config file for official lines found"); 967 log.warn("no config file for official lines found");
946 } 968 }
947 else { 969 else {
948 OfficialLinesConfigParser olcp = 970 final OfficialLinesConfigParser olcp =
949 new OfficialLinesConfigParser(); 971 new OfficialLinesConfigParser();
950 try { 972 try {
951 olcp.parse(configFile); 973 olcp.parse(configFile);
952 } 974 }
953 catch (IOException ioe) { 975 catch (final IOException ioe) {
954 log.warn("Error reading offical lines config", ioe); 976 log.warn("Error reading offical lines config", ioe);
955 } 977 }
956 List<String> mainValueNames = olcp.getMainValueNames(); 978 final List<String> mainValueNames = olcp.getMainValueNames();
957 if (mainValueNames.isEmpty()) { 979 if (mainValueNames.isEmpty()) {
958 log.warn( 980 log.warn(
959 "config file for offical lines contains no entries"); 981 "config file for offical lines contains no entries");
960 } 982 }
961 else { 983 else {
962 // Join as much as possible. 984 // Join as much as possible.
963 Iterator<ImportWstColumn> wi = iw.getColumns().iterator(); 985 final Iterator<ImportWstColumn> wi = iw.getColumns().iterator();
964 Iterator<String> si = olcp.getMainValueNames().iterator(); 986 final Iterator<String> si = olcp.getMainValueNames().iterator();
965 while (wi.hasNext() && si.hasNext()) { 987 while (wi.hasNext() && si.hasNext()) {
966 ImportOfficialWstColumn wc = 988 final ImportOfficialWstColumn wc =
967 (ImportOfficialWstColumn)wi.next(); 989 (ImportOfficialWstColumn)wi.next();
968 String name = si.next(); 990 final String name = si.next();
969 ImportOfficialLine iol = 991 final ImportOfficialLine iol =
970 new ImportOfficialLine(name, wc); 992 new ImportOfficialLine(name, wc);
971 wc.setOfficialLine(iol); 993 wc.setOfficialLine(iol);
972 } 994 }
973 } 995 }
974 } 996 }
975 997
976 officialLines.add(iw); 998 this.officialLines.add(iw);
977 } // for all folders 999 } // for all folders
978 1000
979 } 1001 }
980 1002
981 public void parseFixations() throws IOException { 1003 public void parseFixations() throws IOException {
984 return; 1006 return;
985 } 1007 }
986 1008
987 log.info("Parse fixation wst files"); 1009 log.info("Parse fixation wst files");
988 1010
989 File riverDir = wstFile.getParentFile().getParentFile(); 1011 final File riverDir = this.wstFile.getParentFile().getParentFile();
990 1012
991 File fixDir = FileTools.repair( 1013 final File fixDir = FileTools.repair(
992 new File(riverDir, FIXATIONS)); 1014 new File(riverDir, FIXATIONS));
993 1015
994 if (!fixDir.isDirectory() || !fixDir.canRead()) { 1016 if (!fixDir.isDirectory() || !fixDir.canRead()) {
995 log.info("no fixation wst file directory found"); 1017 log.info("no fixation wst file directory found");
996 return; 1018 return;
997 } 1019 }
998 1020
999 File [] files = fixDir.listFiles(); 1021 final File [] files = fixDir.listFiles();
1000 1022
1001 if (files == null) { 1023 if (files == null) {
1002 log.warn("cannot read fixations wst file directory"); 1024 log.warn("cannot read fixations wst file directory");
1003 return; 1025 return;
1004 } 1026 }
1005 1027
1006 for (File file: files) { 1028 for (final File file: files) {
1007 if (!file.isFile() || !file.canRead()) { 1029 if (!file.isFile() || !file.canRead()) {
1008 continue; 1030 continue;
1009 } 1031 }
1010 String name = file.getName().toLowerCase(); 1032 final String name = file.getName().toLowerCase();
1011 if (!name.endsWith(".wst")) { 1033 if (!name.endsWith(".wst")) {
1012 continue; 1034 continue;
1013 } 1035 }
1014 log.debug("Found WST file: " + file); 1036 log.debug("Found WST file: " + file);
1015 1037
1016 try { 1038 try {
1017 WstParser wstParser = new WstParser(); 1039 final WstParser wstParser = new WstParser();
1018 wstParser.parse(file); 1040 wstParser.parse(file);
1019 ImportWst iw = wstParser.getWst(); 1041 final ImportWst iw = wstParser.getWst();
1020 iw.setKind(2); 1042 iw.setKind(2);
1021 iw.setDescription(FIXATIONS+ "/" + iw.getDescription()); 1043 iw.setDescription(FIXATIONS+ "/" + iw.getDescription());
1022 fixations.add(iw); 1044 this.fixations.add(iw);
1023 } 1045 }
1024 catch (WstParser.ParseException e) { 1046 catch (final WstParser.ParseException e) {
1025 log.error(e.getMessage()); 1047 log.error(e.getMessage());
1026 } 1048 }
1027 } 1049 }
1028 } 1050 }
1029 1051
1033 return; 1055 return;
1034 } 1056 }
1035 1057
1036 log.info("Parse extra longitudinal wst files"); 1058 log.info("Parse extra longitudinal wst files");
1037 1059
1038 File riverDir = wstFile.getParentFile().getParentFile(); 1060 final File riverDir = this.wstFile.getParentFile().getParentFile();
1039 1061
1040 File extraDir = FileTools.repair( 1062 final File extraDir = FileTools.repair(
1041 new File(riverDir, EXTRA_LONGITUDINALS)); 1063 new File(riverDir, EXTRA_LONGITUDINALS));
1042 1064
1043 if (!extraDir.isDirectory() || !extraDir.canRead()) { 1065 if (!extraDir.isDirectory() || !extraDir.canRead()) {
1044 log.info("no extra longitudinal wst file directory found"); 1066 log.info("no extra longitudinal wst file directory found");
1045 return; 1067 return;
1046 } 1068 }
1047 1069
1048 File [] files = extraDir.listFiles(); 1070 final File [] files = extraDir.listFiles();
1049 1071
1050 if (files == null) { 1072 if (files == null) {
1051 log.warn("cannot read extra longitudinal wst file directory"); 1073 log.warn("cannot read extra longitudinal wst file directory");
1052 return; 1074 return;
1053 } 1075 }
1054 1076
1055 for (File file: files) { 1077 for (final File file: files) {
1056 if (!file.isFile() || !file.canRead()) { 1078 if (!file.isFile() || !file.canRead()) {
1057 continue; 1079 continue;
1058 } 1080 }
1059 String name = file.getName().toLowerCase(); 1081 final String name = file.getName().toLowerCase();
1060 if (!(name.endsWith(".zus") || name.endsWith(".wst"))) { 1082 if (!(name.endsWith(".zus") || name.endsWith(".wst"))) {
1061 continue; 1083 continue;
1062 } 1084 }
1063 log.debug("Found WST file: " + file); 1085 log.debug("Found WST file: " + file);
1064 1086
1065 try { 1087 try {
1066 WstParser wstParser = new WstParser(); 1088 final WstParser wstParser = new WstParser();
1067 wstParser.parse(file); 1089 wstParser.parse(file);
1068 ImportWst iw = wstParser.getWst(); 1090 final ImportWst iw = wstParser.getWst();
1069 iw.setKind(1); 1091 iw.setKind(1);
1070 iw.setDescription( 1092 iw.setDescription(
1071 EXTRA_LONGITUDINALS + "/" + iw.getDescription()); 1093 EXTRA_LONGITUDINALS + "/" + iw.getDescription());
1072 extraWsts.add(iw); 1094 this.extraWsts.add(iw);
1073 } 1095 }
1074 catch (WstParser.ParseException e) { 1096 catch (final WstParser.ParseException e) {
1075 log.error(e.getMessage()); 1097 log.error(e.getMessage());
1076 } 1098 }
1077 } 1099 }
1078 1100
1079 } 1101 }
1082 if (Config.INSTANCE.skipWst()) { 1104 if (Config.INSTANCE.skipWst()) {
1083 log.info("skip parsing WST file"); 1105 log.info("skip parsing WST file");
1084 return; 1106 return;
1085 } 1107 }
1086 1108
1087 WstParser wstParser = new WstParser(); 1109 final WstParser wstParser = new WstParser();
1088 try { 1110 try {
1089 wstParser.parse(wstFile); 1111 wstParser.parse(this.wstFile);
1090 wst = wstParser.getWst(); 1112 this.wst = wstParser.getWst();
1091 wst.setKmUp(wst.guessWaterLevelIncreasing()); 1113 this.wst.setKmUp(this.wst.guessWaterLevelIncreasing());
1092 } 1114 }
1093 catch (WstParser.ParseException e) { 1115 catch (final WstParser.ParseException e) {
1094 log.error(e.getMessage()); 1116 log.error(e.getMessage());
1095 } 1117 }
1096 } 1118 }
1097 1119
1098 public void parseGauges() throws IOException { 1120 public void parseGauges() throws IOException {
1099 if (Config.INSTANCE.skipGauges()) { 1121 if (Config.INSTANCE.skipGauges()) {
1100 log.info("skip parsing gauges"); 1122 log.info("skip parsing gauges");
1101 return; 1123 return;
1102 } 1124 }
1103 1125
1104 File gltFile = new File(wstFile.getParentFile(), PEGEL_GLT); 1126 File gltFile = new File(this.wstFile.getParentFile(), PEGEL_GLT);
1105 gltFile = FileTools.repair(gltFile); 1127 gltFile = FileTools.repair(gltFile);
1106 1128
1107 if (!gltFile.isFile() || !gltFile.canRead()) { 1129 if (!gltFile.isFile() || !gltFile.canRead()) {
1108 log.warn("cannot read gauges from '" + gltFile + "'"); 1130 log.warn("cannot read gauges from '" + gltFile + "'");
1109 return; 1131 return;
1110 } 1132 }
1111 1133
1112 PegelGltParser pgltp = new PegelGltParser(); 1134 final PegelGltParser pgltp = new PegelGltParser();
1113 pgltp.parse(gltFile); 1135 pgltp.parse(gltFile);
1114 1136
1115 gauges = pgltp.getGauges(); 1137 this.gauges = pgltp.getGauges();
1116 1138
1117 for (ImportGauge gauge: gauges) { 1139 for (final ImportGauge gauge: this.gauges) {
1118 gauge.parseDependencies(); 1140 gauge.parseDependencies();
1119 } 1141 }
1120 } 1142 }
1121 1143
1122 public void parseAnnotations() throws IOException { 1144 public void parseAnnotations() throws IOException {
1123 if (Config.INSTANCE.skipAnnotations()) { 1145 if (Config.INSTANCE.skipAnnotations()) {
1124 log.info("skip parsing annotations"); 1146 log.info("skip parsing annotations");
1125 return; 1147 return;
1126 } 1148 }
1127 1149
1128 File riverDir = wstFile.getParentFile().getParentFile(); 1150 final File riverDir = this.wstFile.getParentFile().getParentFile();
1129 AnnotationsParser aparser = 1151 final AnnotationsParser aparser =
1130 new AnnotationsParser(annotationClassifier); 1152 new AnnotationsParser(this.annotationClassifier);
1131 aparser.parse(riverDir); 1153 aparser.parse(riverDir);
1132 1154
1133 annotations = aparser.getAnnotations(); 1155 this.annotations = aparser.getAnnotations();
1134 } 1156 }
1135 1157
1136 public void parseHYKs() { 1158 public void parseHYKs() {
1137 if (Config.INSTANCE.skipHYKs()) { 1159 if (Config.INSTANCE.skipHYKs()) {
1138 log.info("skip parsing HYK files"); 1160 log.info("skip parsing HYK files");
1139 return; 1161 return;
1140 } 1162 }
1141 1163
1142 log.info("looking for HYK files"); 1164 log.info("looking for HYK files");
1143 HYKParser parser = new HYKParser(); 1165 final HYKParser parser = new HYKParser();
1144 File riverDir = wstFile 1166 final File riverDir = this.wstFile
1145 .getParentFile() // Basisdaten 1167 .getParentFile() // Basisdaten
1146 .getParentFile() // Hydrologie 1168 .getParentFile() // Hydrologie
1147 .getParentFile(); // <river> 1169 .getParentFile(); // <river>
1148 1170
1149 parser.parseHYKs(riverDir, new HYKParser.Callback() { 1171 parser.parseHYKs(riverDir, new HYKParser.Callback() {
1150 1172
1151 Set<HashedFile> hfs = new HashSet<HashedFile>(); 1173 Set<HashedFile> hfs = new HashSet<>();
1152 1174
1153 @Override 1175 @Override
1154 public boolean hykAccept(File file) { 1176 public boolean hykAccept(final File file) {
1155 HashedFile hf = new HashedFile(file); 1177 final HashedFile hf = new HashedFile(file);
1156 boolean success = hfs.add(hf); 1178 final boolean success = this.hfs.add(hf);
1157 if (!success) { 1179 if (!success) {
1158 log.warn("HYK file '" + file 1180 log.warn("HYK file '" + file
1159 + "' seems to be a duplicate."); 1181 + "' seems to be a duplicate.");
1160 } 1182 }
1161 return success; 1183 return success;
1162 } 1184 }
1163 1185
1164 @Override 1186 @Override
1165 public void hykParsed(HYKParser parser) { 1187 public void hykParsed(final HYKParser parser) {
1166 log.debug("callback from HYK parser"); 1188 log.debug("callback from HYK parser");
1167 ImportHYK hyk = parser.getHYK(); 1189 final ImportHYK hyk = parser.getHYK();
1168 hyk.setRiver(ImportRiver.this); 1190 hyk.setRiver(ImportRiver.this);
1169 hyks.add(hyk); 1191 ImportRiver.this.hyks.add(hyk);
1170 } 1192 }
1171 }); 1193 });
1172 } 1194 }
1173 1195
1174 1196
1176 public void parseW80s() { 1198 public void parseW80s() {
1177 if (Config.INSTANCE.skipW80s()) { 1199 if (Config.INSTANCE.skipW80s()) {
1178 log.info("skip parsing W80s"); 1200 log.info("skip parsing W80s");
1179 return; 1201 return;
1180 } 1202 }
1181 W80Parser parser = new W80Parser(); 1203 final W80Parser parser = new W80Parser();
1182 File riverDir = wstFile 1204 final File riverDir = this.wstFile
1183 .getParentFile() // Basisdaten 1205 .getParentFile() // Basisdaten
1184 .getParentFile() // Hydrologie 1206 .getParentFile() // Hydrologie
1185 .getParentFile(); // <river> 1207 .getParentFile(); // <river>
1186 1208
1187 ImportRiverCrossSectionParserCallback w80Callback = 1209 final ImportRiverCrossSectionParserCallback w80Callback =
1188 new ImportRiverCrossSectionParserCallback("w80"); 1210 new ImportRiverCrossSectionParserCallback("w80");
1189 parser.parseW80s(riverDir, w80Callback); 1211 parser.parseW80s(riverDir, w80Callback);
1190 } 1212 }
1191 1213
1192 /** Create a W80 Parser and parse w80 files found. */ 1214 /** Create a W80 Parser and parse w80 files found. */
1193 public void parseW80CSVs() { 1215 public void parseW80CSVs() {
1194 if (Config.INSTANCE.skipW80CSVs()) { 1216 if (Config.INSTANCE.skipW80CSVs()) {
1195 log.info("skip parsing W80 csvs"); 1217 log.info("skip parsing W80 csvs");
1196 return; 1218 return;
1197 } 1219 }
1198 W80CSVParser parser = new W80CSVParser(); 1220 final W80CSVParser parser = new W80CSVParser();
1199 File riverDir = wstFile 1221 final File riverDir = this.wstFile
1200 .getParentFile() // Basisdaten 1222 .getParentFile() // Basisdaten
1201 .getParentFile() // Hydrologie 1223 .getParentFile() // Hydrologie
1202 .getParentFile(); // <river> 1224 .getParentFile(); // <river>
1203 1225
1204 // Construct the Cross-Section-Data path. 1226 // Construct the Cross-Section-Data path.
1205 File csDir = new File(riverDir.getPath() 1227 final File csDir = new File(riverDir.getPath()
1206 + File.separator + "Geodaesie" 1228 + File.separator + "Geodaesie"
1207 + File.separator + "Querprofile" 1229 + File.separator + "Querprofile"
1208 + File.separator + "QP-Daten"); 1230 + File.separator + "QP-Daten");
1209 1231
1210 ImportRiverCrossSectionParserCallback w80CSVCallback = 1232 final ImportRiverCrossSectionParserCallback w80CSVCallback =
1211 new ImportRiverCrossSectionParserCallback("w80-csv"); 1233 new ImportRiverCrossSectionParserCallback("w80-csv");
1212 parser.parseW80CSVs(csDir, w80CSVCallback); 1234 parser.parseW80CSVs(csDir, w80CSVCallback);
1213 } 1235 }
1214 1236
1215 1237
1216 /** 1238 /**
1220 public void parseDA50s() { 1242 public void parseDA50s() {
1221 if (Config.INSTANCE.skipDA50s()) { 1243 if (Config.INSTANCE.skipDA50s()) {
1222 log.info("skip parsing DA50s"); 1244 log.info("skip parsing DA50s");
1223 return; 1245 return;
1224 } 1246 }
1225 DA50Parser parser = new DA50Parser(); 1247 final DA50Parser parser = new DA50Parser();
1226 File riverDir = wstFile 1248 final File riverDir = this.wstFile
1227 .getParentFile() // Basisdaten 1249 .getParentFile() // Basisdaten
1228 .getParentFile() // Hydrologie 1250 .getParentFile() // Hydrologie
1229 .getParentFile(); // <river> 1251 .getParentFile(); // <river>
1230 1252
1231 ImportRiverCrossSectionParserCallback da50Callback = 1253 final ImportRiverCrossSectionParserCallback da50Callback =
1232 new ImportRiverCrossSectionParserCallback("da50"); 1254 new ImportRiverCrossSectionParserCallback("da50");
1233 1255
1234 parser.parseDA50s(riverDir, da50Callback); 1256 parser.parseDA50s(riverDir, da50Callback);
1235 } 1257 }
1236 1258
1237 1259
1243 log.info("skip parsing DA66s"); 1265 log.info("skip parsing DA66s");
1244 return; 1266 return;
1245 } 1267 }
1246 1268
1247 log.info("looking for DA66 files"); 1269 log.info("looking for DA66 files");
1248 DA66Parser parser = new DA66Parser(); 1270 final DA66Parser parser = new DA66Parser();
1249 File riverDir = wstFile 1271 final File riverDir = this.wstFile
1250 .getParentFile() // Basisdaten 1272 .getParentFile() // Basisdaten
1251 .getParentFile() // Hydrologie 1273 .getParentFile() // Hydrologie
1252 .getParentFile(); // <river> 1274 .getParentFile(); // <river>
1253 1275
1254 ImportRiverCrossSectionParserCallback da66Callback = 1276 final ImportRiverCrossSectionParserCallback da66Callback =
1255 new ImportRiverCrossSectionParserCallback("da66"); 1277 new ImportRiverCrossSectionParserCallback("da66");
1256 1278
1257 parser.parseDA66s(riverDir, da66Callback); 1279 parser.parseDA66s(riverDir, da66Callback);
1258 } 1280 }
1259 1281
1260 /** Create a PRFParser and let it parse the prf files found. */ 1282 /** Create a PRFParser and let it parse the prf files found. */
1263 log.info("skip parsing PRFs"); 1285 log.info("skip parsing PRFs");
1264 return; 1286 return;
1265 } 1287 }
1266 1288
1267 log.info("looking for PRF files"); 1289 log.info("looking for PRF files");
1268 PRFParser parser = new PRFParser(); 1290 final PRFParser parser = new PRFParser();
1269 File riverDir = wstFile 1291 final File riverDir = this.wstFile
1270 .getParentFile() // Basisdaten 1292 .getParentFile() // Basisdaten
1271 .getParentFile() // Hydrologie 1293 .getParentFile() // Hydrologie
1272 .getParentFile(); // <river> 1294 .getParentFile(); // <river>
1273 1295
1274 ImportRiverCrossSectionParserCallback prfCallback = 1296 final ImportRiverCrossSectionParserCallback prfCallback =
1275 new ImportRiverCrossSectionParserCallback("prf"); 1297 new ImportRiverCrossSectionParserCallback("prf");
1276 parser.parsePRFs(riverDir, prfCallback); 1298 parser.parsePRFs(riverDir, prfCallback);
1277 } 1299 }
1278 1300
1279 public static Date yearToDate(int year) { 1301 public static Date yearToDate(final int year) {
1280 Calendar cal = Calendar.getInstance(); 1302 final Calendar cal = Calendar.getInstance();
1281 cal.set(year, 5, 15, 12, 0, 0); 1303 cal.set(year, 5, 15, 12, 0, 0);
1282 long ms = cal.getTimeInMillis(); 1304 final long ms = cal.getTimeInMillis();
1283 cal.setTimeInMillis(ms - ms%1000); 1305 cal.setTimeInMillis(ms - ms%1000);
1284 return cal.getTime(); 1306 return cal.getTime();
1285 } 1307 }
1286 1308
1287 public void storeDependencies() { 1309 public void storeDependencies() {
1288 /* test whether river is already in database. 1310 /* test whether river is already in database.
1289 * Otherwise it makes no sense to skip waterlevel model WST-file 1311 * Otherwise it makes no sense to skip waterlevel model WST-file
1290 * because the altitude reference is taken from there. */ 1312 * because the altitude reference is taken from there. */
1291 Session session = ImporterSession.getInstance().getDatabaseSession(); 1313 final Session session = ImporterSession.getInstance().getDatabaseSession();
1292 Query query = session.createQuery("from River where name=:name"); 1314 final Query query = session.createQuery("from River where name=:name");
1293 query.setString("name", name); 1315 query.setString("name", this.name);
1294 List<River> rivers = query.list(); 1316 final List<River> rivers = query.list();
1295 if (rivers.isEmpty() && Config.INSTANCE.skipWst()){ 1317 if (rivers.isEmpty() && Config.INSTANCE.skipWst()){
1296 log.error("River not yet in database. " 1318 log.error("River not yet in database. "
1297 + "You cannot skip importing waterlevel model."); 1319 + "You cannot skip importing waterlevel model.");
1298 return; 1320 return;
1299 } 1321 }
1300 1322
1301 storeWstUnit(); 1323 storeWstUnit();
1302 storeAnnotations(); 1324 storeAnnotations();
1319 storeSedimentLoad(); 1341 storeSedimentLoad();
1320 storeWaterlevels(); 1342 storeWaterlevels();
1321 storeWaterlevelDifferences(); 1343 storeWaterlevelDifferences();
1322 storeSQRelations(); 1344 storeSQRelations();
1323 storeOfficialNumber(); 1345 storeOfficialNumber();
1346 this.sinfoImporter.store();
1347 this.uinfoImporter.store();
1324 } 1348 }
1325 1349
1326 public void storeWstUnit() { 1350 public void storeWstUnit() {
1327 if (wst == null) { 1351 if (this.wst == null) {
1328 log.warn("No unit given. " 1352 log.warn("No unit given. "
1329 + "Waterlevel-model WST-file has to be imported already."); 1353 + "Waterlevel-model WST-file has to be imported already.");
1330 } 1354 }
1331 else { 1355 else {
1332 wstUnit = wst.getUnit(); 1356 this.wstUnit = this.wst.getUnit();
1333 } 1357 }
1334 } 1358 }
1335 1359
1336 public void storeHYKs() { 1360 public void storeHYKs() {
1337 if (!Config.INSTANCE.skipHYKs()) { 1361 if (!Config.INSTANCE.skipHYKs()) {
1338 log.info("store HYKs"); 1362 log.info("store HYKs");
1339 getPeer(); 1363 getPeer();
1340 for (ImportHYK hyk: hyks) { 1364 for (final ImportHYK hyk: this.hyks) {
1341 hyk.storeDependencies(); 1365 hyk.storeDependencies();
1342 } 1366 }
1343 } 1367 }
1344 } 1368 }
1345 1369
1346 public void storeCrossSections() { 1370 public void storeCrossSections() {
1347 if (!Config.INSTANCE.skipPRFs() 1371 if (!Config.INSTANCE.skipPRFs()
1348 || !Config.INSTANCE.skipDA66s() 1372 || !Config.INSTANCE.skipDA66s()
1349 || !Config.INSTANCE.skipDA50s() 1373 || !Config.INSTANCE.skipDA50s()
1350 || !Config.INSTANCE.skipW80s() 1374 || !Config.INSTANCE.skipW80s()
1351 || !Config.INSTANCE.skipW80CSVs()) { 1375 || !Config.INSTANCE.skipW80CSVs()) {
1352 log.info("store cross sections"); 1376 log.info("store cross sections");
1353 getPeer(); 1377 getPeer();
1354 for (ImportCrossSection crossSection: crossSections) { 1378 for (final ImportCrossSection crossSection: this.crossSections) {
1355 crossSection.storeDependencies(); 1379 crossSection.storeDependencies();
1356 } 1380 }
1357 } 1381 }
1358 } 1382 }
1359 1383
1360 public void storeWst() { 1384 public void storeWst() {
1361 if (wst != null && !Config.INSTANCE.skipWst()) { 1385 if (this.wst != null && !Config.INSTANCE.skipWst()) {
1362 River river = getPeer(); 1386 final River river = getPeer();
1363 wst.storeDependencies(river); 1387 this.wst.storeDependencies(river);
1364 1388
1365 // The flow direction of the main wst and the corresponding 1389 // The flow direction of the main wst and the corresponding
1366 // waterlevels determine if the river is 'km_up'. 1390 // waterlevels determine if the river is 'km_up'.
1367 Session session = ImporterSession.getInstance() 1391 final Session session = ImporterSession.getInstance()
1368 .getDatabaseSession(); 1392 .getDatabaseSession();
1369 river.setKmUp(wst.getKmUp()); 1393 river.setKmUp(this.wst.getKmUp());
1370 session.save(river); 1394 session.save(river);
1371 } 1395 }
1372 } 1396 }
1373 1397
1374 public void storeFixations() { 1398 public void storeFixations() {
1375 if (!Config.INSTANCE.skipFixations()) { 1399 if (!Config.INSTANCE.skipFixations()) {
1376 log.info("store fixation wsts"); 1400 log.info("store fixation wsts");
1377 River river = getPeer(); 1401 final River river = getPeer();
1378 for (ImportWst fWst: fixations) { 1402 for (final ImportWst fWst: this.fixations) {
1379 log.debug("Fixation name: " + fWst.getDescription()); 1403 log.debug("Fixation name: " + fWst.getDescription());
1380 fWst.storeDependencies(river); 1404 fWst.storeDependencies(river);
1381 } 1405 }
1382 } 1406 }
1383 } 1407 }
1385 1409
1386 /** Store wsts from waterlevel-csv files. */ 1410 /** Store wsts from waterlevel-csv files. */
1387 public void storeWaterlevels() { 1411 public void storeWaterlevels() {
1388 if (!Config.INSTANCE.skipWaterlevels()) 1412 if (!Config.INSTANCE.skipWaterlevels())
1389 1413
1390 log.info("store waterlevel wsts from csv"); 1414 log.info("store waterlevel wsts from csv");
1391 River river = getPeer(); 1415 final River river = getPeer();
1392 for (ImportWst wWst: waterlevels) { 1416 for (final ImportWst wWst: this.waterlevels) {
1393 log.debug("Waterlevel name: " + wWst.getDescription()); 1417 log.debug("Waterlevel name: " + wWst.getDescription());
1394 wWst.storeDependencies(river); 1418 wWst.storeDependencies(river);
1395 } 1419 }
1396 } 1420 }
1397 1421
1398 1422
1399 /** Store wsts from waterleveldifference-csv files. */ 1423 /** Store wsts from waterleveldifference-csv files. */
1400 public void storeWaterlevelDifferences() { 1424 public void storeWaterlevelDifferences() {
1401 if (!Config.INSTANCE.skipWaterlevelDifferences()) 1425 if (!Config.INSTANCE.skipWaterlevelDifferences())
1402 1426
1403 log.info("store waterleveldifferences wsts from csv"); 1427 log.info("store waterleveldifferences wsts from csv");
1404 River river = getPeer(); 1428 final River river = getPeer();
1405 for (ImportWst dWst: waterlevelDifferences) { 1429 for (final ImportWst dWst: this.waterlevelDifferences) {
1406 log.debug("water.diff.: name " + dWst.getDescription()); 1430 log.debug("water.diff.: name " + dWst.getDescription());
1407 dWst.storeDependencies(river); 1431 dWst.storeDependencies(river);
1408 } 1432 }
1409 } 1433 }
1410 1434
1411 1435
1412 public void storeExtraWsts() { 1436 public void storeExtraWsts() {
1413 if (!Config.INSTANCE.skipExtraWsts()) { 1437 if (!Config.INSTANCE.skipExtraWsts()) {
1414 log.info("store extra wsts"); 1438 log.info("store extra wsts");
1415 River river = getPeer(); 1439 final River river = getPeer();
1416 for (ImportWst wst: extraWsts) { 1440 for (final ImportWst wst: this.extraWsts) {
1417 log.debug("name: " + wst.getDescription()); 1441 log.debug("name: " + wst.getDescription());
1418 wst.storeDependencies(river); 1442 wst.storeDependencies(river);
1419 } 1443 }
1420 } 1444 }
1421 } 1445 }
1422 1446
1423 public void storeOfficialLines() { 1447 public void storeOfficialLines() {
1424 if (Config.INSTANCE.skipOfficialLines() || officialLines.isEmpty()) { 1448 if (Config.INSTANCE.skipOfficialLines() || this.officialLines.isEmpty()) {
1425 return; 1449 return;
1426 } 1450 }
1427 1451
1428 log.info("store official lines wsts"); 1452 log.info("store official lines wsts");
1429 River river = getPeer(); 1453 final River river = getPeer();
1430 for (ImportWst wst: officialLines) { 1454 for (final ImportWst wst: this.officialLines) {
1431 log.debug("name: " + wst.getDescription()); 1455 log.debug("name: " + wst.getDescription());
1432 wst.storeDependencies(river); 1456 wst.storeDependencies(river);
1433 1457
1434 // Store the official lines after the columns are store. 1458 // Store the official lines after the columns are store.
1435 for (ImportWstColumn wc: wst.getColumns()) { 1459 for (final ImportWstColumn wc: wst.getColumns()) {
1436 ImportOfficialWstColumn owc = (ImportOfficialWstColumn)wc; 1460 final ImportOfficialWstColumn owc = (ImportOfficialWstColumn)wc;
1437 ImportOfficialLine ioc = owc.getOfficialLine(); 1461 final ImportOfficialLine ioc = owc.getOfficialLine();
1438 if (ioc != null) { 1462 if (ioc != null) {
1439 if (ioc.getPeer(river) == null) { 1463 if (ioc.getPeer(river) == null) {
1440 log.warn("Cannot store official line: " 1464 log.warn("Cannot store official line: "
1441 + ioc.getName()); 1465 + ioc.getName());
1442 } 1466 }
1443 } 1467 }
1444 } 1468 }
1445 } 1469 }
1446 } 1470 }
1447 1471
1448 public void storeFloodWater() { 1472 public void storeFloodWater() {
1449 if (!Config.INSTANCE.skipFloodWater()) { 1473 if (!Config.INSTANCE.skipFloodWater()) {
1450 log.info("store flood water wsts"); 1474 log.info("store flood water wsts");
1451 River river = getPeer(); 1475 final River river = getPeer();
1452 for (ImportWst wst: floodWater) { 1476 for (final ImportWst wst: this.floodWater) {
1453 log.debug("name: " + wst.getDescription()); 1477 log.debug("name: " + wst.getDescription());
1454 wst.storeDependencies(river); 1478 wst.storeDependencies(river);
1455 } 1479 }
1456 } 1480 }
1457 } 1481 }
1458 1482
1459 1483
1460 public void storeFloodProtection() { 1484 public void storeFloodProtection() {
1461 if (!Config.INSTANCE.skipFloodProtection()) { 1485 if (!Config.INSTANCE.skipFloodProtection()) {
1462 log.info("store flood protection wsts"); 1486 log.info("store flood protection wsts");
1463 River river = getPeer(); 1487 final River river = getPeer();
1464 for (ImportWst wst: floodProtection) { 1488 for (final ImportWst wst: this.floodProtection) {
1465 log.debug("name: " + wst.getDescription()); 1489 log.debug("name: " + wst.getDescription());
1466 wst.storeDependencies(river); 1490 wst.storeDependencies(river);
1467 } 1491 }
1468 } 1492 }
1469 } 1493 }
1470 1494
1471 1495
1472 public void storeBedHeight() { 1496 public void storeBedHeight() {
1473 if (!Config.INSTANCE.skipBedHeight()) { 1497 if (!Config.INSTANCE.skipBedHeight()) {
1474 log.info("store bed heights"); 1498 log.info("store bed heights");
1475 River river = getPeer(); 1499 final River river = getPeer();
1476 1500
1477 if (bedHeights != null) { 1501 if (this.bedHeights != null) {
1478 for (ImportBedHeight tmp: bedHeights) { 1502 for (final ImportBedHeight tmp: this.bedHeights) {
1479 ImportBedHeight single = (ImportBedHeight) tmp; 1503 final ImportBedHeight single = tmp;
1480 1504
1481 String desc = single.getDescription(); 1505 final String desc = single.getDescription();
1482 1506
1483 log.debug("name: " + desc); 1507 log.debug("name: " + desc);
1484 1508
1485 single.storeDependencies(river); 1509 single.storeDependencies(river);
1486 } 1510 }
1494 1518
1495 public void storeSedimentDensity() { 1519 public void storeSedimentDensity() {
1496 if (!Config.INSTANCE.skipSedimentDensity()) { 1520 if (!Config.INSTANCE.skipSedimentDensity()) {
1497 log.info("store sediment density"); 1521 log.info("store sediment density");
1498 1522
1499 River river = getPeer(); 1523 final River river = getPeer();
1500 1524
1501 for (ImportSedimentDensity density: sedimentDensities) { 1525 for (final ImportSedimentDensity density: this.sedimentDensities) {
1502 String desc = density.getDescription(); 1526 final String desc = density.getDescription();
1503 1527
1504 log.debug("name: " + desc); 1528 log.debug("name: " + desc);
1505 1529
1506 density.storeDependencies(river); 1530 density.storeDependencies(river);
1507 } 1531 }
1510 1534
1511 public void storePorosity() { 1535 public void storePorosity() {
1512 if (!Config.INSTANCE.skipPorosity()) { 1536 if (!Config.INSTANCE.skipPorosity()) {
1513 log.info("store porosity"); 1537 log.info("store porosity");
1514 1538
1515 River river = getPeer(); 1539 final River river = getPeer();
1516 1540
1517 for (ImportPorosity porosity: porosities) { 1541 for (final ImportPorosity porosity: this.porosities) {
1518 String desc = porosity.getDescription(); 1542 final String desc = porosity.getDescription();
1519 1543
1520 log.debug("name: " + desc); 1544 log.debug("name: " + desc);
1521 1545
1522 porosity.storeDependencies(river); 1546 porosity.storeDependencies(river);
1523 } 1547 }
1526 1550
1527 public void storeMorphologicalWidth() { 1551 public void storeMorphologicalWidth() {
1528 if (!Config.INSTANCE.skipMorphologicalWidth()) { 1552 if (!Config.INSTANCE.skipMorphologicalWidth()) {
1529 log.info("store morphological width"); 1553 log.info("store morphological width");
1530 1554
1531 River river = getPeer(); 1555 final River river = getPeer();
1532 1556
1533 for (ImportMorphWidth width: morphologicalWidths) { 1557 for (final ImportMorphWidth width: this.morphologicalWidths) {
1534 width.storeDependencies(river); 1558 width.storeDependencies(river);
1535 } 1559 }
1536 } 1560 }
1537 } 1561 }
1538 1562
1539 public void storeFlowVelocity() { 1563 public void storeFlowVelocity() {
1540 if (!Config.INSTANCE.skipFlowVelocity()) { 1564 if (!Config.INSTANCE.skipFlowVelocity()) {
1541 log.info("store flow velocity"); 1565 log.info("store flow velocity");
1542 1566
1543 River river = getPeer(); 1567 final River river = getPeer();
1544 1568
1545 for (ImportFlowVelocityModel flowVelocityModel: flowVelocityModels 1569 for (final ImportFlowVelocityModel flowVelocityModel: this.flowVelocityModels
1546 ) { 1570 ) {
1547 flowVelocityModel.storeDependencies(river); 1571 flowVelocityModel.storeDependencies(river);
1548 } 1572 }
1549 1573
1550 for (ImportFlowVelocityMeasurement m: flowVelocityMeasurements) { 1574 for (final ImportFlowVelocityMeasurement m: this.flowVelocityMeasurements) {
1551 m.storeDependencies(river); 1575 m.storeDependencies(river);
1552 } 1576 }
1553 } 1577 }
1554 } 1578 }
1555 1579
1556 1580
1557 public void storeSedimentLoadLS() { 1581 public void storeSedimentLoadLS() {
1558 if (!Config.INSTANCE.skipSedimentLoadLS()) { 1582 if (!Config.INSTANCE.skipSedimentLoadLS()) {
1559 log.info("store sediment load longitudinal section data"); 1583 log.info("store sediment load longitudinal section data");
1560 1584
1561 River river = getPeer(); 1585 final River river = getPeer();
1562 1586
1563 for (ImportSedimentLoadLS sedimentLoadLS: sedimentLoadLSs) { 1587 for (final ImportSedimentLoadLS sedimentLoadLS: this.sedimentLoadLSs) {
1564 sedimentLoadLS.storeDependencies(river); 1588 sedimentLoadLS.storeDependencies(river);
1565 } 1589 }
1566 } 1590 }
1567 } 1591 }
1568 1592
1569 1593
1570 public void storeSedimentLoad() { 1594 public void storeSedimentLoad() {
1571 if (!Config.INSTANCE.skipSedimentLoad()) { 1595 if (!Config.INSTANCE.skipSedimentLoad()) {
1572 log.info("store sediment load data at measurement stations"); 1596 log.info("store sediment load data at measurement stations");
1573 1597
1574 for (ImportSedimentLoad sedimentLoad: sedimentLoads) { 1598 for (final ImportSedimentLoad sedimentLoad: this.sedimentLoads) {
1575 sedimentLoad.storeDependencies(); 1599 sedimentLoad.storeDependencies();
1576 } 1600 }
1577 } 1601 }
1578 } 1602 }
1579 1603
1580 1604
1581 public void storeMeasurementStations() { 1605 public void storeMeasurementStations() {
1582 if (!Config.INSTANCE.skipMeasurementStations()) { 1606 if (!Config.INSTANCE.skipMeasurementStations()) {
1583 log.info("store measurement stations"); 1607 log.info("store measurement stations");
1584 1608
1585 River river = getPeer(); 1609 final River river = getPeer();
1586 1610
1587 int count = 0; 1611 int count = 0;
1588 1612
1589 for (ImportMeasurementStation station: measurementStations) { 1613 for (final ImportMeasurementStation station: this.measurementStations) {
1590 boolean success = station.storeDependencies(river); 1614 final boolean success = station.storeDependencies(river);
1591 if (success) { 1615 if (success) {
1592 count++; 1616 count++;
1593 } 1617 }
1594 } 1618 }
1595 1619
1602 if (!Config.INSTANCE.skipSQRelation()) { 1626 if (!Config.INSTANCE.skipSQRelation()) {
1603 log.info("store sq relations"); 1627 log.info("store sq relations");
1604 1628
1605 int count = 0; 1629 int count = 0;
1606 1630
1607 for (ImportSQRelation sqRelation: sqRelations) { 1631 for (final ImportSQRelation sqRelation: this.sqRelations) {
1608 sqRelation.storeDependencies(); 1632 sqRelation.storeDependencies();
1609 count++; 1633 count++;
1610 } 1634 }
1611 1635
1612 log.info("stored " + count + " sq relations."); 1636 log.info("stored " + count + " sq relations.");
1614 } 1638 }
1615 1639
1616 1640
1617 public void storeAnnotations() { 1641 public void storeAnnotations() {
1618 if (!Config.INSTANCE.skipAnnotations()) { 1642 if (!Config.INSTANCE.skipAnnotations()) {
1619 River river = getPeer(); 1643 final River river = getPeer();
1620 for (ImportAnnotation annotation: annotations) { 1644 for (final ImportAnnotation annotation: this.annotations) {
1621 annotation.getPeer(river); 1645 annotation.getPeer(river);
1622 } 1646 }
1623 } 1647 }
1624 } 1648 }
1625 1649
1626 public void storeGauges() { 1650 public void storeGauges() {
1627 if (!Config.INSTANCE.skipGauges()) { 1651 if (!Config.INSTANCE.skipGauges()) {
1628 log.info("store gauges:"); 1652 log.info("store gauges:");
1629 River river = getPeer(); 1653 final River river = getPeer();
1630 Session session = ImporterSession.getInstance() 1654 final Session session = ImporterSession.getInstance()
1631 .getDatabaseSession(); 1655 .getDatabaseSession();
1632 for (ImportGauge gauge: gauges) { 1656 for (final ImportGauge gauge: this.gauges) {
1633 log.info("\tgauge: " + gauge.getName()); 1657 log.info("\tgauge: " + gauge.getName());
1634 gauge.storeDependencies(river); 1658 gauge.storeDependencies(river);
1635 ImporterSession.getInstance().getDatabaseSession(); 1659 ImporterSession.getInstance().getDatabaseSession();
1636 session.flush(); 1660 session.flush();
1637 } 1661 }
1638 } 1662 }
1639 } 1663 }
1640 1664
1641 public River getPeer() { 1665 public River getPeer() {
1642 if (peer == null) { 1666 if (this.peer == null) {
1643 Session session = ImporterSession.getInstance() 1667 final Session session = ImporterSession.getInstance()
1644 .getDatabaseSession(); 1668 .getDatabaseSession();
1645 Query query = session.createQuery("from River where name=:name"); 1669 final Query query = session.createQuery("from River where name=:name");
1646 1670
1647 Unit u = null; 1671 Unit u = null;
1648 if (wstUnit != null) { 1672 if (this.wstUnit != null) {
1649 u = wstUnit.getPeer(); 1673 u = this.wstUnit.getPeer();
1650 } 1674 }
1651 1675
1652 query.setString("name", name); 1676 query.setString("name", this.name);
1653 List<River> rivers = query.list(); 1677 final List<River> rivers = query.list();
1654 if (rivers.isEmpty()) { 1678 if (rivers.isEmpty()) {
1655 log.info("Store new river '" + name + "'"); 1679 log.info("Store new river '" + this.name + "'");
1656 peer = new River(name, u, modelUuid); 1680 this.peer = new River(this.name, u, this.modelUuid);
1657 if (!Config.INSTANCE.skipBWASTR()) { 1681 if (!Config.INSTANCE.skipBWASTR()) {
1658 peer.setOfficialNumber(officialNumber); 1682 this.peer.setOfficialNumber(this.officialNumber);
1659 } 1683 }
1660 session.save(peer); 1684 session.save(this.peer);
1661 } 1685 }
1662 else { 1686 else {
1663 peer = rivers.get(0); 1687 this.peer = rivers.get(0);
1664 } 1688 }
1665 } 1689 }
1666 return peer; 1690 return this.peer;
1667 } 1691 }
1668 } 1692 }
1669 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 1693 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org