comparison flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java @ 482:3a99d0295006

Importer: Support parsing "zusaetzliche Laengsschnitte". flys-backend/trunk@1801 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 03 May 2011 11:32:11 +0000
parents 3169b559ca3c
children f1fd9cab6a07
comparison
equal deleted inserted replaced
481:73052199f9f6 482:3a99d0295006
1 package de.intevation.flys.importer; 1 package de.intevation.flys.importer;
2 2
3 import java.util.List; 3 import java.util.List;
4 import java.util.ArrayList;
4 5
5 import java.io.File; 6 import java.io.File;
6 import java.io.IOException; 7 import java.io.IOException;
7 8
8 import org.apache.log4j.Logger; 9 import org.apache.log4j.Logger;
18 { 19 {
19 private static Logger log = Logger.getLogger(ImportRiver.class); 20 private static Logger log = Logger.getLogger(ImportRiver.class);
20 21
21 public static final String PEGEL_GLT = "PEGEL.GLT"; 22 public static final String PEGEL_GLT = "PEGEL.GLT";
22 23
24 public static final String EXTRA_LONGITUDINALS =
25 "Zus.L\u00e4ngsschnitte";
26
23 protected String name; 27 protected String name;
24 28
25 protected File wstFile; 29 protected File wstFile;
26 30
27 protected File bbInfoFile; 31 protected File bbInfoFile;
28 32
29 protected List<ImportGauge> gauges; 33 protected List<ImportGauge> gauges;
30 34
31 protected List<ImportAnnotation> annotations; 35 protected List<ImportAnnotation> annotations;
32 36
37 protected List<ImportWst> extraWsts;
38
33 protected ImportWst wst; 39 protected ImportWst wst;
34 40
35 protected River peer; 41 protected River peer;
36 42
37 public ImportRiver() { 43 public ImportRiver() {
44 extraWsts = new ArrayList<ImportWst>();
38 } 45 }
39 46
40 public ImportRiver(String name, File wstFile, File bbInfoFile) { 47 public ImportRiver(String name, File wstFile, File bbInfoFile) {
48 this();
41 this.name = name; 49 this.name = name;
42 this.wstFile = wstFile; 50 this.wstFile = wstFile;
43 this.bbInfoFile = bbInfoFile; 51 this.bbInfoFile = bbInfoFile;
44 } 52 }
45 53
77 85
78 public void parseDependencies() throws IOException { 86 public void parseDependencies() throws IOException {
79 parseGauges(); 87 parseGauges();
80 parseAnnotations(); 88 parseAnnotations();
81 parseWst(); 89 parseWst();
90 parseExtraWsts();
91 }
92
93 public void parseExtraWsts() throws IOException {
94 log.info("Parse extra longitudinal wst files");
95
96 File riverDir = wstFile.getParentFile().getParentFile();
97
98 File extraDir = FileTools.repair(
99 new File(riverDir, EXTRA_LONGITUDINALS));
100
101 if (!extraDir.isDirectory() || !extraDir.canRead()) {
102 log.info("no extra longitudinal wst file directory found");
103 return;
104 }
105
106 File [] files = extraDir.listFiles();
107
108 if (files == null) {
109 log.warn("cannot read extra longitudinal wst file directory");
110 return;
111 }
112
113 for (File file: files) {
114 if (!file.isFile() || !file.canRead()) {
115 continue;
116 }
117 String name = file.getName().toLowerCase();
118 if (!(name.endsWith(".zus") || name.endsWith(".wst"))) {
119 continue;
120 }
121 log.debug("Found WST file: " + file);
122
123 WstParser wstParser = new WstParser();
124 wstParser.parse(file);
125 ImportWst iw = wstParser.getWst();
126 iw.setKind(1);
127 extraWsts.add(iw);
128 }
129
82 } 130 }
83 131
84 public void parseWst() throws IOException { 132 public void parseWst() throws IOException {
85 WstParser wstParser = new WstParser(); 133 WstParser wstParser = new WstParser();
86 wstParser.parse(wstFile); 134 wstParser.parse(wstFile);
116 164
117 public void storeDependencies() { 165 public void storeDependencies() {
118 storeAnnotations(); 166 storeAnnotations();
119 storeGauges(); 167 storeGauges();
120 storeWst(); 168 storeWst();
169 storeExtraWsts();
121 } 170 }
122 171
123 public void storeWst() { 172 public void storeWst() {
124 River river = getPeer(); 173 River river = getPeer();
125 wst.storeDependencies(river); 174 wst.storeDependencies(river);
175 }
176
177 public void storeExtraWsts() {
178 log.info("store extra wsts");
179 River river = getPeer();
180 for (ImportWst wst: extraWsts) {
181 log.debug("name: " + wst.getDescription());
182 wst.storeDependencies(river);
183 }
126 } 184 }
127 185
128 public void storeAnnotations() { 186 public void storeAnnotations() {
129 River river = getPeer(); 187 River river = getPeer();
130 for (ImportAnnotation annotation: annotations) { 188 for (ImportAnnotation annotation: annotations) {

http://dive4elements.wald.intevation.org