annotate backend/src/main/java/org/dive4elements/river/importer/ImportTimeInterval.java @ 5844:4dd33b86dc61

Added header to river backend.
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 26 Apr 2013 08:25:41 +0200
parents 5aa05a7a34b7
children 45871a108aae
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 *
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
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
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
6 * documentation coming with Dive4Elements River for details.
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) {
22858e7cca79 Integrated PRF parsing into importer. Needs testing!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 497
diff changeset
34 this.startTime = startTime;
5811
67e07c29dd29 ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5780
diff changeset
35 this.stopTime = null;
1204
22858e7cca79 Integrated PRF parsing into importer. Needs testing!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 497
diff changeset
36 }
22858e7cca79 Integrated PRF parsing into importer. Needs testing!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 497
diff changeset
37
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
38 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
39 Date start;
5e3c9027e09c avoid NPE in time interval import (made by R. Renkert)
Tom Gottfried <tom.gottfried@intevation.de>
parents: 5775
diff changeset
40 Date stop;
5e3c9027e09c avoid NPE in time interval import (made by R. Renkert)
Tom Gottfried <tom.gottfried@intevation.de>
parents: 5775
diff changeset
41 if (startTime == null) {
5e3c9027e09c avoid NPE in time interval import (made by R. Renkert)
Tom Gottfried <tom.gottfried@intevation.de>
parents: 5775
diff changeset
42 start = stopTime;
5e3c9027e09c avoid NPE in time interval import (made by R. Renkert)
Tom Gottfried <tom.gottfried@intevation.de>
parents: 5775
diff changeset
43 stop = null;
5e3c9027e09c avoid NPE in time interval import (made by R. Renkert)
Tom Gottfried <tom.gottfried@intevation.de>
parents: 5775
diff changeset
44 }
5e3c9027e09c avoid NPE in time interval import (made by R. Renkert)
Tom Gottfried <tom.gottfried@intevation.de>
parents: 5775
diff changeset
45 else {
5e3c9027e09c avoid NPE in time interval import (made by R. Renkert)
Tom Gottfried <tom.gottfried@intevation.de>
parents: 5775
diff changeset
46 start = startTime;
5e3c9027e09c avoid NPE in time interval import (made by R. Renkert)
Tom Gottfried <tom.gottfried@intevation.de>
parents: 5775
diff changeset
47 stop = stopTime;
5e3c9027e09c avoid NPE in time interval import (made by R. Renkert)
Tom Gottfried <tom.gottfried@intevation.de>
parents: 5775
diff changeset
48 }
5e3c9027e09c avoid NPE in time interval import (made by R. Renkert)
Tom Gottfried <tom.gottfried@intevation.de>
parents: 5775
diff changeset
49
5e3c9027e09c avoid NPE in time interval import (made by R. Renkert)
Tom Gottfried <tom.gottfried@intevation.de>
parents: 5775
diff changeset
50 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
51 this.stopTime = start;
5e3c9027e09c avoid NPE in time interval import (made by R. Renkert)
Tom Gottfried <tom.gottfried@intevation.de>
parents: 5775
diff changeset
52 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
53 }
300c0270c576 Switch start- and stoptime if starttime is after stoptime in timeinterval
Raimund Renkert <rrenkert@intevation.de>
parents: 1204
diff changeset
54 else {
5780
5e3c9027e09c avoid NPE in time interval import (made by R. Renkert)
Tom Gottfried <tom.gottfried@intevation.de>
parents: 5775
diff changeset
55 this.startTime = start;
5e3c9027e09c avoid NPE in time interval import (made by R. Renkert)
Tom Gottfried <tom.gottfried@intevation.de>
parents: 5775
diff changeset
56 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
57 }
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
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 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
61 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
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 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
65 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
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 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
69 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
70 }
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 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
73 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
74 }
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 public TimeInterval getPeer() {
493
b35c5dc0f8b7 Importer: Make import of historical discharge tables work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 487
diff changeset
77 if (peer == null) {
497
67fd63e4ef66 Importer: centralized caching
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 493
diff changeset
78 Session session = ImporterSession.getInstance().getDatabaseSession();
5811
67e07c29dd29 ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5780
diff changeset
79 if (startTime == null) {
67e07c29dd29 ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5780
diff changeset
80 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
81 }
67e07c29dd29 ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5780
diff changeset
82 Query query;
67e07c29dd29 ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5780
diff changeset
83 if (stopTime == null) {
67e07c29dd29 ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5780
diff changeset
84 query = session.createQuery(
67e07c29dd29 ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5780
diff changeset
85 "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
86 }
67e07c29dd29 ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5780
diff changeset
87 else {
67e07c29dd29 ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5780
diff changeset
88 query = session.createQuery(
67e07c29dd29 ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5780
diff changeset
89 "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
90 query.setParameter("b", stopTime);
67e07c29dd29 ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5780
diff changeset
91 }
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
92 query.setParameter("a", startTime);
5812
c24820c235d9 ImportTimeInterval: Removed obsolete b parameter setting.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5811
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 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
95 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
96 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
97 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
98 }
487
cf513cbe88c3 Importer: forgot to fetch time interval peer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 486
diff changeset
99 else {
cf513cbe88c3 Importer: forgot to fetch time interval peer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 486
diff changeset
100 peer = intervals.get(0);
cf513cbe88c3 Importer: forgot to fetch time interval peer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 486
diff changeset
101 }
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
102 }
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 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
104 }
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 }
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
106 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org