annotate backend/src/main/java/org/dive4elements/river/importer/ImportTimeInterval.java @ 9726:0a5239a1e46e 3.2.x

Upgrade to Log4j 2
author Tom Gottfried <tom@intevation.de>
date Wed, 02 Mar 2022 10:26:50 +0100
parents 5e38e2924c07
children
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
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8856
diff changeset
19 import org.apache.logging.log4j.Logger;
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8856
diff changeset
20 import org.apache.logging.log4j.LogManager;
493
b35c5dc0f8b7 Importer: Make import of historical discharge tables work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 487
diff changeset
21
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
22 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
23 {
9726
0a5239a1e46e Upgrade to Log4j 2
Tom Gottfried <tom@intevation.de>
parents: 8856
diff changeset
24 private static Logger log = LogManager.getLogger(ImportTimeInterval.class);
493
b35c5dc0f8b7 Importer: Make import of historical discharge tables work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 487
diff changeset
25
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
26 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
27 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
28
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 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
30
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 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
32 }
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
33
1204
22858e7cca79 Integrated PRF parsing into importer. Needs testing!
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 497
diff changeset
34 public ImportTimeInterval(Date startTime) {
5896
45871a108aae Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5844
diff changeset
35 this(startTime, 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
5896
45871a108aae Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5844
diff changeset
40 if (startTime != null && stopTime == null) {
45871a108aae Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5844
diff changeset
41 this.startTime = startTime;
45871a108aae Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5844
diff changeset
42 this.stopTime = null;
45871a108aae Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5844
diff changeset
43 }
45871a108aae Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5844
diff changeset
44 else if (startTime == null && stopTime != null) {
45871a108aae Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5844
diff changeset
45 this.startTime = stopTime;
45871a108aae Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5844
diff changeset
46 this.stopTime = null;
45871a108aae Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5844
diff changeset
47 }
45871a108aae Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5844
diff changeset
48 else if (startTime == null && stopTime == null) {
45871a108aae Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5844
diff changeset
49 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
50 }
300c0270c576 Switch start- and stoptime if starttime is after stoptime in timeinterval
Raimund Renkert <rrenkert@intevation.de>
parents: 1204
diff changeset
51 else {
5896
45871a108aae Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5844
diff changeset
52 if (startTime.after(stopTime)) {
45871a108aae Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5844
diff changeset
53 Date t = startTime;
45871a108aae Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5844
diff changeset
54 startTime = stopTime;
45871a108aae Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5844
diff changeset
55 stopTime = t;
45871a108aae Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5844
diff changeset
56 }
45871a108aae Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5844
diff changeset
57 this.startTime = startTime;
45871a108aae Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5844
diff changeset
58 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
59 }
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
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
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 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
63 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
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
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 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
67 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
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
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 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
71 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
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
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 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
75 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
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
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
78 public TimeInterval getPeer() {
493
b35c5dc0f8b7 Importer: Make import of historical discharge tables work.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 487
diff changeset
79 if (peer == null) {
8856
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 5992
diff changeset
80 Session session = ImporterSession.getInstance()
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 5992
diff changeset
81 .getDatabaseSession();
5811
67e07c29dd29 ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5780
diff changeset
82 if (startTime == null) {
67e07c29dd29 ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5780
diff changeset
83 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
84 }
67e07c29dd29 ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5780
diff changeset
85 Query query;
67e07c29dd29 ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5780
diff changeset
86 if (stopTime == null) {
67e07c29dd29 ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5780
diff changeset
87 query = session.createQuery(
8856
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 5992
diff changeset
88 "from TimeInterval "
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 5992
diff changeset
89 + "where startTime=:a and stopTime is null");
5811
67e07c29dd29 ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5780
diff changeset
90 }
67e07c29dd29 ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5780
diff changeset
91 else {
67e07c29dd29 ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5780
diff changeset
92 query = session.createQuery(
67e07c29dd29 ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5780
diff changeset
93 "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
94 query.setParameter("b", stopTime);
67e07c29dd29 ImportTimeInterval: Verbosity increased and fixed bug
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5780
diff changeset
95 }
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
96 query.setParameter("a", startTime);
5812
c24820c235d9 ImportTimeInterval: Removed obsolete b parameter setting.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 5811
diff changeset
97
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
98 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
99 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
100 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
101 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
102 }
487
cf513cbe88c3 Importer: forgot to fetch time interval peer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 486
diff changeset
103 else {
cf513cbe88c3 Importer: forgot to fetch time interval peer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 486
diff changeset
104 peer = intervals.get(0);
cf513cbe88c3 Importer: forgot to fetch time interval peer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 486
diff changeset
105 }
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
106 }
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
107 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
108 }
5896
45871a108aae Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5844
diff changeset
109
45871a108aae Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5844
diff changeset
110 @Override
45871a108aae Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5844
diff changeset
111 public String toString() {
45871a108aae Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5844
diff changeset
112 return "start time: " + startTime + ", stop time: " + stopTime;
45871a108aae Backend: Fixed constructor of ImportTimeInterval.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5844
diff changeset
113 }
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
114 }
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
115 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org