comparison backend/src/main/java/org/dive4elements/river/importer/uinfo/UInfoImporter.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.uinfo;
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.uinfo.parsers.SalixParser;
22
23 /**
24 * Import all S-INFO files of a river from its import directory and subdirectories<br />
25 * <br />
26 * Requires river and its gauges to exist in the database already
27 *
28 * @author Matthias Schäfer
29 *
30 */
31 public class UInfoImporter
32 {
33 /***** FIELDS *****/
34
35 private static final Logger log = Logger.getLogger(UInfoImporter.class);
36
37 private static final String UINFO_DIR = "Oekologie";
38
39 private enum UInfoDirName {
40 BASICS("Basisdaten"), //
41 SALIX("Salix-Linie_Fluss-Aue-Konnektivitaet" + File.separator + "Salix-Linie");
42
43 private final String dirname;
44
45 UInfoDirName(final String dirname) {
46 this.dirname = dirname;
47 }
48
49 public String getDir() {
50 return this.dirname;
51 }
52 public File getFile() {
53 return new File(getDir());
54 }
55
56 public File buildPath(final File rootDir) {
57 return new File(rootDir, getDir());
58 }
59 }
60
61 /**
62 * Series of river's stations with bed mobility flag.
63 */
64 private final List<ImportParser> parsers;
65
66 /**
67 * Path of the S-INFO data directory of the importing river.
68 */
69 private File rootDir;
70
71
72 /***** CONSTRUCTOR *****/
73
74 public UInfoImporter() {
75 this.parsers = new ArrayList<>();
76 }
77
78 /***** METHODS *****/
79
80 /**
81 * Inits the parser list regarding the skip flags.
82 */
83 public void setup(final File riverDir, final ImportRiver river) {
84 this.rootDir = new File(riverDir, UINFO_DIR);
85 log.info("Parse U-INFO files from " + this.rootDir);
86 this.parsers.clear();
87 if (!SalixParser.shallSkip()) {
88 if (!this.parsers.addAll(SalixParser.createParsers(UInfoDirName.SALIX.buildPath(this.rootDir), UInfoDirName.SALIX.getFile(), river)))
89 log.info("Salix: no files found");
90 }
91 else {
92 log.info("Salix: skipped");
93 }
94 }
95
96 /**
97 * Imports the files according to the active parser list
98 */
99 public void parse() throws IOException {
100 for (final ImportParser parser : this.parsers)
101 parser.parse();
102 }
103
104 /**
105 * Stores all pending import objects
106 */
107 public void store() {
108 for (final ImportParser parser : this.parsers)
109 parser.store();
110 }
111
112 }

http://dive4elements.wald.intevation.org