annotate flys-backend/src/main/java/org/dive4elements/river/importer/ImportTimeInterval.java @ 5828:dfb26b03b179

Moved directories to org.dive4elements.river
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 11:53:11 +0200
parents flys-backend/src/main/java/de/intevation/flys/importer/ImportTimeInterval.java@c24820c235d9
children 18619c1e7c2a
rev   line source
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
1 package de.intevation.flys.importer;
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
2
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
3 import de.intevation.flys.model.TimeInterval;
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
4
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
5 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
6 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
7
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
8 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
9 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
10
493
b35c5dc0f8b7 Importer: Make import of historical discharge tables work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 487
diff changeset
11 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
12
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
13 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
14 {
493
b35c5dc0f8b7 Importer: Make import of historical discharge tables work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 487
diff changeset
15 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
16
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
17 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
18 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
19
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
20 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
21
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 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
23 }
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
24
1204
22858e7cca79 Integrated PRF parsing into importer. Needs testing!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 497
diff changeset
25 public ImportTimeInterval(Date startTime) {
22858e7cca79 Integrated PRF parsing into importer. Needs testing!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 497
diff changeset
26 this.startTime = startTime;
5811
67e07c29dd29 ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5780
diff changeset
27 this.stopTime = null;
1204
22858e7cca79 Integrated PRF parsing into importer. Needs testing!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 497
diff changeset
28 }
22858e7cca79 Integrated PRF parsing into importer. Needs testing!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 497
diff changeset
29
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
30 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
31 Date start;
5e3c9027e09c avoid NPE in time interval import (made by R. Renkert)
Tom Gottfried <tom.gottfried@intevation.de>
parents: 5775
diff changeset
32 Date stop;
5e3c9027e09c avoid NPE in time interval import (made by R. Renkert)
Tom Gottfried <tom.gottfried@intevation.de>
parents: 5775
diff changeset
33 if (startTime == null) {
5e3c9027e09c avoid NPE in time interval import (made by R. Renkert)
Tom Gottfried <tom.gottfried@intevation.de>
parents: 5775
diff changeset
34 start = stopTime;
5e3c9027e09c avoid NPE in time interval import (made by R. Renkert)
Tom Gottfried <tom.gottfried@intevation.de>
parents: 5775
diff changeset
35 stop = null;
5e3c9027e09c avoid NPE in time interval import (made by R. Renkert)
Tom Gottfried <tom.gottfried@intevation.de>
parents: 5775
diff changeset
36 }
5e3c9027e09c avoid NPE in time interval import (made by R. Renkert)
Tom Gottfried <tom.gottfried@intevation.de>
parents: 5775
diff changeset
37 else {
5e3c9027e09c avoid NPE in time interval import (made by R. Renkert)
Tom Gottfried <tom.gottfried@intevation.de>
parents: 5775
diff changeset
38 start = startTime;
5e3c9027e09c avoid NPE in time interval import (made by R. Renkert)
Tom Gottfried <tom.gottfried@intevation.de>
parents: 5775
diff changeset
39 stop = stopTime;
5e3c9027e09c avoid NPE in time interval import (made by R. Renkert)
Tom Gottfried <tom.gottfried@intevation.de>
parents: 5775
diff changeset
40 }
5e3c9027e09c avoid NPE in time interval import (made by R. Renkert)
Tom Gottfried <tom.gottfried@intevation.de>
parents: 5775
diff changeset
41
5e3c9027e09c avoid NPE in time interval import (made by R. Renkert)
Tom Gottfried <tom.gottfried@intevation.de>
parents: 5775
diff changeset
42 if (stop != null && start.after(stop)) {
5e3c9027e09c avoid NPE in time interval import (made by R. Renkert)
Tom Gottfried <tom.gottfried@intevation.de>
parents: 5775
diff changeset
43 this.stopTime = start;
5e3c9027e09c avoid NPE in time interval import (made by R. Renkert)
Tom Gottfried <tom.gottfried@intevation.de>
parents: 5775
diff changeset
44 this.startTime = stop;
5775
300c0270c576 Switch start- and stoptime if starttime is after stoptime in timeinterval
Raimund Renkert <rrenkert@intevation.de>
parents: 1204
diff changeset
45 }
300c0270c576 Switch start- and stoptime if starttime is after stoptime in timeinterval
Raimund Renkert <rrenkert@intevation.de>
parents: 1204
diff changeset
46 else {
5780
5e3c9027e09c avoid NPE in time interval import (made by R. Renkert)
Tom Gottfried <tom.gottfried@intevation.de>
parents: 5775
diff changeset
47 this.startTime = start;
5e3c9027e09c avoid NPE in time interval import (made by R. Renkert)
Tom Gottfried <tom.gottfried@intevation.de>
parents: 5775
diff changeset
48 this.stopTime = stop;
5775
300c0270c576 Switch start- and stoptime if starttime is after stoptime in timeinterval
Raimund Renkert <rrenkert@intevation.de>
parents: 1204
diff changeset
49 }
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
50 }
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
51
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
52 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
53 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
54 }
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
55
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
56 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
57 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
58 }
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 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
61 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
62 }
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 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
65 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
66 }
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 public TimeInterval getPeer() {
493
b35c5dc0f8b7 Importer: Make import of historical discharge tables work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 487
diff changeset
69 if (peer == null) {
497
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 493
diff changeset
70 Session session = ImporterSession.getInstance().getDatabaseSession();
5811
67e07c29dd29 ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5780
diff changeset
71 if (startTime == null) {
67e07c29dd29 ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5780
diff changeset
72 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
73 }
67e07c29dd29 ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5780
diff changeset
74 Query query;
67e07c29dd29 ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5780
diff changeset
75 if (stopTime == null) {
67e07c29dd29 ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5780
diff changeset
76 query = session.createQuery(
67e07c29dd29 ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5780
diff changeset
77 "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
78 }
67e07c29dd29 ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5780
diff changeset
79 else {
67e07c29dd29 ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5780
diff changeset
80 query = session.createQuery(
67e07c29dd29 ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5780
diff changeset
81 "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
82 query.setParameter("b", stopTime);
67e07c29dd29 ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5780
diff changeset
83 }
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
84 query.setParameter("a", startTime);
5812
c24820c235d9 ImportTimeInterval: Removed obsolete b parameter setting.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5811
diff changeset
85
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
86 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
87 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
88 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
89 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
90 }
487
cf513cbe88c3 Importer: forgot to fetch time interval peer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 486
diff changeset
91 else {
cf513cbe88c3 Importer: forgot to fetch time interval peer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 486
diff changeset
92 peer = intervals.get(0);
cf513cbe88c3 Importer: forgot to fetch time interval peer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 486
diff changeset
93 }
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
94 }
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 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
96 }
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 }
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 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org