comparison backend/src/main/java/org/dive4elements/river/model/BedHeight.java @ 8559:6d8d7425a6b5

Bed heights are just bed heights since a while ('single' is obsolete).
author "Tom Gottfried <tom@intevation.de>"
date Mon, 16 Feb 2015 11:08:33 +0100
parents backend/src/main/java/org/dive4elements/river/model/BedHeightSingle.java@4c3ccf2b0304
children
comparison
equal deleted inserted replaced
8558:d0ea092a32f5 8559:6d8d7425a6b5
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
2 * Software engineering by Intevation GmbH
3 *
4 * This file is Free Software under the GNU AGPL (>=v3)
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
6 * documentation coming with Dive4Elements River for details.
7 */
8
9 package org.dive4elements.river.model;
10
11 import java.io.Serializable;
12
13 import java.util.ArrayList;
14 import java.util.List;
15
16 import javax.persistence.Entity;
17 import javax.persistence.Id;
18 import javax.persistence.Table;
19 import javax.persistence.GeneratedValue;
20 import javax.persistence.Column;
21 import javax.persistence.SequenceGenerator;
22 import javax.persistence.GenerationType;
23 import javax.persistence.JoinColumn;
24 import javax.persistence.OneToOne;
25 import javax.persistence.OneToMany;
26
27 import org.hibernate.Session;
28 import org.hibernate.Query;
29
30 import org.dive4elements.river.backend.SessionHolder;
31
32
33 @Entity
34 @Table(name = "bed_height")
35 public class BedHeight implements Serializable {
36
37 private Integer id;
38 private Integer year;
39 private Integer soundingWidth;
40
41 private String evaluationBy;
42 private String description;
43
44 private River river;
45
46 private BedHeightType type;
47
48 private LocationSystem locationSystem;
49
50 private ElevationModel curElevationModel;
51
52 private ElevationModel oldElevationModel;
53
54 private Range range;
55
56 private List<BedHeightValue> values;
57
58
59 public BedHeight() {
60 }
61
62
63 public BedHeight(
64 River river,
65 Integer year,
66 Integer soundingWidth,
67 BedHeightType type,
68 LocationSystem locationSystem,
69 ElevationModel curElevationModel,
70 Range range
71 ) {
72 this(
73 river,
74 year,
75 soundingWidth,
76 type,
77 locationSystem,
78 curElevationModel,
79 null,
80 range,
81 null,
82 null);
83 }
84
85
86 public BedHeight(
87 River river,
88 Integer year,
89 Integer soundingWidth,
90 BedHeightType type,
91 LocationSystem locationSystem,
92 ElevationModel curElevationModel,
93 ElevationModel oldElevationModel,
94 Range range,
95 String evaluationBy,
96 String description
97 ) {
98 this.river = river;
99 this.year = year;
100 this.soundingWidth = soundingWidth;
101 this.type = type;
102 this.locationSystem = locationSystem;
103 this.curElevationModel = curElevationModel;
104 this.oldElevationModel = oldElevationModel;
105 this.range = range;
106 this.evaluationBy = evaluationBy;
107 this.description = description;
108 }
109
110
111 @Id
112 @SequenceGenerator(
113 name = "SEQUENCE_BED_HEIGHT_ID_SEQ",
114 sequenceName = "BED_HEIGHT_ID_SEQ",
115 allocationSize = 1)
116 @GeneratedValue(
117 strategy = GenerationType.SEQUENCE,
118 generator = "SEQUENCE_BED_HEIGHT_ID_SEQ")
119 @Column(name = "id")
120 public Integer getId() {
121 return id;
122 }
123
124 public void setId(Integer id) {
125 this.id = id;
126 }
127
128 @OneToOne
129 @JoinColumn(name = "river_id" )
130 public River getRiver() {
131 return river;
132 }
133
134 public void setRiver(River river) {
135 this.river = river;
136 }
137
138 @Column(name = "year")
139 public Integer getYear() {
140 return year;
141 }
142
143 public void setYear(Integer year) {
144 this.year = year;
145 }
146
147 @Column(name = "sounding_width")
148 public Integer getSoundingWidth() {
149 return soundingWidth;
150 }
151
152 public void setSoundingWidth(Integer soundingWidth) {
153 this.soundingWidth = soundingWidth;
154 }
155
156 @OneToOne
157 @JoinColumn(name = "type_id")
158 public BedHeightType getType() {
159 return type;
160 }
161
162 public void setType(BedHeightType type) {
163 this.type = type;
164 }
165
166 @OneToOne
167 @JoinColumn(name = "location_system_id")
168 public LocationSystem getLocationSystem() {
169 return locationSystem;
170 }
171
172 public void setLocationSystem(LocationSystem locationSystem) {
173 this.locationSystem = locationSystem;
174 }
175
176 @OneToOne
177 @JoinColumn(name = "cur_elevation_model_id")
178 public ElevationModel getCurElevationModel() {
179 return curElevationModel;
180 }
181
182 public void setCurElevationModel(ElevationModel curElevationModel) {
183 this.curElevationModel = curElevationModel;
184 }
185
186 @OneToOne
187 @JoinColumn(name = "old_elevation_model_id")
188 public ElevationModel getOldElevationModel() {
189 return oldElevationModel;
190 }
191
192 public void setOldElevationModel(ElevationModel oldElevationModel) {
193 this.oldElevationModel = oldElevationModel;
194 }
195
196 @OneToOne
197 @JoinColumn(name = "range_id")
198 public Range getRange() {
199 return range;
200 }
201
202 public void setRange(Range range) {
203 this.range = range;
204 }
205
206 @Column(name = "evaluation_by")
207 public String getEvaluationBy() {
208 return evaluationBy;
209 }
210
211 public void setEvaluationBy(String evaluationBy) {
212 this.evaluationBy = evaluationBy;
213 }
214
215 @Column(name = "description")
216 public String getDescription() {
217 return description;
218 }
219
220 public void setDescription(String description) {
221 this.description = description;
222 }
223
224 @OneToMany
225 @JoinColumn(name = "bed_height_id")
226 public List<BedHeightValue> getValues() {
227 return values;
228 }
229
230 public void setValues(List<BedHeightValue> values) {
231 this.values = values;
232 }
233
234
235 public static List<BedHeight> getBedHeights(
236 River river,
237 double kmLo,
238 double kmHi
239 ) {
240 Session session = SessionHolder.HOLDER.get();
241
242 Query query = session.createQuery(
243 "from BedHeight where river=:river");
244
245 query.setParameter("river", river);
246
247 // TODO Do km range filtering in SQL statement
248
249 List<BedHeight> singles = query.list();
250 List<BedHeight> good = new ArrayList<BedHeight>();
251
252 for (BedHeight s: singles) {
253 for (BedHeightValue value: s.getValues()) {
254 double station = value.getStation().doubleValue();
255
256 if (station >= kmLo && station <= kmHi) {
257 good.add(s);
258 break;
259 }
260 }
261 }
262
263 return good;
264 }
265
266
267 public static BedHeight getBedHeightById(int id) {
268 Session session = SessionHolder.HOLDER.get();
269
270 Query query = session.createQuery(
271 "from BedHeight where id=:id");
272
273 query.setParameter("id", id);
274
275 List<BedHeight> singles = query.list();
276
277 return singles != null ? singles.get(0) : null;
278 }
279 }
280 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org