comparison backend/src/main/java/org/dive4elements/river/model/BedHeight.java @ 8975:a0a0a7f912ab

Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
author mschaefer
date Tue, 03 Apr 2018 10:40:57 +0200
parents 11bf13cf0463
children 4c5eeaff554c
comparison
equal deleted inserted replaced
8974:a275ddf7a3a1 8975:a0a0a7f912ab
7 */ 7 */
8 8
9 package org.dive4elements.river.model; 9 package org.dive4elements.river.model;
10 10
11 import java.io.Serializable; 11 import java.io.Serializable;
12
13 import java.util.ArrayList; 12 import java.util.ArrayList;
14 import java.util.List; 13 import java.util.List;
15 14
15 import javax.persistence.Column;
16 import javax.persistence.Entity; 16 import javax.persistence.Entity;
17 import javax.persistence.GeneratedValue;
18 import javax.persistence.GenerationType;
17 import javax.persistence.Id; 19 import javax.persistence.Id;
20 import javax.persistence.JoinColumn;
21 import javax.persistence.OneToMany;
22 import javax.persistence.OneToOne;
23 import javax.persistence.SequenceGenerator;
18 import javax.persistence.Table; 24 import javax.persistence.Table;
19 import javax.persistence.GeneratedValue; 25
20 import javax.persistence.Column; 26 import org.dive4elements.river.backend.SessionHolder;
21 import javax.persistence.SequenceGenerator; 27 import org.hibernate.Query;
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.Session;
28 import org.hibernate.Query;
29
30 import org.dive4elements.river.backend.SessionHolder;
31 29
32 30
33 @Entity 31 @Entity
34 @Table(name = "bed_height") 32 @Table(name = "bed_height")
35 public class BedHeight implements Serializable { 33 public class BedHeight implements Serializable {
50 48
51 private ElevationModel oldElevationModel; 49 private ElevationModel oldElevationModel;
52 50
53 private Range range; 51 private Range range;
54 52
53 private String sounding_width_info;
54 private String comment;
55
55 private List<BedHeightValue> values; 56 private List<BedHeightValue> values;
56 57
57 58
58 public BedHeight() { 59 public BedHeight() {
59 } 60 }
60 61
61 62
62 public BedHeight( 63 public BedHeight(final River river, final Integer year, final BedHeightType type, final LocationSystem locationSystem,
63 River river, 64 final ElevationModel curElevationModel,
64 Integer year, 65 final Range range) {
65 BedHeightType type, 66 this(river, year, type, locationSystem, curElevationModel, null, range, null, null, null, null);
66 LocationSystem locationSystem, 67 }
67 ElevationModel curElevationModel, 68
68 Range range 69
69 ) { 70 public BedHeight(final River river, final Integer year, final BedHeightType type, final LocationSystem locationSystem,
70 this( 71 final ElevationModel curElevationModel,
71 river, 72 final ElevationModel oldElevationModel, final Range range, final String evaluationBy, final String description, final String sounding_width_info,
72 year, 73 final String comment) {
73 type,
74 locationSystem,
75 curElevationModel,
76 null,
77 range,
78 null,
79 null);
80 }
81
82
83 public BedHeight(
84 River river,
85 Integer year,
86 BedHeightType type,
87 LocationSystem locationSystem,
88 ElevationModel curElevationModel,
89 ElevationModel oldElevationModel,
90 Range range,
91 String evaluationBy,
92 String description
93 ) {
94 this.river = river; 74 this.river = river;
95 this.year = year; 75 this.year = year;
96 this.type = type; 76 this.type = type;
97 this.locationSystem = locationSystem; 77 this.locationSystem = locationSystem;
98 this.curElevationModel = curElevationModel; 78 this.curElevationModel = curElevationModel;
99 this.oldElevationModel = oldElevationModel; 79 this.oldElevationModel = oldElevationModel;
100 this.range = range; 80 this.range = range;
101 this.evaluationBy = evaluationBy; 81 this.evaluationBy = evaluationBy;
102 this.description = description; 82 this.description = description;
83 this.sounding_width_info = sounding_width_info;
84 this.comment = comment;
103 } 85 }
104 86
105 87
106 @Id 88 @Id
107 @SequenceGenerator( 89 @SequenceGenerator(name = "SEQUENCE_BED_HEIGHT_ID_SEQ", sequenceName = "BED_HEIGHT_ID_SEQ", allocationSize = 1)
108 name = "SEQUENCE_BED_HEIGHT_ID_SEQ", 90 @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQUENCE_BED_HEIGHT_ID_SEQ")
109 sequenceName = "BED_HEIGHT_ID_SEQ",
110 allocationSize = 1)
111 @GeneratedValue(
112 strategy = GenerationType.SEQUENCE,
113 generator = "SEQUENCE_BED_HEIGHT_ID_SEQ")
114 @Column(name = "id") 91 @Column(name = "id")
115 public Integer getId() { 92 public Integer getId() {
116 return id; 93 return this.id;
117 } 94 }
118 95
119 public void setId(Integer id) { 96 public void setId(final Integer id) {
120 this.id = id; 97 this.id = id;
121 } 98 }
122 99
123 @OneToOne 100 @OneToOne
124 @JoinColumn(name = "river_id") 101 @JoinColumn(name = "river_id")
125 public River getRiver() { 102 public River getRiver() {
126 return river; 103 return this.river;
127 } 104 }
128 105
129 public void setRiver(River river) { 106 public void setRiver(final River river) {
130 this.river = river; 107 this.river = river;
131 } 108 }
132 109
133 @Column(name = "year") 110 @Column(name = "year")
134 public Integer getYear() { 111 public Integer getYear() {
135 return year; 112 return this.year;
136 } 113 }
137 114
138 public void setYear(Integer year) { 115 public void setYear(final Integer year) {
139 this.year = year; 116 this.year = year;
140 } 117 }
141 118
142 @OneToOne 119 @OneToOne
143 @JoinColumn(name = "type_id") 120 @JoinColumn(name = "type_id")
144 public BedHeightType getType() { 121 public BedHeightType getType() {
145 return type; 122 return this.type;
146 } 123 }
147 124
148 public void setType(BedHeightType type) { 125 public void setType(final BedHeightType type) {
149 this.type = type; 126 this.type = type;
150 } 127 }
151 128
152 @OneToOne 129 @OneToOne
153 @JoinColumn(name = "location_system_id") 130 @JoinColumn(name = "location_system_id")
154 public LocationSystem getLocationSystem() { 131 public LocationSystem getLocationSystem() {
155 return locationSystem; 132 return this.locationSystem;
156 } 133 }
157 134
158 public void setLocationSystem(LocationSystem locationSystem) { 135 public void setLocationSystem(final LocationSystem locationSystem) {
159 this.locationSystem = locationSystem; 136 this.locationSystem = locationSystem;
160 } 137 }
161 138
162 @OneToOne 139 @OneToOne
163 @JoinColumn(name = "cur_elevation_model_id") 140 @JoinColumn(name = "cur_elevation_model_id")
164 public ElevationModel getCurElevationModel() { 141 public ElevationModel getCurElevationModel() {
165 return curElevationModel; 142 return this.curElevationModel;
166 } 143 }
167 144
168 public void setCurElevationModel(ElevationModel curElevationModel) { 145 public void setCurElevationModel(final ElevationModel curElevationModel) {
169 this.curElevationModel = curElevationModel; 146 this.curElevationModel = curElevationModel;
170 } 147 }
171 148
172 @OneToOne 149 @OneToOne
173 @JoinColumn(name = "old_elevation_model_id") 150 @JoinColumn(name = "old_elevation_model_id")
174 public ElevationModel getOldElevationModel() { 151 public ElevationModel getOldElevationModel() {
175 return oldElevationModel; 152 return this.oldElevationModel;
176 } 153 }
177 154
178 public void setOldElevationModel(ElevationModel oldElevationModel) { 155 public void setOldElevationModel(final ElevationModel oldElevationModel) {
179 this.oldElevationModel = oldElevationModel; 156 this.oldElevationModel = oldElevationModel;
180 } 157 }
181 158
182 @OneToOne 159 @OneToOne
183 @JoinColumn(name = "range_id") 160 @JoinColumn(name = "range_id")
184 public Range getRange() { 161 public Range getRange() {
185 return range; 162 return this.range;
186 } 163 }
187 164
188 public void setRange(Range range) { 165 public void setRange(final Range range) {
189 this.range = range; 166 this.range = range;
190 } 167 }
191 168
192 @Column(name = "evaluation_by") 169 @Column(name = "evaluation_by")
193 public String getEvaluationBy() { 170 public String getEvaluationBy() {
194 return evaluationBy; 171 return this.evaluationBy;
195 } 172 }
196 173
197 public void setEvaluationBy(String evaluationBy) { 174 public void setEvaluationBy(final String evaluationBy) {
198 this.evaluationBy = evaluationBy; 175 this.evaluationBy = evaluationBy;
199 } 176 }
200 177
201 @Column(name = "description") 178 @Column(name = "description")
202 public String getDescription() { 179 public String getDescription() {
203 return description; 180 return this.description;
204 } 181 }
205 182
206 public void setDescription(String description) { 183 public void setDescription(final String description) {
207 this.description = description; 184 this.description = description;
185 }
186
187 @Column(name = "sounding_width_info")
188 public String getSoundingWidthInfo() {
189 return this.sounding_width_info;
190 }
191
192 public void setSoundingWidthInfo(final String sounding_width_info) {
193 this.sounding_width_info = sounding_width_info;
194 }
195
196 @Column(name = "comment")
197 public String getComment() {
198 return this.comment;
199 }
200
201 public void setComment(final String comment) {
202 this.comment = comment;
208 } 203 }
209 204
210 @OneToMany 205 @OneToMany
211 @JoinColumn(name = "bed_height_id") 206 @JoinColumn(name = "bed_height_id")
212 public List<BedHeightValue> getValues() { 207 public List<BedHeightValue> getValues() {
213 return values; 208 return this.values;
214 } 209 }
215 210
216 public void setValues(List<BedHeightValue> values) { 211 public void setValues(final List<BedHeightValue> values) {
217 this.values = values; 212 this.values = values;
218 } 213 }
219 214
220 215
221 public static List<BedHeight> getBedHeights( 216 public static List<BedHeight> getBedHeights(
222 River river, 217 final River river,
223 double kmLo, 218 final double kmLo,
224 double kmHi 219 final double kmHi
225 ) { 220 ) {
226 Session session = SessionHolder.HOLDER.get(); 221 final Session session = SessionHolder.HOLDER.get();
227 222
228 Query query = session.createQuery( 223 final Query query = session.createQuery(
229 "from BedHeight where river=:river"); 224 "from BedHeight where river=:river");
230 225
231 query.setParameter("river", river); 226 query.setParameter("river", river);
232 227
233 // TODO Do km range filtering in SQL statement 228 // TODO Do km range filtering in SQL statement
234 229
235 List<BedHeight> singles = query.list(); 230 final List<BedHeight> singles = query.list();
236 List<BedHeight> good = new ArrayList<BedHeight>(); 231 final List<BedHeight> good = new ArrayList<>();
237 232
238 for (BedHeight s: singles) { 233 for (final BedHeight s: singles) {
239 for (BedHeightValue value: s.getValues()) { 234 for (final BedHeightValue value: s.getValues()) {
240 double station = value.getStation().doubleValue(); 235 final double station = value.getStation().doubleValue();
241 236
242 if (station >= kmLo && station <= kmHi) { 237 if (station >= kmLo && station <= kmHi) {
243 good.add(s); 238 good.add(s);
244 break; 239 break;
245 } 240 }
248 243
249 return good; 244 return good;
250 } 245 }
251 246
252 247
253 public static BedHeight getBedHeightById(int id) { 248 public static BedHeight getBedHeightById(final int id) {
254 Session session = SessionHolder.HOLDER.get(); 249 final Session session = SessionHolder.HOLDER.get();
255 250
256 Query query = session.createQuery( 251 final Query query = session.createQuery(
257 "from BedHeight where id=:id"); 252 "from BedHeight where id=:id");
258 253
259 query.setParameter("id", id); 254 query.setParameter("id", id);
260 255
261 List<BedHeight> singles = query.list(); 256 final List<BedHeight> singles = query.list();
262 257
263 return singles != null ? singles.get(0) : null; 258 return singles != null ? singles.get(0) : null;
264 } 259 }
265 260
266 public static BedHeight getBedHeightByDescription(final String description) { 261 public static BedHeight getBedHeightByDescription(final String description) {
267 262
268 final Session session = SessionHolder.HOLDER.get(); 263 final Session session = SessionHolder.HOLDER.get();
269 264
270 final Query query = session.createQuery("from BedHeight where description=:description"); 265 final Query query = session.createQuery("FROM BedHeight WHERE (trim(description)=:description)");
271 query.setParameter("description", description); 266 query.setParameter("description", description);
272 267
273 final List<BedHeight> singles = query.list(); 268 final List<BedHeight> singles = query.list();
274 269
275 return singles != null ? singles.get(0) : null; 270 return singles != null ? singles.get(0) : null;
276 } 271 }
277 } 272 }
278 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 273 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org