Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/importer/ImportGauge.java @ 492:14de9246b356
Importer: parse historical discharge tables, too. TODO: store them in database.
flys-backend/trunk@1840 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 05 May 2011 15:25:16 +0000 |
parents | d37ccb04ab5d |
children | b35c5dc0f8b7 |
comparison
equal
deleted
inserted
replaced
491:738140fe56fe | 492:14de9246b356 |
---|---|
7 import java.math.BigDecimal; | 7 import java.math.BigDecimal; |
8 | 8 |
9 import de.intevation.flys.model.River; | 9 import de.intevation.flys.model.River; |
10 import de.intevation.flys.model.Gauge; | 10 import de.intevation.flys.model.Gauge; |
11 | 11 |
12 import de.intevation.flys.utils.FileTools; | |
13 | |
12 import org.hibernate.Session; | 14 import org.hibernate.Session; |
13 import org.hibernate.Query; | 15 import org.hibernate.Query; |
14 | 16 |
15 import java.io.IOException; | 17 import java.io.IOException; |
16 | 18 |
19 import org.apache.log4j.Logger; | |
20 | |
17 public class ImportGauge | 21 public class ImportGauge |
18 { | 22 { |
23 private static Logger log = Logger.getLogger(ImportGauge.class); | |
24 | |
25 public static final String HISTORICAL_DISCHARGE_TABLES = | |
26 "Histor.Abflusstafeln"; | |
27 | |
19 protected ImportRange range; | 28 protected ImportRange range; |
20 | 29 |
21 protected File staFile; | 30 protected File staFile; |
22 protected File atFile; | 31 protected File atFile; |
23 | 32 |
130 public void parseDependencies() throws IOException { | 139 public void parseDependencies() throws IOException { |
131 StaFileParser sfp = new StaFileParser(); | 140 StaFileParser sfp = new StaFileParser(); |
132 sfp.parse(this); | 141 sfp.parse(this); |
133 | 142 |
134 AtFileParser afp = new AtFileParser(); | 143 AtFileParser afp = new AtFileParser(); |
135 setDischargeTable(afp.parse(this)); | 144 setDischargeTable(afp.parse(getAtFile())); |
145 parseHistoricalDischargeTables(); | |
146 } | |
147 | |
148 public void parseHistoricalDischargeTables() throws IOException { | |
149 log.info("parse historical discharge tables"); | |
150 | |
151 File riverDir = atFile.getParentFile().getParentFile(); | |
152 | |
153 File histDischargeDir = FileTools.repair( | |
154 new File(riverDir, HISTORICAL_DISCHARGE_TABLES)); | |
155 | |
156 if (!histDischargeDir.isDirectory() || !histDischargeDir.canRead()) { | |
157 log.info("cannot find '" + histDischargeDir + "'"); | |
158 return; | |
159 } | |
160 | |
161 histDischargeDir = FileTools.repair( | |
162 new File(histDischargeDir, getName())); | |
163 | |
164 if (!histDischargeDir.isDirectory() || !histDischargeDir.canRead()) { | |
165 log.info("cannot find '" + histDischargeDir + "'"); | |
166 return; | |
167 } | |
168 | |
169 File [] files = histDischargeDir.listFiles(); | |
170 | |
171 if (files == null) { | |
172 log.info("cannot read directory '" + histDischargeDir + "'"); | |
173 return; | |
174 } | |
175 | |
176 for (File file: files) { | |
177 if (!file.isFile() || !file.canRead()) { | |
178 continue; | |
179 } | |
180 String name = file.getName().toLowerCase(); | |
181 if (!name.endsWith(".at")) { | |
182 continue; | |
183 } | |
184 log.info("found at file '" + file.getName() + "'"); | |
185 | |
186 AtFileParser afp = new AtFileParser(); | |
187 ImportDischargeTable dct = afp.parse(file, 1); | |
188 } | |
136 } | 189 } |
137 | 190 |
138 public void storeDependencies(River river) { | 191 public void storeDependencies(River river) { |
139 | 192 |
140 Gauge gauge = getPeer(river); | 193 Gauge gauge = getPeer(river); |