Mercurial > lada > lada-server
comparison src/main/java/de/intevation/lada/data/importer/LAFWriter.java @ 366:567ce7697fc7 0.5
Code documentation.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Tue, 10 Sep 2013 15:55:54 +0200 |
parents | d39d3886b97d |
children | bc6d0785986f |
comparison
equal
deleted
inserted
replaced
365:fab80595ed55 | 366:567ce7697fc7 |
---|---|
22 import de.intevation.lada.model.LProbe; | 22 import de.intevation.lada.model.LProbe; |
23 import de.intevation.lada.model.Ort; | 23 import de.intevation.lada.model.Ort; |
24 import de.intevation.lada.validation.ValidationException; | 24 import de.intevation.lada.validation.ValidationException; |
25 import de.intevation.lada.validation.Validator; | 25 import de.intevation.lada.validation.Validator; |
26 | 26 |
27 /** | |
28 * Writer to persist new entities in the database. | |
29 * | |
30 * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a> | |
31 */ | |
27 @Named("lafwriter") | 32 @Named("lafwriter") |
28 public class LAFWriter | 33 public class LAFWriter |
29 implements Writer | 34 implements Writer |
30 { | 35 { |
31 @Inject | 36 @Inject |
67 private Repository messwertRepository; | 72 private Repository messwertRepository; |
68 | 73 |
69 private List<ReportData> errors; | 74 private List<ReportData> errors; |
70 private List<ReportData> warnings; | 75 private List<ReportData> warnings; |
71 | 76 |
77 /** | |
78 * Default constructor. | |
79 */ | |
72 public LAFWriter() { | 80 public LAFWriter() { |
73 errors = new ArrayList<ReportData>(); | 81 errors = new ArrayList<ReportData>(); |
74 warnings = new ArrayList<ReportData>(); | 82 warnings = new ArrayList<ReportData>(); |
75 } | 83 } |
76 | 84 |
85 /** | |
86 * Write a new {@link LProbe} object to the database using | |
87 * authorization and validation. | |
88 * | |
89 * @param auth The authentication information. | |
90 * @param probe The new {@link LProbe} object. | |
91 * @return success | |
92 */ | |
77 @Override | 93 @Override |
78 public boolean writeProbe(AuthenticationResponse auth, LProbe probe) { | 94 public boolean writeProbe(AuthenticationResponse auth, LProbe probe) { |
79 if (!authorized(probe, auth)) { | 95 if (!authorized(probe, auth)) { |
80 errors.add(new ReportData("auth", "not authorized", 699)); | 96 errors.add(new ReportData("auth", "not authorized", 699)); |
81 return false; | 97 return false; |
111 } | 127 } |
112 persist(probe); | 128 persist(probe); |
113 return true; | 129 return true; |
114 } | 130 } |
115 | 131 |
132 /** | |
133 * Write new {@link LMessung} objects to the database using | |
134 * authorization and validation. | |
135 * | |
136 * @param auth The authentication information. | |
137 * @param messungen The new {@link LMessung} objects. | |
138 * @return success | |
139 */ | |
116 @Override | 140 @Override |
117 public boolean writeMessungen( | 141 public boolean writeMessungen( |
118 AuthenticationResponse auth, | 142 AuthenticationResponse auth, |
119 List<LMessung> messungen | 143 List<LMessung> messungen |
120 ) { | 144 ) { |
148 } | 172 } |
149 | 173 |
150 return true; | 174 return true; |
151 } | 175 } |
152 | 176 |
177 /** | |
178 * Write new {@link Ort} objects to the database. | |
179 * | |
180 * @param auth The authentication information. | |
181 * @param orte List of {@link Ort} objects. | |
182 * @return success | |
183 */ | |
153 @Override | 184 @Override |
154 public boolean writeOrte(AuthenticationResponse auth, List<Ort> orte) { | 185 public boolean writeOrte(AuthenticationResponse auth, List<Ort> orte) { |
155 for (Ort ort :orte) { | 186 for (Ort ort :orte) { |
156 ortRepository.create(ort); | 187 ortRepository.create(ort); |
157 } | 188 } |
158 return true; | 189 return true; |
159 } | 190 } |
160 | 191 |
192 /** | |
193 * Write new {@link LOrt} objects to the database using validation. | |
194 * | |
195 * @param auth The authentication information. | |
196 * @param orte List of {@link LOrt} objects. | |
197 * @return success | |
198 */ | |
161 @Override | 199 @Override |
162 public boolean writeLOrte(AuthenticationResponse auth, List<LOrt> orte) { | 200 public boolean writeLOrte(AuthenticationResponse auth, List<LOrt> orte) { |
163 for(LOrt ort: orte) { | 201 for(LOrt ort: orte) { |
164 try { | 202 try { |
165 Map<String, Integer> warn = | 203 Map<String, Integer> warn = |
189 } | 227 } |
190 } | 228 } |
191 return true; | 229 return true; |
192 } | 230 } |
193 | 231 |
232 /** | |
233 * Write new {@link LKommentarP} objects to the database. | |
234 * | |
235 * @param auth The authentication information. | |
236 * @param kommentare List of {@link LKommentarP} objects. | |
237 * @return success | |
238 */ | |
194 @Override | 239 @Override |
195 public boolean writeProbenKommentare( | 240 public boolean writeProbenKommentare( |
196 AuthenticationResponse auth, | 241 AuthenticationResponse auth, |
197 List<LKommentarP> kommentare | 242 List<LKommentarP> kommentare |
198 ) { | 243 ) { |
200 pKommentarRepository.create(kommentar); | 245 pKommentarRepository.create(kommentar); |
201 } | 246 } |
202 return true; | 247 return true; |
203 } | 248 } |
204 | 249 |
250 /** | |
251 * Write new {@link LKommentarM} objects to the database. | |
252 * | |
253 * @param auth The authentication information. | |
254 * @param kommentare List of {@link LKommentarM} objects. | |
255 * @return success | |
256 */ | |
205 @Override | 257 @Override |
206 public boolean writeMessungKommentare( | 258 public boolean writeMessungKommentare( |
207 AuthenticationResponse auth, | 259 AuthenticationResponse auth, |
208 List<LKommentarM> kommentare | 260 List<LKommentarM> kommentare |
209 ) { | 261 ) { |
216 mKommentarRepository.create(kommentar); | 268 mKommentarRepository.create(kommentar); |
217 } | 269 } |
218 return true; | 270 return true; |
219 } | 271 } |
220 | 272 |
273 /** | |
274 * Write new {@link LMesswert} objects to the database using validation. | |
275 * | |
276 * @param auth The authentication information. | |
277 * @param werte List of {@link LMesswert} objects. | |
278 * @return success | |
279 */ | |
221 @Override | 280 @Override |
222 public boolean writeMesswerte( | 281 public boolean writeMesswerte( |
223 AuthenticationResponse auth, | 282 AuthenticationResponse auth, |
224 List<LMesswert> werte | 283 List<LMesswert> werte |
225 ) { | 284 ) { |
252 } | 311 } |
253 } | 312 } |
254 return false; | 313 return false; |
255 } | 314 } |
256 | 315 |
316 /** | |
317 * Persist a {@link LProbe} object. | |
318 * | |
319 * @param probe The {@link LProbe} object. | |
320 */ | |
257 @TransactionAttribute(TransactionAttributeType.REQUIRED) | 321 @TransactionAttribute(TransactionAttributeType.REQUIRED) |
258 private void persist(LProbe probe) { | 322 private void persist(LProbe probe) { |
259 String queryColumns = "insert into l_probe (probe_id, ba_id, test," + | 323 String queryColumns = "insert into l_probe (probe_id, ba_id, test," + |
260 " datenbasis_id, netzbetreiber_id, mst_id, probenart_id, umw_id"; | 324 " datenbasis_id, netzbetreiber_id, mst_id, probenart_id, umw_id"; |
261 String queryParameter = " values (:probe_id, :ba_id, :test," + | 325 String queryParameter = " values (:probe_id, :ba_id, :test," + |
371 insert.setParameter("solldatum_ende", probe.getSolldatumEnde()); | 435 insert.setParameter("solldatum_ende", probe.getSolldatumEnde()); |
372 } | 436 } |
373 insert.executeUpdate(); | 437 insert.executeUpdate(); |
374 } | 438 } |
375 | 439 |
440 /** | |
441 * Check if the user given in the authentication information is authorized | |
442 * to access the {@link LProbe} object. | |
443 * | |
444 * @param probe The {@link LProbe} object. | |
445 * @param auth The authentication information. | |
446 * @return access | |
447 */ | |
376 private boolean authorized(LProbe probe, AuthenticationResponse auth) { | 448 private boolean authorized(LProbe probe, AuthenticationResponse auth) { |
377 if (auth.getNetzbetreiber().contains(probe.getNetzbetreiberId()) && | 449 if (auth.getNetzbetreiber().contains(probe.getNetzbetreiberId()) && |
378 auth.getMst().contains(probe.getMstId())) { | 450 auth.getMst().contains(probe.getMstId())) { |
379 return true; | 451 return true; |
380 } | 452 } |
393 */ | 465 */ |
394 public List<ReportData> getWarnings() { | 466 public List<ReportData> getWarnings() { |
395 return warnings; | 467 return warnings; |
396 } | 468 } |
397 | 469 |
470 /** | |
471 * Reset the errors and warnings. | |
472 */ | |
398 public void reset() { | 473 public void reset() { |
399 this.warnings = new ArrayList<ReportData>(); | 474 this.warnings = new ArrayList<ReportData>(); |
400 this.errors = new ArrayList<ReportData>(); | 475 this.errors = new ArrayList<ReportData>(); |
401 } | 476 } |
402 } | 477 } |