Mercurial > dive4elements > river
changeset 493:b35c5dc0f8b7
Importer: Make import of historical discharge tables work.
flys-backend/trunk@1842 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 06 May 2011 10:27:32 +0000 |
parents | 14de9246b356 |
children | 88d5b02ff0c1 |
files | flys-backend/ChangeLog flys-backend/doc/schema/postgresql.sql 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 flys-backend/src/main/java/de/intevation/flys/importer/ImportTimeInterval.java flys-backend/src/main/java/de/intevation/flys/model/DischargeTable.java |
diffstat | 7 files changed, 106 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-backend/ChangeLog Thu May 05 15:25:16 2011 +0000 +++ b/flys-backend/ChangeLog Fri May 06 10:27:32 2011 +0000 @@ -1,3 +1,25 @@ +2011-05-05 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + Make import of historical discharge tables work. + + * doc/schema/postgresql.sql: Added forgotten column 'description'. + + !!! You have to drop your database !!! + + * src/main/java/de/intevation/flys/importer/ImportDischargeTable.java: + src/main/java/de/intevation/flys/model/DischargeTable.java: + Add the forgotten description property. + + * src/main/java/de/intevation/flys/importer/AtFileParser.java: + Fixed problems with date recognition. + + * src/main/java/de/intevation/flys/importer/ImportGauge.java: + Prefix the description of the historical discharge tables + with "Histor.Abflusstafeln". + + * src/main/java/de/intevation/flys/importer/ImportTimeInterval.java: + Fixed silly programming error. + 2011-05-05 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/java/de/intevation/flys/importer/AtFileParser.java:
--- a/flys-backend/doc/schema/postgresql.sql Thu May 05 15:25:16 2011 +0000 +++ b/flys-backend/doc/schema/postgresql.sql Fri May 06 10:27:32 2011 +0000 @@ -114,6 +114,7 @@ CREATE TABLE discharge_tables ( id int PRIMARY KEY NOT NULL, gauge_id int NOT NULL REFERENCES gauges(id), + description VARCHAR(256) NOT NULL, kind int NOT NULL DEFAULT 0, time_interval_id int REFERENCES time_intervals(id),
--- a/flys-backend/src/main/java/de/intevation/flys/importer/AtFileParser.java Thu May 05 15:25:16 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/AtFileParser.java Fri May 06 10:27:32 2011 +0000 @@ -40,10 +40,15 @@ public ImportDischargeTable parse(File file) throws IOException { - return parse(file, 0); + return parse(file, "", 0); } - public ImportDischargeTable parse(File file, int kind) throws IOException { + public ImportDischargeTable parse( + File file, + String prefix, + int kind + ) + throws IOException { logger.info("parsing AT file: " + file); @@ -53,7 +58,8 @@ boolean beginning = true; - ImportDischargeTable dischargeTable = new ImportDischargeTable(kind); + ImportDischargeTable dischargeTable = + new ImportDischargeTable(kind, prefix + file.getName()); Date from = null; Date to = null; @@ -73,8 +79,8 @@ Matcher m = DATE_LINE.matcher(tmp); if (m.matches()) { - from = guessDate(m.group(1), m.group(2), m.group(3)); - to = guessDate(m.group(4), m.group(5), m.group(6)); + from = guessDate(m.group(2), m.group(3), m.group(4)); + to = guessDate(m.group(5), m.group(6), m.group(7)); if (from == null) { Date t = from; from = to; to = t; } @@ -137,6 +143,9 @@ } if (from != null) { + if (to != null && from.compareTo(to) > 0) { + Date t = from; from = to; to = t; + } logger.info("from: " + from + " to: " + to); ImportTimeInterval interval = new ImportTimeInterval(from, to); dischargeTable.setTimeInterval(interval); @@ -152,6 +161,8 @@ return null; } + logger.debug("day: " + day + " month: " + month + " year: " + year); + int dayI = 15; if (day != null) { try { @@ -188,7 +199,9 @@ } Calendar cal = Calendar.getInstance(); - cal.set(yearI, monthI-1, dayI); + cal.set(yearI, monthI-1, dayI, 12, 0, 0); + long ms = cal.getTimeInMillis(); + cal.setTimeInMillis(ms - ms%1000); return cal.getTime(); } }
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportDischargeTable.java Thu May 05 15:25:16 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportDischargeTable.java Fri May 06 10:27:32 2011 +0000 @@ -10,26 +10,40 @@ import de.intevation.flys.model.Gauge; import de.intevation.flys.model.TimeInterval; +import org.apache.log4j.Logger; + public class ImportDischargeTable { protected DischargeTable peer; - protected Integer kind; + protected String description; + + protected Integer kind; protected List<ImportDischargeTableValue> dischargeTableValues; protected ImportTimeInterval timeInterval; public ImportDischargeTable() { - this(0); + this(0, null); } - public ImportDischargeTable(int kind) { - this.kind = kind; + public ImportDischargeTable(int kind, String description) { + this.kind = kind; + this.description = description; dischargeTableValues = new ArrayList<ImportDischargeTableValue>(); } + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public void addDischargeTableValue(ImportDischargeTableValue value) { dischargeTableValues.add(value); } @@ -62,14 +76,16 @@ Query query = session.createQuery( "from DischargeTable where " + - "gauge.id=:gauge and kind=:kind and timeInterval=:interval"); - query.setParameter("gauge", gauge.getId()); - query.setParameter("kind", kind); - query.setParameter("interval", ti); + "gauge.id=:gauge and kind=:kind and " + + "description=:description and timeInterval=:interval"); + query.setParameter("gauge", gauge.getId()); + query.setParameter("description", description); + query.setParameter("kind", kind); + query.setParameter("interval", ti); List<DischargeTable> dischargeTables = query.list(); if (dischargeTables.isEmpty()) { - peer = new DischargeTable(gauge, kind); + peer = new DischargeTable(gauge, description, kind, ti); session.save(peer); } else {
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportGauge.java Thu May 05 15:25:16 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportGauge.java Fri May 06 10:27:32 2011 +0000 @@ -2,6 +2,7 @@ import java.io.File; +import java.util.ArrayList; import java.util.List; import java.math.BigDecimal; @@ -42,11 +43,14 @@ protected List<ImportMainValueType> mainValueTypes; protected List<ImportNamedMainValue> namedMainValues; protected List<ImportMainValue> mainValues; + protected List<ImportDischargeTable> historicalDischargeTables; public ImportGauge() { + historicalDischargeTables = new ArrayList<ImportDischargeTable>(); } public ImportGauge(ImportRange range, File staFile, File atFile) { + this(); this.range = range; this.staFile = staFile; this.atFile = atFile; @@ -184,7 +188,8 @@ log.info("found at file '" + file.getName() + "'"); AtFileParser afp = new AtFileParser(); - ImportDischargeTable dct = afp.parse(file, 1); + historicalDischargeTables.add( + afp.parse(file, HISTORICAL_DISCHARGE_TABLES + "/", 1)); } } @@ -205,14 +210,20 @@ } storeDischargeTable(gauge); + storeHistoricalDischargeTable(gauge); } - public void storeDischargeTable(Gauge gauge) { dischargeTable.getPeer(gauge); dischargeTable.storeDependencies(gauge); } + public void storeHistoricalDischargeTable(Gauge gauge) { + for (ImportDischargeTable hdt: historicalDischargeTables) { + hdt.storeDependencies(gauge); + } + } + public Gauge getPeer(River river) { if (peer == null) { Session session = Importer.sessionHolder.get();
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportTimeInterval.java Thu May 05 15:25:16 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportTimeInterval.java Fri May 06 10:27:32 2011 +0000 @@ -8,8 +8,12 @@ import java.util.List; import java.util.Date; +import org.apache.log4j.Logger; + public class ImportTimeInterval { + private static Logger log = Logger.getLogger(ImportTimeInterval.class); + protected Date startTime; protected Date stopTime; @@ -40,7 +44,7 @@ } public TimeInterval getPeer() { - if (peer != null) { + if (peer == null) { Session session = Importer.sessionHolder.get(); Query query = session.createQuery( "from TimeInterval where startTime=:a and stopTime=:b");
--- a/flys-backend/src/main/java/de/intevation/flys/model/DischargeTable.java Thu May 05 15:25:16 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/DischargeTable.java Fri May 06 10:27:32 2011 +0000 @@ -22,6 +22,7 @@ { private Integer id; private Gauge gauge; + private String description; private Integer kind; private TimeInterval timeInterval; @@ -32,12 +33,19 @@ } public DischargeTable(Gauge gauge) { - this(gauge, 0); + this(gauge, null, 0, null); } - public DischargeTable(Gauge gauge, Integer kind) { - this.gauge = gauge; - this.kind = kind; + public DischargeTable( + Gauge gauge, + String description, + Integer kind, + TimeInterval timeInterval + ) { + this.gauge = gauge; + this.description = description; + this.kind = kind; + this.timeInterval = timeInterval; } @Id @@ -67,6 +75,15 @@ this.gauge = gauge; } + @Column(name = "description") + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + @Column(name = "kind") public Integer getKind() { return kind;