comparison backend/src/main/java/org/dive4elements/river/importer/ImportBedHeightValue.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 5e38e2924c07
children 392bbcd8a88b
comparison
equal deleted inserted replaced
8974:a275ddf7a3a1 8975:a0a0a7f912ab
9 package org.dive4elements.river.importer; 9 package org.dive4elements.river.importer;
10 10
11 import java.util.List; 11 import java.util.List;
12 12
13 import org.apache.log4j.Logger; 13 import org.apache.log4j.Logger;
14
15 import org.hibernate.Session;
16 import org.hibernate.Query;
17
18 import org.dive4elements.river.model.BedHeight; 14 import org.dive4elements.river.model.BedHeight;
19 import org.dive4elements.river.model.BedHeightValue; 15 import org.dive4elements.river.model.BedHeightValue;
16 import org.hibernate.Query;
17 import org.hibernate.Session;
20 18
21 19
22 public class ImportBedHeightValue { 20 public class ImportBedHeightValue {
23 21
24 private static final Logger log = 22 private static final Logger log = Logger.getLogger(ImportBedHeightValue.class);
25 Logger.getLogger(ImportBedHeightValue.class);
26 23
27 24
28 protected ImportBedHeight bedHeight; 25 protected ImportBedHeight bedHeight;
29 26
30 protected Double station; 27 protected Double station;
31 protected Double height; 28 protected Double height;
32 protected Double uncertainty; 29 protected Double uncertainty;
33 protected Double dataGap; 30 protected Double dataGap;
34 protected Double soundingWidth; 31 protected Double soundingWidth;
32 protected Double minHeight;
33 protected Double maxHeight;
35 34
36 protected BedHeightValue peer; 35 protected BedHeightValue peer;
37 36
38 37
39 public ImportBedHeightValue( 38 public ImportBedHeightValue(final ImportBedHeight bedHeight, final Double station, final Double height, final Double uncertainty, final Double dataGap,
40 ImportBedHeight bedHeight, 39 final Double soundingWidth, final Double minHeight, final Double maxHeight) {
41 Double station,
42 Double height,
43 Double uncertainty,
44 Double dataGap,
45 Double soundingWidth
46 ) {
47 this.bedHeight = bedHeight; 40 this.bedHeight = bedHeight;
48 this.station = station; 41 this.station = station;
49 this.height = height; 42 this.height = height;
50 this.uncertainty = uncertainty; 43 this.uncertainty = uncertainty;
51 this.dataGap = dataGap; 44 this.dataGap = dataGap;
52 this.soundingWidth = soundingWidth; 45 this.soundingWidth = soundingWidth;
46 this.minHeight = minHeight;
47 this.maxHeight = maxHeight;
53 } 48 }
54 49
55 50
56 public void storeDependencies(BedHeight bedHeight) { 51 public void storeDependencies(final BedHeight bedHeight) {
57 getPeer(bedHeight); 52 getPeer(bedHeight);
58 } 53 }
59 54
60 55
61 /** 56 /**
62 * Add this value to database or return database bound Value, assuring 57 * Add this value to database or return database bound Value, assuring
63 * that the BedHeight exists in db already. 58 * that the BedHeight exists in db already.
64 */ 59 */
65 public BedHeightValue getPeer(BedHeight bedHeight) { 60 public BedHeightValue getPeer(final BedHeight bedHeight) {
66 if (peer == null) { 61 if (this.peer != null)
67 Session session = ImporterSession.getInstance() 62 return this.peer;
68 .getDatabaseSession();
69 63
70 Query query = session.createQuery( 64 final Session session = ImporterSession.getInstance().getDatabaseSession();
71 "from BedHeightValue where " + 65 final Query query = session.createQuery("FROM BedHeightValue WHERE (bedHeight=:bedHeight)"
72 " bedHeight=:bedHeight and " + 66 + " AND (station BETWEEN (:station-0.0001) AND (:station+0.0001))");
73 " station=:station"); 67 query.setParameter("bedHeight", bedHeight);
74 68 query.setParameter("station", this.station);
75 query.setParameter("bedHeight", bedHeight); 69 final List<BedHeightValue> values = query.list();
76 query.setParameter("station", station); 70 if (values.isEmpty()) {
77 71 this.peer = new BedHeightValue(bedHeight, this.station, this.height, this.uncertainty, this.dataGap, this.soundingWidth,
78 List<BedHeightValue> values = query.list(); 72 this.minHeight, this.maxHeight);
79 if (values.isEmpty()) { 73 session.save(this.peer);
80 peer = new BedHeightValue( 74 } else {
81 bedHeight, 75 this.peer = values.get(0);
82 station,
83 height,
84 uncertainty,
85 dataGap,
86 soundingWidth
87 );
88 session.save(peer);
89 }
90 else {
91 peer = values.get(0);
92 }
93 } 76 }
94 77 return this.peer;
95 return peer;
96 } 78 }
97 } 79 }
98 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 80 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org