# HG changeset patch # User Sascha L. Teichmann # Date 1304444092 0 # Node ID 8ea09ec7f0c8ff95a15b7f3765ba6f21d0e409ab # Parent 6b231041dc1829cdd3631b3c64ac74e7b269d8ce Importer: Attach a time interval to a discharge table if we find one during import. flys-backend/trunk@1813 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 6b231041dc18 -r 8ea09ec7f0c8 flys-backend/ChangeLog --- a/flys-backend/ChangeLog Tue May 03 17:09:38 2011 +0000 +++ b/flys-backend/ChangeLog Tue May 03 17:34:52 2011 +0000 @@ -1,3 +1,18 @@ +2011-05-03 Sascha L. Teichmann + + * src/main/java/de/intevation/flys/importer/ImportTimeInterval.java: + New. Importer model help fetching the database peer. + + * src/main/java/de/intevation/flys/model/TimeInterval.java: + Add convinience constructor with start and stop time. + + * src/main/java/de/intevation/flys/importer/AtFileParser.java: + Attach a time interval to a discharge table if we find one. + + * src/main/java/de/intevation/flys/importer/ImportDischargeTable.java: + Store the reference to the importer model of the + time interval of the discharge table. + 2011-05-03 Sascha L. Teichmann * src/main/java/de/intevation/flys/importer/AtFileParser.java: diff -r 6b231041dc18 -r 8ea09ec7f0c8 flys-backend/src/main/java/de/intevation/flys/importer/AtFileParser.java --- a/flys-backend/src/main/java/de/intevation/flys/importer/AtFileParser.java Tue May 03 17:09:38 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/AtFileParser.java Tue May 03 17:34:52 2011 +0000 @@ -134,6 +134,11 @@ } } + if (from != null) { + ImportTimeInterval interval = new ImportTimeInterval(from, to); + dischargeTable.setTimeInterval(interval); + } + logger.info("Finished parsing AT file: " + file); return dischargeTable; diff -r 6b231041dc18 -r 8ea09ec7f0c8 flys-backend/src/main/java/de/intevation/flys/importer/ImportDischargeTable.java --- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportDischargeTable.java Tue May 03 17:09:38 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportDischargeTable.java Tue May 03 17:34:52 2011 +0000 @@ -8,7 +8,7 @@ import de.intevation.flys.model.DischargeTable; import de.intevation.flys.model.Gauge; - +import de.intevation.flys.model.TimeInterval; public class ImportDischargeTable { @@ -18,6 +18,7 @@ protected List dischargeTableValues; + protected ImportTimeInterval timeInterval; public ImportDischargeTable() { kind = 0; @@ -39,15 +40,28 @@ return dischargeTableValues; } + public ImportTimeInterval getTimeInterval() { + return timeInterval; + } + + public void setTimeInterval(ImportTimeInterval timeInterval) { + this.timeInterval = timeInterval; + } + public DischargeTable getPeer(Gauge gauge) { if (peer == null) { + TimeInterval ti = timeInterval != null + ? timeInterval.getPeer() + : null; Session session = Importer.sessionHolder.get(); Query query = session.createQuery( - "from DischargeTable where gauge.id=:gauge and kind=:kind"); - query.setParameter("gauge", gauge.getId()); - query.setParameter("kind", kind); + "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); List dischargeTables = query.list(); if (dischargeTables.isEmpty()) { diff -r 6b231041dc18 -r 8ea09ec7f0c8 flys-backend/src/main/java/de/intevation/flys/importer/ImportTimeInterval.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportTimeInterval.java Tue May 03 17:34:52 2011 +0000 @@ -0,0 +1,58 @@ +package de.intevation.flys.importer; + +import de.intevation.flys.model.TimeInterval; + +import org.hibernate.Session; +import org.hibernate.Query; + +import java.util.List; +import java.util.Date; + +public class ImportTimeInterval +{ + protected Date startTime; + protected Date stopTime; + + protected TimeInterval peer; + + public ImportTimeInterval() { + } + + public ImportTimeInterval(Date startTime, Date stopTime) { + this.startTime = startTime; + this.stopTime = stopTime; + } + + public Date getStartTime() { + return startTime; + } + + public void setStartTime(Date startTime) { + this.startTime = startTime; + } + + public Date getStopTime() { + return stopTime; + } + + public void setStopTime(Date stopTime) { + this.stopTime = stopTime; + } + + public TimeInterval getPeer() { + if (peer != null) { + Session session = Importer.sessionHolder.get(); + Query query = session.createQuery( + "from TimeInterval where startTime=:a and stopTime=:b"); + query.setParameter("a", startTime); + query.setParameter("b", stopTime); + List intervals = query.list(); + if (intervals.isEmpty()) { + peer = new TimeInterval(startTime, stopTime); + session.save(peer); + } + } + return peer; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 6b231041dc18 -r 8ea09ec7f0c8 flys-backend/src/main/java/de/intevation/flys/model/TimeInterval.java --- a/flys-backend/src/main/java/de/intevation/flys/model/TimeInterval.java Tue May 03 17:09:38 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/TimeInterval.java Tue May 03 17:34:52 2011 +0000 @@ -24,6 +24,11 @@ public TimeInterval() { } + public TimeInterval(Date startTime, Date stopTime) { + this.startTime = startTime; + this.stopTime = stopTime; + } + @Id @SequenceGenerator( name = "SEQUENCE_TIME_INTERVALS_ID_SEQ",