annotate backend/src/main/java/org/dive4elements/river/model/sinfo/DailyDischargeValue.java @ 9409:38201f5b0dd9

Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
author mschaefer
date Thu, 16 Aug 2018 08:47:41 +0200
parents 34cd4faf43f4
children
rev   line source
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
1 /* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
2 * Software engineering by
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
3 * Björnsen Beratende Ingenieure GmbH
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
5 *
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
6 * This file is Free Software under the GNU AGPL (>=v3)
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
8 * documentation coming with Dive4Elements River for details.
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
9 */
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
10
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
11 package org.dive4elements.river.model.sinfo;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
12
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
13 import java.io.Serializable;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
14 import java.util.Date;
9392
e4a6679b868f Implemented first approach of bundu dynamic main value calculation
mschaefer
parents: 8971
diff changeset
15 import java.util.List;
9409
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
16 import java.util.Map;
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
17 import java.util.TreeMap;
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
18
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
19 import javax.persistence.Column;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
20 import javax.persistence.Entity;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
21 import javax.persistence.GeneratedValue;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
22 import javax.persistence.GenerationType;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
23 import javax.persistence.Id;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
24 import javax.persistence.JoinColumn;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
25 import javax.persistence.OneToOne;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
26 import javax.persistence.SequenceGenerator;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
27 import javax.persistence.Table;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
28
9392
e4a6679b868f Implemented first approach of bundu dynamic main value calculation
mschaefer
parents: 8971
diff changeset
29 import org.dive4elements.river.backend.SessionHolder;
e4a6679b868f Implemented first approach of bundu dynamic main value calculation
mschaefer
parents: 8971
diff changeset
30 import org.dive4elements.river.model.Gauge;
e4a6679b868f Implemented first approach of bundu dynamic main value calculation
mschaefer
parents: 8971
diff changeset
31 import org.hibernate.Query;
9409
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
32 import org.hibernate.SQLQuery;
9392
e4a6679b868f Implemented first approach of bundu dynamic main value calculation
mschaefer
parents: 8971
diff changeset
33 import org.hibernate.Session;
9409
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
34 import org.hibernate.type.StandardBasicTypes;
9392
e4a6679b868f Implemented first approach of bundu dynamic main value calculation
mschaefer
parents: 8971
diff changeset
35
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
36 /**
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
37 * Hibernate binding for the DB table daily_discharge_values
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
38 *
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
39 * @author Matthias Schäfer
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
40 *
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
41 */
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
42 @Entity
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
43 @Table(name = "daily_discharge_values")
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
44 public class DailyDischargeValue implements Serializable {
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
45
9392
e4a6679b868f Implemented first approach of bundu dynamic main value calculation
mschaefer
parents: 8971
diff changeset
46 /***** TYPES *****/
e4a6679b868f Implemented first approach of bundu dynamic main value calculation
mschaefer
parents: 8971
diff changeset
47
e4a6679b868f Implemented first approach of bundu dynamic main value calculation
mschaefer
parents: 8971
diff changeset
48 /**
e4a6679b868f Implemented first approach of bundu dynamic main value calculation
mschaefer
parents: 8971
diff changeset
49 * Field to use in a query's order-by clause
e4a6679b868f Implemented first approach of bundu dynamic main value calculation
mschaefer
parents: 8971
diff changeset
50 *
e4a6679b868f Implemented first approach of bundu dynamic main value calculation
mschaefer
parents: 8971
diff changeset
51 */
e4a6679b868f Implemented first approach of bundu dynamic main value calculation
mschaefer
parents: 8971
diff changeset
52 public enum OrderByField {
e4a6679b868f Implemented first approach of bundu dynamic main value calculation
mschaefer
parents: 8971
diff changeset
53 DAY, DISCHARGE;
e4a6679b868f Implemented first approach of bundu dynamic main value calculation
mschaefer
parents: 8971
diff changeset
54 }
e4a6679b868f Implemented first approach of bundu dynamic main value calculation
mschaefer
parents: 8971
diff changeset
55
9405
34cd4faf43f4 minMax queries
gernotbelger
parents: 9404
diff changeset
56
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
57 /***** FIELDS *****/
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
58
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
59 private static final long serialVersionUID = -6192738825193230784L;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
60
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
61 private Integer id;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
62
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
63 private DailyDischarge dailyDischarge;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
64
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
65 private Date day;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
66
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
67 private Double discharge;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
68
9409
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
69
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
70 /***** CONSTRUCTORS *****/
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
71
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
72 public DailyDischargeValue() {
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
73 }
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
74
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
75 public DailyDischargeValue(final DailyDischarge dailyDischarge, final Date day, final Double discharge) {
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
76 this.dailyDischarge = dailyDischarge;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
77 this.day = day;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
78 this.discharge = discharge;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
79 }
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
80
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
81 /**
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
82 * Parameter constructor with primitive parameter types
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
83 */
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
84 public DailyDischargeValue(final DailyDischarge dailyDischarge, final Date day, final double discharge) {
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
85 this(dailyDischarge, day, Double.valueOf(discharge));
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
86 }
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
87
9409
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
88
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
89 /***** METHODS *****/
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
90
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
91 @Id
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
92 @SequenceGenerator(name = "SEQUENCE_DAILY_DISCHARGE_VALUE_ID_SEQ", sequenceName = "DAILY_DISCHARGE_VALUES_ID_SEQ", allocationSize = 1)
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
93 @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQUENCE_DAILY_DISCHARGE_VALUE_ID_SEQ")
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
94 @Column(name = "id")
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
95 public Integer getId() {
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
96 return this.id;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
97 }
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
98
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
99 public void setId(final Integer id) {
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
100 this.id = id;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
101 }
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
102
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
103 @OneToOne
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
104 @JoinColumn(name = "daily_discharge_id")
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
105 public DailyDischarge getDailyDischarge() {
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
106 return this.dailyDischarge;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
107 }
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
108
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
109 public void setDailyDischarge(final DailyDischarge dailyDischarge) {
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
110 this.dailyDischarge = dailyDischarge;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
111 }
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
112
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
113 @Column(name = "discharge")
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
114 public Double getDischarge() {
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
115 return this.discharge;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
116 }
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
117
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
118 public void setDischarge(final Double discharge) {
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
119 this.discharge = discharge;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
120 }
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
121
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
122 @Column(name = "day")
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
123 public Date getDay() {
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
124 return this.day;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
125 }
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
126
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
127 public void setDay(final Date day) {
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
128 this.day = day;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
129 }
9392
e4a6679b868f Implemented first approach of bundu dynamic main value calculation
mschaefer
parents: 8971
diff changeset
130
e4a6679b868f Implemented first approach of bundu dynamic main value calculation
mschaefer
parents: 8971
diff changeset
131 /**
e4a6679b868f Implemented first approach of bundu dynamic main value calculation
mschaefer
parents: 8971
diff changeset
132 * Selects from the database the daily discharge values of a gauge and a date range
e4a6679b868f Implemented first approach of bundu dynamic main value calculation
mschaefer
parents: 8971
diff changeset
133 */
e4a6679b868f Implemented first approach of bundu dynamic main value calculation
mschaefer
parents: 8971
diff changeset
134 public static List<DailyDischargeValue> getValues(final Gauge gauge, final Date startDate, final Date endDate, final OrderByField orderBy) {
e4a6679b868f Implemented first approach of bundu dynamic main value calculation
mschaefer
parents: 8971
diff changeset
135 final Session session = SessionHolder.HOLDER.get();
e4a6679b868f Implemented first approach of bundu dynamic main value calculation
mschaefer
parents: 8971
diff changeset
136 final String orderField = (orderBy == OrderByField.DISCHARGE) ? "discharge" : "day";
9404
bc9a45d2b1fa common time range for gauges incl. error messages
gernotbelger
parents: 9392
diff changeset
137 final Query query = session.createQuery("SELECT v" + " FROM DailyDischargeValue AS v JOIN v.dailyDischarge AS s"
bc9a45d2b1fa common time range for gauges incl. error messages
gernotbelger
parents: 9392
diff changeset
138 + " WHERE (s.gauge.id=:gaugeid) AND (v.day BETWEEN :startDate AND :endDate)" + " ORDER BY " + orderField);
9392
e4a6679b868f Implemented first approach of bundu dynamic main value calculation
mschaefer
parents: 8971
diff changeset
139 query.setParameter("gaugeid", gauge.getId());
e4a6679b868f Implemented first approach of bundu dynamic main value calculation
mschaefer
parents: 8971
diff changeset
140 query.setParameter("startDate", startDate);
e4a6679b868f Implemented first approach of bundu dynamic main value calculation
mschaefer
parents: 8971
diff changeset
141 query.setParameter("endDate", endDate);
e4a6679b868f Implemented first approach of bundu dynamic main value calculation
mschaefer
parents: 8971
diff changeset
142 return query.list();
e4a6679b868f Implemented first approach of bundu dynamic main value calculation
mschaefer
parents: 8971
diff changeset
143 }
9404
bc9a45d2b1fa common time range for gauges incl. error messages
gernotbelger
parents: 9392
diff changeset
144
bc9a45d2b1fa common time range for gauges incl. error messages
gernotbelger
parents: 9392
diff changeset
145 /**
bc9a45d2b1fa common time range for gauges incl. error messages
gernotbelger
parents: 9392
diff changeset
146 * Selects from the database the daily discharge, puts the first and the last into a List (min, max day)
bc9a45d2b1fa common time range for gauges incl. error messages
gernotbelger
parents: 9392
diff changeset
147 */
9409
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
148 public static Date[] getTimePeriod(final Gauge gauge, final Date fromDay, final Date toDay) {
9404
bc9a45d2b1fa common time range for gauges incl. error messages
gernotbelger
parents: 9392
diff changeset
149 final Session session = SessionHolder.HOLDER.get();
9409
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
150 final Query query = session.createQuery("SELECT MIN(v.day), MAX(v.day)"
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
151 + " FROM DailyDischargeValue AS v JOIN v.dailyDischarge AS s"
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
152 + " WHERE (s.gauge.id=:gaugeid) AND (v.day BETWEEN :startDate AND :endDate)");
9404
bc9a45d2b1fa common time range for gauges incl. error messages
gernotbelger
parents: 9392
diff changeset
153 query.setParameter("gaugeid", gauge.getId());
9409
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
154 query.setDate("startDate", fromDay);
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
155 query.setDate("endDate", toDay);
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
156 final List<Object[]> list = query.list();
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
157 if (!list.isEmpty()) {
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
158 return new Date[] { (Date) list.get(0)[0], (Date) list.get(0)[1] };
9405
34cd4faf43f4 minMax queries
gernotbelger
parents: 9404
diff changeset
159 }
34cd4faf43f4 minMax queries
gernotbelger
parents: 9404
diff changeset
160 return null;
9404
bc9a45d2b1fa common time range for gauges incl. error messages
gernotbelger
parents: 9392
diff changeset
161 }
bc9a45d2b1fa common time range for gauges incl. error messages
gernotbelger
parents: 9392
diff changeset
162
9409
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
163 /**
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
164 * Fetches a map of minimum+maximum daily discharge dates (or null) by gauge for a list of gauges and a time period
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
165 */
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
166 public static Map<Gauge, Date[]> fetchGaugesTimePeriod(final List<Gauge> gauges, final Date fromDay, final Date toDay) {
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
167 final Map<Gauge, Date[]> result = new TreeMap<>();
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
168 final Map<Integer, Gauge> gaugelookup = new TreeMap<>();
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
169 String gaugeids = "";
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
170 String sep = "";
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
171 for (final Gauge gauge : gauges) {
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
172 gaugeids += sep + gauge.getId().toString();
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
173 sep = ",";
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
174 result.put(gauge, null);
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
175 gaugelookup.put(gauge.getId(), gauge);
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
176 }
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
177 final Session session = SessionHolder.HOLDER.get();
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
178 final SQLQuery query = session.createSQLQuery("SELECT g.id AS gauge_id, MIN(v.day) AS min_day, MAX(v.day) AS max_day"
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
179 + "FROM (gauges g LEFT JOIN daily_discharge s ON g.id=s.gauge_id)"
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
180 + " LEFT JOIN daily_discharge_values v ON s.id=v.daily_discharge_id"
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
181 + " WHERE g.id IN (:gaugeids)"
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
182 + " AND v.day BETWEEN :fromDay AND :toDay"
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
183 + " GROUP BY g.id"
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
184 + "UNION SELECT id, NULL, NULL"
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
185 + " FROM gauges"
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
186 + " WHERE id IN (:gaugeids)"
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
187 + " AND id NOT IN "
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
188 +" (SELECT s2.gauge_id FROM daily_discharge s2 INNER JOIN daily_discharge_values v2 ON s2.id=v2.daily_discharge_id"
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
189 + " WHERE v2.day BETWEEN :fromDay AND :toDay)"
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
190 + "ORDER BY 1")
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
191 .addScalar("gauge_id", StandardBasicTypes.INTEGER)
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
192 .addScalar("min_day", StandardBasicTypes.DATE)
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
193 .addScalar("max_day", StandardBasicTypes.DATE);
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
194 query.setString("gaugeids", gaugeids);
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
195 query.setDate("fromDay", fromDay);
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
196 query.setDate("toDay", toDay);
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
197 final List<Object[]> rows = query.list();
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
198 if (!rows.isEmpty()) {
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
199 // TODO handle nulls
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
200 for (int i = 0; i <= rows.size() - 1; i++)
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
201 result.put(gaugelookup.get(rows.get(i)[0]), new Date[] { (Date) rows.get(i)[1], (Date) rows.get(i)[2] });
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
202 return result;
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
203 }
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
204 return new TreeMap<>();
38201f5b0dd9 Changed bundu bzws workflow to stop in case of missing daily discharge values and other minor changes
mschaefer
parents: 9405
diff changeset
205 }
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents:
diff changeset
206 }

http://dive4elements.wald.intevation.org