Mercurial > dive4elements > river
annotate backend/src/main/java/org/dive4elements/river/importer/ImportTimeInterval.java @ 6890:8ca5d0e3c438 double-precision
BWASTR-Import: name of tributary contains name of river, not the other way round.
author | Tom Gottfried <tom.gottfried@intevation.de> |
---|---|
date | Wed, 21 Aug 2013 15:32:53 +0200 |
parents | 4c3ccf2b0304 |
children | 5e38e2924c07 |
rev | line source |
---|---|
5844
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
2 * Software engineering by Intevation GmbH |
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
3 * |
5992
4c3ccf2b0304
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5896
diff
changeset
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
5844
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
5992
4c3ccf2b0304
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5896
diff
changeset
|
6 * documentation coming with Dive4Elements River for details. |
5844
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
7 */ |
4dd33b86dc61
Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
8 |
5829
18619c1e7c2a
Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5828
diff
changeset
|
9 package org.dive4elements.river.importer; |
486
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 |
5829
18619c1e7c2a
Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5828
diff
changeset
|
11 import org.dive4elements.river.model.TimeInterval; |
486
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 import org.hibernate.Session; |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 import org.hibernate.Query; |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import java.util.List; |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 import java.util.Date; |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 |
493
b35c5dc0f8b7
Importer: Make import of historical discharge tables work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
487
diff
changeset
|
19 import org.apache.log4j.Logger; |
b35c5dc0f8b7
Importer: Make import of historical discharge tables work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
487
diff
changeset
|
20 |
486
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 public class ImportTimeInterval |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 { |
493
b35c5dc0f8b7
Importer: Make import of historical discharge tables work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
487
diff
changeset
|
23 private static Logger log = Logger.getLogger(ImportTimeInterval.class); |
b35c5dc0f8b7
Importer: Make import of historical discharge tables work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
487
diff
changeset
|
24 |
486
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 protected Date startTime; |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 protected Date stopTime; |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 protected TimeInterval peer; |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 public ImportTimeInterval() { |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 } |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 |
1204
22858e7cca79
Integrated PRF parsing into importer. Needs testing!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
497
diff
changeset
|
33 public ImportTimeInterval(Date startTime) { |
5896
45871a108aae
Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5844
diff
changeset
|
34 this(startTime, null); |
1204
22858e7cca79
Integrated PRF parsing into importer. Needs testing!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
497
diff
changeset
|
35 } |
22858e7cca79
Integrated PRF parsing into importer. Needs testing!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
497
diff
changeset
|
36 |
486
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 public ImportTimeInterval(Date startTime, Date stopTime) { |
5780
5e3c9027e09c
avoid NPE in time interval import (made by R. Renkert)
Tom Gottfried <tom.gottfried@intevation.de>
parents:
5775
diff
changeset
|
38 |
5896
45871a108aae
Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5844
diff
changeset
|
39 if (startTime != null && stopTime == null) { |
45871a108aae
Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5844
diff
changeset
|
40 this.startTime = startTime; |
45871a108aae
Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5844
diff
changeset
|
41 this.stopTime = null; |
45871a108aae
Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5844
diff
changeset
|
42 } |
45871a108aae
Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5844
diff
changeset
|
43 else if (startTime == null && stopTime != null) { |
45871a108aae
Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5844
diff
changeset
|
44 this.startTime = stopTime; |
45871a108aae
Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5844
diff
changeset
|
45 this.stopTime = null; |
45871a108aae
Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5844
diff
changeset
|
46 } |
45871a108aae
Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5844
diff
changeset
|
47 else if (startTime == null && stopTime == null) { |
45871a108aae
Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5844
diff
changeset
|
48 throw new IllegalArgumentException("Both dates are null."); |
5775
300c0270c576
Switch start- and stoptime if starttime is after stoptime in timeinterval
Raimund Renkert <rrenkert@intevation.de>
parents:
1204
diff
changeset
|
49 } |
300c0270c576
Switch start- and stoptime if starttime is after stoptime in timeinterval
Raimund Renkert <rrenkert@intevation.de>
parents:
1204
diff
changeset
|
50 else { |
5896
45871a108aae
Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5844
diff
changeset
|
51 if (startTime.after(stopTime)) { |
45871a108aae
Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5844
diff
changeset
|
52 Date t = startTime; |
45871a108aae
Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5844
diff
changeset
|
53 startTime = stopTime; |
45871a108aae
Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5844
diff
changeset
|
54 stopTime = t; |
45871a108aae
Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5844
diff
changeset
|
55 } |
45871a108aae
Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5844
diff
changeset
|
56 this.startTime = startTime; |
45871a108aae
Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5844
diff
changeset
|
57 this.stopTime = stopTime; |
5775
300c0270c576
Switch start- and stoptime if starttime is after stoptime in timeinterval
Raimund Renkert <rrenkert@intevation.de>
parents:
1204
diff
changeset
|
58 } |
486
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 } |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 public Date getStartTime() { |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 return startTime; |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 } |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 public void setStartTime(Date startTime) { |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 this.startTime = startTime; |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 } |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 public Date getStopTime() { |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 return stopTime; |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 } |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 public void setStopTime(Date stopTime) { |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 this.stopTime = stopTime; |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 } |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 public TimeInterval getPeer() { |
493
b35c5dc0f8b7
Importer: Make import of historical discharge tables work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
487
diff
changeset
|
78 if (peer == null) { |
497
67fd63e4ef66
Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
493
diff
changeset
|
79 Session session = ImporterSession.getInstance().getDatabaseSession(); |
5811
67e07c29dd29
ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5780
diff
changeset
|
80 if (startTime == null) { |
67e07c29dd29
ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5780
diff
changeset
|
81 log.error("Null Start time will be ignored."); |
67e07c29dd29
ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5780
diff
changeset
|
82 } |
67e07c29dd29
ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5780
diff
changeset
|
83 Query query; |
67e07c29dd29
ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5780
diff
changeset
|
84 if (stopTime == null) { |
67e07c29dd29
ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5780
diff
changeset
|
85 query = session.createQuery( |
67e07c29dd29
ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5780
diff
changeset
|
86 "from TimeInterval where startTime=:a and stopTime is null"); |
67e07c29dd29
ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5780
diff
changeset
|
87 } |
67e07c29dd29
ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5780
diff
changeset
|
88 else { |
67e07c29dd29
ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5780
diff
changeset
|
89 query = session.createQuery( |
67e07c29dd29
ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5780
diff
changeset
|
90 "from TimeInterval where startTime=:a and stopTime=:b"); |
67e07c29dd29
ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5780
diff
changeset
|
91 query.setParameter("b", stopTime); |
67e07c29dd29
ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5780
diff
changeset
|
92 } |
486
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 query.setParameter("a", startTime); |
5812
c24820c235d9
ImportTimeInterval: Removed obsolete b parameter setting.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
5811
diff
changeset
|
94 |
486
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 List<TimeInterval> intervals = query.list(); |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 if (intervals.isEmpty()) { |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
97 peer = new TimeInterval(startTime, stopTime); |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
98 session.save(peer); |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
99 } |
487
cf513cbe88c3
Importer: forgot to fetch time interval peer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
486
diff
changeset
|
100 else { |
cf513cbe88c3
Importer: forgot to fetch time interval peer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
486
diff
changeset
|
101 peer = intervals.get(0); |
cf513cbe88c3
Importer: forgot to fetch time interval peer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
486
diff
changeset
|
102 } |
486
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
103 } |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
104 return peer; |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
105 } |
5896
45871a108aae
Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5844
diff
changeset
|
106 |
45871a108aae
Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5844
diff
changeset
|
107 @Override |
45871a108aae
Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5844
diff
changeset
|
108 public String toString() { |
45871a108aae
Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5844
diff
changeset
|
109 return "start time: " + startTime + ", stop time: " + stopTime; |
45871a108aae
Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5844
diff
changeset
|
110 } |
486
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 } |
8ea09ec7f0c8
Importer: Attach a time interval to a discharge table if we find one during import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
112 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |