Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/model/BedHeight.java @ 9706:299c1c61d8ef
zu 1.1. Sohlhöhen-Überlappung
author | dnt_bjoernsen <d.tironi@bjoernsen.de> |
---|---|
date | Fri, 22 Jan 2021 12:28:58 +0100 |
parents | 3f4215ddd6b4 |
children |
comparison
equal
deleted
inserted
replaced
9705:bfdf98529a66 | 9706:299c1c61d8ef |
---|---|
25 | 25 |
26 import org.dive4elements.river.backend.SessionHolder; | 26 import org.dive4elements.river.backend.SessionHolder; |
27 import org.hibernate.Query; | 27 import org.hibernate.Query; |
28 import org.hibernate.Session; | 28 import org.hibernate.Session; |
29 | 29 |
30 import com.vividsolutions.jts.util.Assert; | |
31 | |
30 @Entity | 32 @Entity |
31 @Table(name = "bed_height") | 33 @Table(name = "bed_height") |
32 public class BedHeight implements Serializable { | 34 public class BedHeight implements Serializable { |
33 | 35 |
34 private Integer id; | 36 private Integer id; |
35 private Integer year; | 37 private Integer year; |
36 | 38 |
37 private String evaluationBy; | 39 private String evaluationBy; |
38 private String description; | 40 private String description; |
39 | 41 |
40 private River river; | 42 private River river; |
41 | 43 |
42 private BedHeightType type; | 44 private BedHeightType type; |
43 | 45 |
44 private LocationSystem locationSystem; | 46 private LocationSystem locationSystem; |
45 | 47 |
46 private ElevationModel curElevationModel; | 48 private ElevationModel curElevationModel; |
47 | 49 |
48 private ElevationModel oldElevationModel; | 50 private ElevationModel oldElevationModel; |
49 | 51 |
50 private Range range; | 52 private Range range; |
51 | 53 |
52 private String sounding_width_info; | 54 private String sounding_width_info; |
53 private String notes; | 55 private String notes; |
54 | 56 |
55 private List<BedHeightValue> values; | 57 private List<BedHeightValue> values; |
56 | 58 |
57 public BedHeight() { | 59 public static BedHeight copyPojoFrom(BedHeight b, double from, double to) { |
58 } | 60 List<BedHeightValue> values2 = b.getValues(); |
59 | 61 List<BedHeightValue> copyValueList = new ArrayList<>(); |
60 public BedHeight(final River river, final Integer year, final BedHeightType type, final LocationSystem locationSystem, | 62 |
61 final ElevationModel curElevationModel, final Range range) { | 63 BedHeight copy = new BedHeight(b.getRiver(), b.getYear(), b.getType(), b.getLocationSystem(), |
62 this(river, year, type, locationSystem, curElevationModel, null, range, null, null, null, null); | 64 b.getCurElevationModel(), b.getOldElevationModel(), new Range(from, to, b.getRange().getRiver()), |
63 } | 65 b.getEvaluationBy(), b.getDescription(), b.getSoundingWidthInfo(), b.getNotes()); |
64 | 66 |
65 public BedHeight(final River river, final Integer year, final BedHeightType type, final LocationSystem locationSystem, | 67 for (BedHeightValue val : values2) { |
66 final ElevationModel curElevationModel, final ElevationModel oldElevationModel, final Range range, final String evaluationBy, | 68 Double station = val.getStation(); |
67 final String description, final String sounding_width_info, final String notes) { | 69 if (station >= from && station <= to) |
68 this.river = river; | 70 copyValueList.add(val); |
69 this.year = year; | 71 } |
70 this.type = type; | 72 |
71 this.locationSystem = locationSystem; | 73 copy.setValues(copyValueList); |
72 this.curElevationModel = curElevationModel; | 74 return copy; |
73 this.oldElevationModel = oldElevationModel; | 75 } |
74 this.range = range; | 76 |
75 this.evaluationBy = evaluationBy; | 77 public BedHeight() { |
76 this.description = description; | 78 } |
77 this.sounding_width_info = sounding_width_info; | 79 |
78 this.notes = notes; | 80 public BedHeight(final River river, final Integer year, final BedHeightType type, |
79 } | 81 final LocationSystem locationSystem, final ElevationModel curElevationModel, final Range range) { |
80 | 82 this(river, year, type, locationSystem, curElevationModel, null, range, null, null, null, null); |
81 @Id | 83 } |
82 @SequenceGenerator(name = "SEQUENCE_BED_HEIGHT_ID_SEQ", sequenceName = "BED_HEIGHT_ID_SEQ", allocationSize = 1) | 84 |
83 @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQUENCE_BED_HEIGHT_ID_SEQ") | 85 public BedHeight(final River river, final Integer year, final BedHeightType type, |
84 @Column(name = "id") | 86 final LocationSystem locationSystem, final ElevationModel curElevationModel, |
85 public Integer getId() { | 87 final ElevationModel oldElevationModel, final Range range, final String evaluationBy, |
86 return this.id; | 88 final String description, final String sounding_width_info, final String notes) { |
87 } | 89 this.river = river; |
88 | 90 this.year = year; |
89 public void setId(final Integer id) { | 91 this.type = type; |
90 this.id = id; | 92 this.locationSystem = locationSystem; |
91 } | 93 this.curElevationModel = curElevationModel; |
92 | 94 this.oldElevationModel = oldElevationModel; |
93 @OneToOne | 95 this.range = range; |
94 @JoinColumn(name = "river_id") | 96 this.evaluationBy = evaluationBy; |
95 public River getRiver() { | 97 this.description = description; |
96 return this.river; | 98 this.sounding_width_info = sounding_width_info; |
97 } | 99 this.notes = notes; |
98 | 100 } |
99 public void setRiver(final River river) { | 101 |
100 this.river = river; | 102 @Id |
101 } | 103 @SequenceGenerator(name = "SEQUENCE_BED_HEIGHT_ID_SEQ", sequenceName = "BED_HEIGHT_ID_SEQ", allocationSize = 1) |
102 | 104 @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQUENCE_BED_HEIGHT_ID_SEQ") |
103 @Column(name = "year") | 105 @Column(name = "id") |
104 public Integer getYear() { | 106 public Integer getId() { |
105 return this.year; | 107 return this.id; |
106 } | 108 } |
107 | 109 |
108 public void setYear(final Integer year) { | 110 public void setId(final Integer id) { |
109 this.year = year; | 111 this.id = id; |
110 } | 112 } |
111 | 113 |
112 @OneToOne | 114 @OneToOne |
113 @JoinColumn(name = "type_id") | 115 @JoinColumn(name = "river_id") |
114 public BedHeightType getType() { | 116 public River getRiver() { |
115 return this.type; | 117 return this.river; |
116 } | 118 } |
117 | 119 |
118 public void setType(final BedHeightType type) { | 120 public void setRiver(final River river) { |
119 this.type = type; | 121 this.river = river; |
120 } | 122 } |
121 | 123 |
122 @OneToOne | 124 @Column(name = "year") |
123 @JoinColumn(name = "location_system_id") | 125 public Integer getYear() { |
124 public LocationSystem getLocationSystem() { | 126 return this.year; |
125 return this.locationSystem; | 127 } |
126 } | 128 |
127 | 129 public void setYear(final Integer year) { |
128 public void setLocationSystem(final LocationSystem locationSystem) { | 130 this.year = year; |
129 this.locationSystem = locationSystem; | 131 } |
130 } | 132 |
131 | 133 @OneToOne |
132 @OneToOne | 134 @JoinColumn(name = "type_id") |
133 @JoinColumn(name = "cur_elevation_model_id") | 135 public BedHeightType getType() { |
134 public ElevationModel getCurElevationModel() { | 136 return this.type; |
135 return this.curElevationModel; | 137 } |
136 } | 138 |
137 | 139 public void setType(final BedHeightType type) { |
138 public void setCurElevationModel(final ElevationModel curElevationModel) { | 140 this.type = type; |
139 this.curElevationModel = curElevationModel; | 141 } |
140 } | 142 |
141 | 143 @OneToOne |
142 @OneToOne | 144 @JoinColumn(name = "location_system_id") |
143 @JoinColumn(name = "old_elevation_model_id") | 145 public LocationSystem getLocationSystem() { |
144 public ElevationModel getOldElevationModel() { | 146 return this.locationSystem; |
145 return this.oldElevationModel; | 147 } |
146 } | 148 |
147 | 149 public void setLocationSystem(final LocationSystem locationSystem) { |
148 public void setOldElevationModel(final ElevationModel oldElevationModel) { | 150 this.locationSystem = locationSystem; |
149 this.oldElevationModel = oldElevationModel; | 151 } |
150 } | 152 |
151 | 153 @OneToOne |
152 @OneToOne | 154 @JoinColumn(name = "cur_elevation_model_id") |
153 @JoinColumn(name = "range_id") | 155 public ElevationModel getCurElevationModel() { |
154 public Range getRange() { | 156 return this.curElevationModel; |
155 return this.range; | 157 } |
156 } | 158 |
157 | 159 public void setCurElevationModel(final ElevationModel curElevationModel) { |
158 public void setRange(final Range range) { | 160 this.curElevationModel = curElevationModel; |
159 this.range = range; | 161 } |
160 } | 162 |
161 | 163 @OneToOne |
162 @Column(name = "evaluation_by") | 164 @JoinColumn(name = "old_elevation_model_id") |
163 public String getEvaluationBy() { | 165 public ElevationModel getOldElevationModel() { |
164 return this.evaluationBy; | 166 return this.oldElevationModel; |
165 } | 167 } |
166 | 168 |
167 public void setEvaluationBy(final String evaluationBy) { | 169 public void setOldElevationModel(final ElevationModel oldElevationModel) { |
168 this.evaluationBy = evaluationBy; | 170 this.oldElevationModel = oldElevationModel; |
169 } | 171 } |
170 | 172 |
171 @Column(name = "description") | 173 @OneToOne |
172 public String getDescription() { | 174 @JoinColumn(name = "range_id") |
173 return this.description; | 175 public Range getRange() { |
174 } | 176 return this.range; |
175 | 177 } |
176 public void setDescription(final String description) { | 178 |
177 this.description = description; | 179 public void setRange(final Range range) { |
178 } | 180 this.range = range; |
179 | 181 } |
180 @Column(name = "sounding_width_info") | 182 |
181 public String getSoundingWidthInfo() { | 183 @Column(name = "evaluation_by") |
182 return this.sounding_width_info; | 184 public String getEvaluationBy() { |
183 } | 185 return this.evaluationBy; |
184 | 186 } |
185 public void setSoundingWidthInfo(final String sounding_width_info) { | 187 |
186 this.sounding_width_info = sounding_width_info; | 188 public void setEvaluationBy(final String evaluationBy) { |
187 } | 189 this.evaluationBy = evaluationBy; |
188 | 190 } |
189 @Column(name = "notes") | 191 |
190 public String getNotes() { | 192 @Column(name = "description") |
191 return this.notes; | 193 public String getDescription() { |
192 } | 194 return this.description; |
193 | 195 } |
194 public void setNotes(final String notes) { | 196 |
195 this.notes = notes; | 197 public void setDescription(final String description) { |
196 } | 198 this.description = description; |
197 | 199 } |
198 @OneToMany | 200 |
199 @JoinColumn(name = "bed_height_id") | 201 @Column(name = "sounding_width_info") |
200 public List<BedHeightValue> getValues() { | 202 public String getSoundingWidthInfo() { |
201 return this.values; | 203 return this.sounding_width_info; |
202 } | 204 } |
203 | 205 |
204 public void setValues(final List<BedHeightValue> values) { | 206 public void setSoundingWidthInfo(final String sounding_width_info) { |
205 this.values = values; | 207 this.sounding_width_info = sounding_width_info; |
206 } | 208 } |
207 | 209 |
208 public static List<BedHeight> getBedHeights(final River river, final double kmLo, final double kmHi) { | 210 @Column(name = "notes") |
209 return getBedHeights(river, kmLo, kmHi, false); | 211 public String getNotes() { |
210 } | 212 return this.notes; |
211 | 213 } |
212 /** | 214 |
213 * Fetch the soundings with values in a river km range, optionally only those that also have field 01 etc. values | 215 public void setNotes(final String notes) { |
214 */ | 216 this.notes = notes; |
215 public static List<BedHeight> getBedHeights(final River river, final double startKm, final double endKm, final boolean withHeightFieldsOnly) { | 217 } |
216 | 218 |
217 final Session session = SessionHolder.HOLDER.get(); | 219 @OneToMany |
218 | 220 @JoinColumn(name = "bed_height_id") |
219 final String fieldsClause = withHeightFieldsOnly ? " AND (height01 IS NOT NULL)" : ""; | 221 public List<BedHeightValue> getValues() { |
220 final Query query = session.createQuery("FROM BedHeight" | 222 return this.values; |
221 + " WHERE (river=:river)" | 223 } |
222 + " AND (id IN (SELECT bedHeight.id FROM BedHeightValue" | 224 |
223 + " WHERE (station BETWEEN :kmfrom - 0.0001 AND :kmto + 0.0001)" | 225 public void setValues(final List<BedHeightValue> values) { |
224 + fieldsClause | 226 this.values = values; |
225 + " GROUP BY bed_height_id))"); | 227 } |
226 query.setParameter("river", river); | 228 |
227 query.setParameter("kmfrom", startKm); | 229 public static List<BedHeight> getBedHeights(final River river, final double kmLo, final double kmHi) { |
228 query.setParameter("kmto", endKm); | 230 return getBedHeights(river, kmLo, kmHi, false); |
229 | 231 } |
230 final List<BedHeight> singles = query.list(); | 232 |
231 | 233 /** |
232 return ((singles != null) && !singles.isEmpty()) ? singles : null; | 234 * Fetch the soundings with values in a river km range, optionally only those |
233 } | 235 * that also have field 01 etc. values |
234 | 236 */ |
235 public static BedHeight getBedHeightById(final int id) { | 237 public static List<BedHeight> getBedHeights(final River river, final double startKm, final double endKm, |
236 final Session session = SessionHolder.HOLDER.get(); | 238 final boolean withHeightFieldsOnly) { |
237 | 239 |
238 final Query query = session.createQuery("from BedHeight where id=:id"); | 240 final Session session = SessionHolder.HOLDER.get(); |
239 | 241 |
240 query.setParameter("id", id); | 242 final String fieldsClause = withHeightFieldsOnly ? " AND (height01 IS NOT NULL)" : ""; |
241 | 243 final Query query = session.createQuery( |
242 final List<BedHeight> singles = query.list(); | 244 "FROM BedHeight" + " WHERE (river=:river)" + " AND (id IN (SELECT bedHeight.id FROM BedHeightValue" |
243 | 245 + " WHERE (station BETWEEN :kmfrom - 0.0001 AND :kmto + 0.0001)" + fieldsClause |
244 return ((singles != null) && !singles.isEmpty()) ? singles.get(0) : null; | 246 + " GROUP BY bed_height_id))"); |
245 } | 247 query.setParameter("river", river); |
246 | 248 query.setParameter("kmfrom", startKm); |
247 public static BedHeight getBedHeightByDescription(final River river, final String description, final double startKm, final double endKm) { | 249 query.setParameter("kmto", endKm); |
248 | 250 |
249 final Session session = SessionHolder.HOLDER.get(); | 251 final List<BedHeight> singles = query.list(); |
250 | 252 |
251 final Query query = session.createQuery("FROM BedHeight" + " WHERE (TRIM(description)=:description) AND river=:river" | 253 return ((singles != null) && !singles.isEmpty()) ? singles : null; |
252 + " AND id IN (SELECT bedHeight.id FROM BedHeightValue" + " WHERE station BETWEEN :kmfrom AND :kmto" + " GROUP BY bedHeight.id)"); | 254 } |
253 query.setParameter("river", river); | 255 |
254 query.setParameter("description", description); | 256 public static BedHeight getBedHeightById(final int id) { |
255 query.setParameter("kmfrom", startKm); | 257 final Session session = SessionHolder.HOLDER.get(); |
256 query.setParameter("kmto", endKm); | 258 |
257 | 259 final Query query = session.createQuery("from BedHeight where id=:id"); |
258 final List<BedHeight> singles = query.list(); | 260 |
259 | 261 query.setParameter("id", id); |
260 return ((singles != null) && !singles.isEmpty()) ? singles.get(0) : null; | 262 |
261 } | 263 final List<BedHeight> singles = query.list(); |
262 | 264 |
263 public static List<BedHeight> getBedHeightEpochs(final River river, final double startKm, final double endKm) { | 265 return ((singles != null) && !singles.isEmpty()) ? singles.get(0) : null; |
264 | 266 } |
265 final Session session = SessionHolder.HOLDER.get(); | 267 |
266 final String description = "epoch"; | 268 public static BedHeight getBedHeightByDescription(final River river, final String description, final double startKm, |
267 final Query query = session.createQuery("FROM BedHeight" + " WHERE lower(description) LIKE :description AND " + "river=:river" | 269 final double endKm) { |
268 + " AND id IN (SELECT bedHeight.id FROM BedHeightValue" + " WHERE station BETWEEN :kmfrom AND :kmto" + " GROUP BY bedHeight.id)"); | 270 |
269 query.setParameter("river", river); | 271 final Session session = SessionHolder.HOLDER.get(); |
270 query.setParameter("description", "%" + description + "%"); | 272 |
271 query.setParameter("kmfrom", startKm); | 273 final Query query = session |
272 query.setParameter("kmto", endKm); | 274 .createQuery("FROM BedHeight" + " WHERE (TRIM(description)=:description) AND river=:river" |
273 | 275 + " AND id IN (SELECT bedHeight.id FROM BedHeightValue" |
274 final List<BedHeight> singles = query.list(); | 276 + " WHERE station BETWEEN :kmfrom AND :kmto" + " GROUP BY bedHeight.id)"); |
275 | 277 query.setParameter("river", river); |
276 return ((singles != null) && !singles.isEmpty()) ? singles : null; | 278 query.setParameter("description", description); |
277 } | 279 query.setParameter("kmfrom", startKm); |
278 | 280 query.setParameter("kmto", endKm); |
279 public static List<BedHeight> getBedHeightYear(final River river, final double startKm, final double endKm) { | 281 |
280 | 282 final List<BedHeight> singles = query.list(); |
281 final Session session = SessionHolder.HOLDER.get(); | 283 |
282 final String description = "epoch"; | 284 return ((singles != null) && !singles.isEmpty()) ? singles.get(0) : null; |
283 final Query query = session.createQuery("FROM BedHeight" + " WHERE lower(description) NOT LIKE :description AND " + "river=:river" | 285 } |
284 + " AND id IN (SELECT bedHeight.id FROM BedHeightValue" + " WHERE station BETWEEN :kmfrom AND :kmto" + " GROUP BY bedHeight.id)"); | 286 |
285 query.setParameter("river", river); | 287 public static List<BedHeight> getBedHeightEpochs(final River river, final double startKm, final double endKm) { |
286 query.setParameter("description", "%" + description + "%"); | 288 |
287 query.setParameter("kmfrom", startKm); | 289 final Session session = SessionHolder.HOLDER.get(); |
288 query.setParameter("kmto", endKm); | 290 final String description = "epoch"; |
289 | 291 final Query query = session.createQuery("FROM BedHeight" + " WHERE lower(description) LIKE :description AND " |
290 final List<BedHeight> singles = query.list(); | 292 + "river=:river" + " AND id IN (SELECT bedHeight.id FROM BedHeightValue" |
291 | 293 + " WHERE station BETWEEN :kmfrom AND :kmto" + " GROUP BY bedHeight.id)"); |
292 return ((singles != null) && !singles.isEmpty()) ? singles : null; | 294 query.setParameter("river", river); |
293 } | 295 query.setParameter("description", "%" + description + "%"); |
294 | 296 query.setParameter("kmfrom", startKm); |
295 public static Range getRangeFromBedHeights(final BedHeight bh) { | 297 query.setParameter("kmto", endKm); |
296 final List<Range> ranges = new ArrayList<>(); | 298 |
297 | 299 final List<BedHeight> singles = query.list(); |
298 final Session session = SessionHolder.HOLDER.get(); | 300 |
299 | 301 return ((singles != null) && !singles.isEmpty()) ? singles : null; |
300 final Query query = session.createQuery("FROM Range" + " WHERE id=:range_id)"); | 302 } |
301 query.setParameter("range_id", bh.getRange().getId()); | 303 |
302 | 304 public static List<BedHeight> getBedHeightYear(final River river, final double startKm, final double endKm) { |
303 final List<Range> singles = query.list(); | 305 |
304 | 306 final Session session = SessionHolder.HOLDER.get(); |
305 return ((singles != null) && !singles.isEmpty()) ? singles.get(0) : null; | 307 final String description = "epoch"; |
306 } | 308 final Query query = session |
307 | 309 .createQuery("FROM BedHeight" + " WHERE lower(description) NOT LIKE :description AND " + "river=:river" |
308 public static List<BedHeight> getBedHeightYearEpoch(final boolean isEpoch, final Integer year, final River river, final double lowerKm, | 310 + " AND id IN (SELECT bedHeight.id FROM BedHeightValue" |
309 final double upperKm) { | 311 + " WHERE station BETWEEN :kmfrom AND :kmto" + " GROUP BY bedHeight.id)"); |
310 | 312 query.setParameter("river", river); |
311 final Session session = SessionHolder.HOLDER.get(); | 313 query.setParameter("description", "%" + description + "%"); |
312 final String description = "epoch"; | 314 query.setParameter("kmfrom", startKm); |
313 | 315 query.setParameter("kmto", endKm); |
314 final StringBuilder builder = new StringBuilder(); | 316 |
315 builder.append("FROM BedHeight"); | 317 final List<BedHeight> singles = query.list(); |
316 if (isEpoch) { | 318 |
317 builder.append(" WHERE lower(description) LIKE :description "); | 319 return ((singles != null) && !singles.isEmpty()) ? singles : null; |
318 } else { | 320 } |
319 builder.append(" WHERE lower(description) NOT LIKE :description "); | 321 |
320 } | 322 public static Range getRangeFromBedHeights(final BedHeight bh) { |
321 builder.append(" AND year =:year"); | 323 final List<Range> ranges = new ArrayList<>(); |
322 | 324 |
323 builder.append( | 325 final Session session = SessionHolder.HOLDER.get(); |
324 " AND river=:river AND id IN (SELECT bedHeight.id FROM BedHeightValue WHERE station BETWEEN :kmfrom AND :kmto GROUP BY bedHeight.id )"); | 326 |
325 final Query query = session.createQuery(builder.toString()); | 327 final Query query = session.createQuery("FROM Range" + " WHERE id=:range_id)"); |
326 query.setParameter("river", river); | 328 query.setParameter("range_id", bh.getRange().getId()); |
327 query.setParameter("year", year); | 329 |
328 query.setParameter("description", "%" + description + "%"); | 330 final List<Range> singles = query.list(); |
329 query.setParameter("kmfrom", lowerKm); | 331 |
330 query.setParameter("kmto", upperKm); | 332 return ((singles != null) && !singles.isEmpty()) ? singles.get(0) : null; |
331 | 333 } |
332 final List<BedHeight> singles = query.list(); | 334 |
333 | 335 public static List<BedHeight> getBedHeightYearEpoch(final boolean isEpoch, final Integer year, final River river, |
334 return ((singles != null) && !singles.isEmpty()) ? singles : null; | 336 final double lowerKm, final double upperKm) { |
335 } | 337 |
338 final Session session = SessionHolder.HOLDER.get(); | |
339 final String description = "epoch"; | |
340 | |
341 final StringBuilder builder = new StringBuilder(); | |
342 builder.append("FROM BedHeight"); | |
343 if (isEpoch) { | |
344 builder.append(" WHERE lower(description) LIKE :description "); | |
345 } else { | |
346 builder.append(" WHERE lower(description) NOT LIKE :description "); | |
347 } | |
348 builder.append(" AND year =:year"); | |
349 | |
350 builder.append( | |
351 " AND river=:river AND id IN (SELECT bedHeight.id FROM BedHeightValue WHERE station BETWEEN :kmfrom AND :kmto GROUP BY bedHeight.id )"); | |
352 final Query query = session.createQuery(builder.toString()); | |
353 query.setParameter("river", river); | |
354 query.setParameter("year", year); | |
355 query.setParameter("description", "%" + description + "%"); | |
356 query.setParameter("kmfrom", lowerKm); | |
357 query.setParameter("kmto", upperKm); | |
358 | |
359 final List<BedHeight> singles = query.list(); | |
360 | |
361 return ((singles != null) && !singles.isEmpty()) ? singles : null; | |
362 } | |
336 } | 363 } |