Mercurial > dive4elements > river
changeset 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 | 738140fe56fe |
children | b35c5dc0f8b7 |
files | flys-backend/ChangeLog flys-backend/src/main/java/de/intevation/flys/importer/AtFileParser.java flys-backend/src/main/java/de/intevation/flys/importer/ImportDischargeTable.java flys-backend/src/main/java/de/intevation/flys/importer/ImportGauge.java |
diffstat | 4 files changed, 78 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-backend/ChangeLog Thu May 05 14:51:54 2011 +0000 +++ b/flys-backend/ChangeLog Thu May 05 15:25:16 2011 +0000 @@ -1,3 +1,16 @@ +2011-05-05 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * src/main/java/de/intevation/flys/importer/AtFileParser.java: + Inject 'kind' attribute. + + * src/main/java/de/intevation/flys/importer/ImportGauge.java: + Traverse the "Histor.Abflusstafeln" for the historical + discharge tables. too. TODO: Store them in the database. + + * src/main/java/de/intevation/flys/importer/ImportDischargeTable.java: + Added convinience constructor to set the kind of the + discharge table. + 2011-05-05 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/java/de/intevation/flys/importer/ImportRiver.java:
--- a/flys-backend/src/main/java/de/intevation/flys/importer/AtFileParser.java Thu May 05 14:51:54 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/AtFileParser.java Thu May 05 15:25:16 2011 +0000 @@ -39,9 +39,11 @@ } - public ImportDischargeTable parse(ImportGauge gauge) throws IOException { + public ImportDischargeTable parse(File file) throws IOException { + return parse(file, 0); + } - File file = gauge.getAtFile(); + public ImportDischargeTable parse(File file, int kind) throws IOException { logger.info("parsing AT file: " + file); @@ -51,7 +53,7 @@ boolean beginning = true; - ImportDischargeTable dischargeTable = new ImportDischargeTable(); + ImportDischargeTable dischargeTable = new ImportDischargeTable(kind); Date from = null; Date to = null; @@ -135,6 +137,7 @@ } if (from != null) { + logger.info("from: " + from + " to: " + to); ImportTimeInterval interval = new ImportTimeInterval(from, to); dischargeTable.setTimeInterval(interval); }
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportDischargeTable.java Thu May 05 14:51:54 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportDischargeTable.java Thu May 05 15:25:16 2011 +0000 @@ -21,7 +21,11 @@ protected ImportTimeInterval timeInterval; public ImportDischargeTable() { - kind = 0; + this(0); + } + + public ImportDischargeTable(int kind) { + this.kind = kind; dischargeTableValues = new ArrayList<ImportDischargeTableValue>(); }
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportGauge.java Thu May 05 14:51:54 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportGauge.java Thu May 05 15:25:16 2011 +0000 @@ -9,13 +9,22 @@ import de.intevation.flys.model.River; import de.intevation.flys.model.Gauge; +import de.intevation.flys.utils.FileTools; + import org.hibernate.Session; import org.hibernate.Query; import java.io.IOException; +import org.apache.log4j.Logger; + public class ImportGauge { + private static Logger log = Logger.getLogger(ImportGauge.class); + + public static final String HISTORICAL_DISCHARGE_TABLES = + "Histor.Abflusstafeln"; + protected ImportRange range; protected File staFile; @@ -132,7 +141,51 @@ sfp.parse(this); AtFileParser afp = new AtFileParser(); - setDischargeTable(afp.parse(this)); + setDischargeTable(afp.parse(getAtFile())); + parseHistoricalDischargeTables(); + } + + public void parseHistoricalDischargeTables() throws IOException { + log.info("parse historical discharge tables"); + + File riverDir = atFile.getParentFile().getParentFile(); + + File histDischargeDir = FileTools.repair( + new File(riverDir, HISTORICAL_DISCHARGE_TABLES)); + + if (!histDischargeDir.isDirectory() || !histDischargeDir.canRead()) { + log.info("cannot find '" + histDischargeDir + "'"); + return; + } + + histDischargeDir = FileTools.repair( + new File(histDischargeDir, getName())); + + if (!histDischargeDir.isDirectory() || !histDischargeDir.canRead()) { + log.info("cannot find '" + histDischargeDir + "'"); + return; + } + + File [] files = histDischargeDir.listFiles(); + + if (files == null) { + log.info("cannot read directory '" + histDischargeDir + "'"); + return; + } + + for (File file: files) { + if (!file.isFile() || !file.canRead()) { + continue; + } + String name = file.getName().toLowerCase(); + if (!name.endsWith(".at")) { + continue; + } + log.info("found at file '" + file.getName() + "'"); + + AtFileParser afp = new AtFileParser(); + ImportDischargeTable dct = afp.parse(file, 1); + } } public void storeDependencies(River river) {