Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/importer/ImportBedHeight.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 |
---|---|
10 | 10 |
11 import java.util.ArrayList; | 11 import java.util.ArrayList; |
12 import java.util.List; | 12 import java.util.List; |
13 | 13 |
14 import org.apache.log4j.Logger; | 14 import org.apache.log4j.Logger; |
15 | |
16 import org.hibernate.Session; | |
17 import org.hibernate.Query; | |
18 | |
19 import org.dive4elements.river.model.BedHeight; | 15 import org.dive4elements.river.model.BedHeight; |
20 import org.dive4elements.river.model.BedHeightType; | 16 import org.dive4elements.river.model.BedHeightType; |
21 import org.dive4elements.river.model.ElevationModel; | 17 import org.dive4elements.river.model.ElevationModel; |
22 import org.dive4elements.river.model.Range; | 18 import org.dive4elements.river.model.Range; |
23 import org.dive4elements.river.model.River; | 19 import org.dive4elements.river.model.River; |
20 import org.hibernate.Query; | |
21 import org.hibernate.Session; | |
24 | 22 |
25 | 23 |
26 public class ImportBedHeight | 24 public class ImportBedHeight |
27 { | 25 { |
28 private static Logger log = Logger.getLogger(ImportBedHeight.class); | 26 private static Logger log = Logger.getLogger(ImportBedHeight.class); |
35 protected ImportRange range; | 33 protected ImportRange range; |
36 protected ImportBedHeightType type; | 34 protected ImportBedHeightType type; |
37 protected ImportLocationSystem locationSystem; | 35 protected ImportLocationSystem locationSystem; |
38 protected ImportElevationModel curElevationModel; | 36 protected ImportElevationModel curElevationModel; |
39 protected ImportElevationModel oldElevationModel; | 37 protected ImportElevationModel oldElevationModel; |
38 protected String sounding_width_info; | |
39 protected String comment; | |
40 | 40 |
41 protected List<ImportBedHeightValue> values; | 41 protected List<ImportBedHeightValue> values; |
42 | 42 |
43 protected BedHeight peer; | 43 protected BedHeight peer; |
44 | 44 |
45 | 45 |
46 public ImportBedHeight(String description) { | 46 public ImportBedHeight(final String description) { |
47 this.description = description; | 47 this.description = description; |
48 this.values = new ArrayList<ImportBedHeightValue>(); | 48 this.values = new ArrayList<>(); |
49 } | 49 } |
50 | 50 |
51 | 51 |
52 public String getDescription() { | 52 public String getDescription() { |
53 return description; | 53 return this.description; |
54 } | 54 } |
55 | 55 |
56 public int getValueCount() { | 56 public int getValueCount() { |
57 return values.size(); | 57 return this.values.size(); |
58 } | 58 } |
59 | 59 |
60 | 60 |
61 public void setYear(int year) { | 61 public void setYear(final int year) { |
62 this.year = year; | 62 this.year = year; |
63 } | 63 } |
64 | 64 |
65 public void setTimeInterval(ImportTimeInterval timeInterval) { | 65 public void setTimeInterval(final ImportTimeInterval timeInterval) { |
66 // do nothing | 66 // do nothing |
67 } | 67 } |
68 | 68 |
69 public void setEvaluationBy(String evaluationBy) { | 69 public void setEvaluationBy(final String evaluationBy) { |
70 this.evaluationBy = evaluationBy; | 70 this.evaluationBy = evaluationBy; |
71 } | 71 } |
72 | 72 |
73 public void setDescription(String description) { | 73 public void setDescription(final String description) { |
74 this.description = description; | 74 this.description = description; |
75 } | 75 } |
76 | 76 |
77 public void setRange(ImportRange range) { | 77 public void setRange(final ImportRange range) { |
78 this.range = range; | 78 this.range = range; |
79 } | 79 } |
80 | 80 |
81 public void setType(ImportBedHeightType type) { | 81 public void setType(final ImportBedHeightType type) { |
82 this.type = type; | 82 this.type = type; |
83 } | 83 } |
84 | 84 |
85 public void setLocationSystem(ImportLocationSystem locationSystem) { | 85 public void setLocationSystem(final ImportLocationSystem locationSystem) { |
86 this.locationSystem = locationSystem; | 86 this.locationSystem = locationSystem; |
87 } | 87 } |
88 | 88 |
89 public void setCurElevationModel(ImportElevationModel curElevationModel) { | 89 public void setCurElevationModel(final ImportElevationModel curElevationModel) { |
90 this.curElevationModel = curElevationModel; | 90 this.curElevationModel = curElevationModel; |
91 } | 91 } |
92 | 92 |
93 public void setOldElevationModel(ImportElevationModel oldElevationModel) { | 93 public void setOldElevationModel(final ImportElevationModel oldElevationModel) { |
94 this.oldElevationModel = oldElevationModel; | 94 this.oldElevationModel = oldElevationModel; |
95 } | 95 } |
96 | 96 |
97 public void addValue(ImportBedHeightValue value) { | 97 public void setSoundingWidthInfo(final String sounding_width_info) { |
98 values.add((ImportBedHeightValue) value); | 98 this.sounding_width_info = sounding_width_info; |
99 } | 99 } |
100 | 100 |
101 public void storeDependencies(River river) { | 101 public void setComment(final String comment) { |
102 this.comment = comment; | |
103 } | |
104 | |
105 public void addValue(final ImportBedHeightValue value) { | |
106 this.values.add(value); | |
107 } | |
108 | |
109 public void storeDependencies(final River river) { | |
102 log.info("Store dependencies for single: '" + getDescription() + "'"); | 110 log.info("Store dependencies for single: '" + getDescription() + "'"); |
103 | 111 |
104 if (type != null) { | 112 if (this.type != null) { |
105 type.storeDependencies(); | 113 this.type.storeDependencies(); |
106 } | 114 } |
107 | 115 |
108 if (locationSystem != null) { | 116 if (this.locationSystem != null) { |
109 locationSystem.storeDependencies(); | 117 this.locationSystem.storeDependencies(); |
110 } | 118 } |
111 | 119 |
112 if (curElevationModel != null) { | 120 if (this.curElevationModel != null) { |
113 curElevationModel.storeDependencies(); | 121 this.curElevationModel.storeDependencies(); |
114 } | 122 } |
115 | 123 |
116 if (oldElevationModel != null) { | 124 if (this.oldElevationModel != null) { |
117 oldElevationModel.storeDependencies(); | 125 this.oldElevationModel.storeDependencies(); |
118 } | 126 } |
119 | 127 |
120 BedHeight peer = getPeer(river); | 128 final BedHeight peer = getPeer(river); |
121 | 129 |
122 if (peer != null) { | 130 if (peer != null) { |
123 for (ImportBedHeightValue value: values) { | 131 for (final ImportBedHeightValue value: this.values) { |
124 value.storeDependencies(peer); | 132 value.storeDependencies(peer); |
125 } | 133 } |
126 } | 134 } |
127 | 135 |
128 Session session = ImporterSession.getInstance().getDatabaseSession(); | 136 final Session session = ImporterSession.getInstance().getDatabaseSession(); |
129 session.flush(); | 137 session.flush(); |
130 } | 138 } |
131 | 139 |
132 public BedHeight getPeer(River river) { | 140 public BedHeight getPeer(final River river) { |
133 if (peer == null) { | 141 if (this.peer != null) |
134 BedHeightType theType = type != null ? type.getPeer() : null; | 142 return null; |
135 ElevationModel theCurModel = curElevationModel.getPeer(); | |
136 Range theRange = range != null | |
137 ? range.getPeer(river) | |
138 : null; | |
139 | 143 |
140 if (theType == null) { | 144 final BedHeightType theType = this.type != null ? this.type.getPeer() : null; |
141 log.warn("BHS: No bed height type given. Skip file '" + | 145 final ElevationModel theCurModel = this.curElevationModel.getPeer(); |
142 description + "'"); | 146 final Range theRange = (this.range != null) ? this.range.getPeer(river) : null; |
143 return null; | |
144 } | |
145 | 147 |
146 if (theCurModel == null) { | 148 if (theType == null) { |
147 log.warn("BHS: No elevation model given. Skip file '" + | 149 log.warn("BHS: No bed height type given. Skip file '" + this.description + "'"); |
148 description + "'"); | 150 return null; |
149 return null; | |
150 } | |
151 | |
152 if (theRange == null) { | |
153 log.warn("BHS: No km-range given: '" + | |
154 description + "'"); | |
155 } | |
156 | |
157 Session session = ImporterSession.getInstance() | |
158 .getDatabaseSession(); | |
159 | |
160 Query query = session.createQuery( | |
161 "from BedHeight where " + | |
162 "river=:river and year=:year " + | |
163 "and type=:type and locationSystem=:locationSystem and " + | |
164 "curElevationModel=:curElevationModel and range=:range"); | |
165 | |
166 query.setParameter("river", river); | |
167 query.setParameter("year", year); | |
168 query.setParameter("type", theType); | |
169 query.setParameter("locationSystem", locationSystem.getPeer()); | |
170 query.setParameter("curElevationModel", theCurModel); | |
171 query.setParameter("range", range.getPeer(river)); | |
172 | |
173 List<BedHeight> bedHeights = query.list(); | |
174 if (bedHeights.isEmpty()) { | |
175 log.info("Create new BedHeight DB instance."); | |
176 | |
177 peer = new BedHeight( | |
178 river, | |
179 year, | |
180 theType, | |
181 locationSystem.getPeer(), | |
182 theCurModel, | |
183 oldElevationModel != null | |
184 ? oldElevationModel.getPeer() | |
185 : null, | |
186 range.getPeer(river), | |
187 evaluationBy, | |
188 description | |
189 ); | |
190 | |
191 session.save(peer); | |
192 } | |
193 else { | |
194 peer = bedHeights.get(0); | |
195 } | |
196 } | 151 } |
197 | 152 |
198 return peer; | 153 if (theCurModel == null) { |
154 log.warn("BHS: No elevation model given. Skip file '" + this.description + "'"); | |
155 return null; | |
156 } | |
157 | |
158 if (theRange == null) { | |
159 log.warn("BHS: No km-range given: '" + this.description + "'"); | |
160 } | |
161 | |
162 final Session session = ImporterSession.getInstance().getDatabaseSession(); | |
163 | |
164 final Query query = session.createQuery("FROM BedHeight WHERE (river=:river) AND (year=:year)" | |
165 + " AND (type=:type) AND (locationSystem=:locationSystem)" | |
166 + " AND (curElevationModel=:curElevationModel) AND (range=:range)"); | |
167 query.setParameter("river", river); | |
168 query.setParameter("year", this.year); | |
169 query.setParameter("type", theType); | |
170 query.setParameter("locationSystem", this.locationSystem.getPeer()); | |
171 query.setParameter("curElevationModel", theCurModel); | |
172 query.setParameter("range", this.range.getPeer(river)); | |
173 | |
174 final List<BedHeight> bedHeights = query.list(); | |
175 if (bedHeights.isEmpty()) { | |
176 log.info("Create new BedHeight DB instance."); | |
177 this.peer = new BedHeight(river, this.year, theType, this.locationSystem.getPeer(), theCurModel, | |
178 (this.oldElevationModel != null) ? this.oldElevationModel.getPeer() : null, this.range.getPeer(river), | |
179 this.evaluationBy, this.description, this.sounding_width_info, this.comment); | |
180 session.save(this.peer); | |
181 } | |
182 else { | |
183 this.peer = bedHeights.get(0); | |
184 } | |
185 | |
186 return this.peer; | |
199 } | 187 } |
200 } | 188 } |
201 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : | 189 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |