Mercurial > lada > lada-server
comparison src/main/java/de/intevation/lada/importer/laf/LafProducer.java @ 1028:1c41c7b8f7c2 schema-update
Updated server application to new database model. THIS IS STILL WIP!!!
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Fri, 08 Jul 2016 15:32:36 +0200 |
parents | 092e673cbb8d |
children |
comparison
equal
deleted
inserted
replaced
1027:9971471d562c | 1028:1c41c7b8f7c2 |
---|---|
13 import java.util.Map; | 13 import java.util.Map; |
14 | 14 |
15 import javax.inject.Inject; | 15 import javax.inject.Inject; |
16 | 16 |
17 import de.intevation.lada.importer.ReportItem; | 17 import de.intevation.lada.importer.ReportItem; |
18 import de.intevation.lada.model.land.LKommentarM; | 18 import de.intevation.lada.model.land.KommentarM; |
19 import de.intevation.lada.model.land.LKommentarP; | 19 import de.intevation.lada.model.land.KommentarP; |
20 import de.intevation.lada.model.land.LMessung; | 20 import de.intevation.lada.model.land.Messung; |
21 import de.intevation.lada.model.land.LMesswert; | 21 import de.intevation.lada.model.land.Messwert; |
22 import de.intevation.lada.model.land.LOrtszuordnung; | 22 import de.intevation.lada.model.land.Ortszuordnung; |
23 import de.intevation.lada.model.land.LProbe; | 23 import de.intevation.lada.model.land.Probe; |
24 import de.intevation.lada.model.land.LZusatzWert; | 24 import de.intevation.lada.model.land.ZusatzWert; |
25 import de.intevation.lada.model.land.MessungTranslation; | 25 import de.intevation.lada.model.stammdaten.Ort; |
26 import de.intevation.lada.model.land.ProbeTranslation; | |
27 import de.intevation.lada.model.stamm.Ort; | |
28 | 26 |
29 /** | 27 /** |
30 * The LAFProducer creates entity objects form key-value pairs using the | 28 * The LAFProducer creates entity objects form key-value pairs using the |
31 * AttributeMapper. | 29 * AttributeMapper. |
32 * | 30 * |
35 public class LafProducer | 33 public class LafProducer |
36 { | 34 { |
37 /** | 35 /** |
38 * The probe object created by this producer. | 36 * The probe object created by this producer. |
39 */ | 37 */ |
40 private LProbe probe; | 38 private Probe probe; |
41 | |
42 /** | |
43 * The probe translation object created by this producer. | |
44 */ | |
45 private ProbeTranslation probeTranslation; | |
46 | 39 |
47 /** | 40 /** |
48 * The messung object created by this producer. | 41 * The messung object created by this producer. |
49 */ | 42 */ |
50 private LMessung messung; | 43 private Messung messung; |
51 | |
52 /** | |
53 * The messung translation object created by this producer. | |
54 */ | |
55 private MessungTranslation messungTranslation; | |
56 | 44 |
57 /** | 45 /** |
58 * Creator used to build ort objects. | 46 * Creator used to build ort objects. |
59 */ | 47 */ |
60 @Inject | 48 @Inject |
61 private OrtCreator ort; | 49 private OrtCreator ort; |
62 | 50 |
63 /** | 51 /** |
64 * Probekommentare created by this producer. | 52 * Probekommentare created by this producer. |
65 */ | 53 */ |
66 private List<LKommentarP> pKommentare; | 54 private List<KommentarP> pKommentare; |
67 | 55 |
68 /** | 56 /** |
69 * Messungskommentare created by this producer. | 57 * Messungskommentare created by this producer. |
70 */ | 58 */ |
71 private Map<LMessung, List<LKommentarM>> mKommentare; | 59 private Map<Messung, List<KommentarM>> mKommentare; |
72 | 60 |
73 /** | 61 /** |
74 * Messungen created by this producer. | 62 * Messungen created by this producer. |
75 */ | 63 */ |
76 private Map<LMessung, MessungTranslation> messungen; | 64 private List<Messung> messungen; |
77 | 65 |
78 /** | 66 /** |
79 * Orte created by this producer. | 67 * Orte created by this producer. |
80 */ | 68 */ |
81 private List<LOrtszuordnung> lorte; | 69 private List<Ortszuordnung> ortszuordnungen; |
82 | 70 |
83 /** | 71 /** |
84 * SOrte created by this producer. | 72 * SOrte created by this producer. |
85 */ | 73 */ |
86 private List<Ort> orte; | 74 private List<Ort> orte; |
87 | 75 |
88 /** | 76 /** |
89 * Messwerte created by this producer. | 77 * Messwerte created by this producer. |
90 */ | 78 */ |
91 private Map<LMessung, List<LMesswert>> messwerte; | 79 private Map<Messung, List<Messwert>> messwerte; |
92 | 80 |
93 /** | 81 /** |
94 * Zusatzwerte created by this producer. | 82 * Zusatzwerte created by this producer. |
95 */ | 83 */ |
96 private List<LZusatzWert> zusatzwerte; | 84 private List<ZusatzWert> zusatzwerte; |
97 | 85 |
98 /** | 86 /** |
99 * Format mapping for probe objects. | 87 * Format mapping for probe objects. |
100 */ | 88 */ |
101 private List<EntryFormat> probenFormat; | 89 private List<EntryFormat> probenFormat; |
131 * using the systemproperty "de.intevation.lada.importconfig". | 119 * using the systemproperty "de.intevation.lada.importconfig". |
132 */ | 120 */ |
133 public LafProducer() { | 121 public LafProducer() { |
134 this.warnings = new HashMap<String, List<ReportItem>>(); | 122 this.warnings = new HashMap<String, List<ReportItem>>(); |
135 this.errors = new HashMap<String, List<ReportItem>>(); | 123 this.errors = new HashMap<String, List<ReportItem>>(); |
136 this.probe = new LProbe(); | 124 this.probe = new Probe(); |
137 this.probeTranslation = new ProbeTranslation(); | 125 this.pKommentare = new ArrayList<KommentarP>(); |
138 this.pKommentare = new ArrayList<LKommentarP>(); | 126 this.mKommentare = new HashMap<Messung, List<KommentarM>>(); |
139 this.mKommentare = new HashMap<LMessung, List<LKommentarM>>(); | 127 this.messungen = new ArrayList<Messung>(); |
140 this.messungen = new HashMap<LMessung, MessungTranslation>(); | 128 this.ortszuordnungen = new ArrayList<Ortszuordnung>(); |
141 this.lorte = new ArrayList<LOrtszuordnung>(); | 129 this.messwerte = new HashMap<Messung, List<Messwert>>(); |
142 this.messwerte = new HashMap<LMessung, List<LMesswert>>(); | |
143 String fileName = "/import.json"; | 130 String fileName = "/import.json"; |
144 LafFormat format = new LafFormat(); | 131 LafFormat format = new LafFormat(); |
145 format.readConfigFile(fileName); | 132 format.readConfigFile(fileName); |
146 probenFormat = format.getFormat("probe"); | 133 probenFormat = format.getFormat("probe"); |
147 messungFormat = format.getFormat("messung"); | 134 messungFormat = format.getFormat("messung"); |
159 */ | 146 */ |
160 public void addData(String key, Object values) | 147 public void addData(String key, Object values) |
161 throws LafParserException { | 148 throws LafParserException { |
162 String lKey = key.toLowerCase(); | 149 String lKey = key.toLowerCase(); |
163 if(lKey.equals("probenkommentar")) { | 150 if(lKey.equals("probenkommentar")) { |
164 LKommentarP kommentar = new LKommentarP(); | 151 KommentarP kommentar = new KommentarP(); |
165 kommentar.setProbeId(this.probe.getId()); | 152 kommentar.setProbeId(this.probe.getId()); |
166 this.pKommentare.add( | 153 this.pKommentare.add( |
167 mapper.addAttribute(lKey, values, kommentar)); | 154 mapper.addAttribute(lKey, values, kommentar)); |
168 } | 155 } |
169 else if (lKey.equals("kommentar")) { | 156 else if (lKey.equals("kommentar")) { |
170 LKommentarM kommentar = new LKommentarM(); | 157 KommentarM kommentar = new KommentarM(); |
171 kommentar.setMessungsId(this.messung.getId()); | 158 kommentar.setMessungsId(this.messung.getId()); |
172 if (this.mKommentare.get(this.messung) == null) { | 159 if (this.mKommentare.get(this.messung) == null) { |
173 this.mKommentare.put(this.messung, new ArrayList<LKommentarM>()); | 160 this.mKommentare.put(this.messung, new ArrayList<KommentarM>()); |
174 } | 161 } |
175 this.mKommentare.get(this.messung).add( | 162 this.mKommentare.get(this.messung).add( |
176 mapper.addAttribute(lKey, values, kommentar)); | 163 mapper.addAttribute(lKey, values, kommentar)); |
177 } | 164 } |
178 else if (lKey.equals("probenzusatzbeschreibung")) { | 165 else if (lKey.equals("probenzusatzbeschreibung")) { |
179 LZusatzWert wert = new LZusatzWert(); | 166 ZusatzWert wert = new ZusatzWert(); |
180 LZusatzWert zusatzWert = mapper.addAttribute(lKey, values, wert); | 167 ZusatzWert zusatzWert = mapper.addAttribute(lKey, values, wert); |
181 if (zusatzWert != null) { | 168 if (zusatzWert != null) { |
182 zusatzWert.setProbeId(probe.getId()); | 169 zusatzWert.setProbeId(probe.getId()); |
183 this.zusatzwerte.add(zusatzWert); | 170 this.zusatzwerte.add(zusatzWert); |
184 } | 171 } |
185 else { | 172 else { |
193 err.addAll(mapper.getErrors()); | 180 err.addAll(mapper.getErrors()); |
194 } | 181 } |
195 } | 182 } |
196 } | 183 } |
197 else if (lKey.equals("pzb_s")) { | 184 else if (lKey.equals("pzb_s")) { |
198 LZusatzWert wert = new LZusatzWert(); | 185 ZusatzWert wert = new ZusatzWert(); |
199 LZusatzWert zusatzWert = mapper.addAttributeS(lKey, values, wert); | 186 ZusatzWert zusatzWert = mapper.addAttributeS(lKey, values, wert); |
200 if (zusatzWert != null) { | 187 if (zusatzWert != null) { |
201 zusatzWert.setProbeId(probe.getId()); | 188 zusatzWert.setProbeId(probe.getId()); |
202 this.zusatzwerte.add(zusatzWert); | 189 this.zusatzwerte.add(zusatzWert); |
203 } | 190 } |
204 else { | 191 else { |
212 err.addAll(mapper.getErrors()); | 199 err.addAll(mapper.getErrors()); |
213 } | 200 } |
214 } | 201 } |
215 } | 202 } |
216 else if (lKey.equals("messwert")) { | 203 else if (lKey.equals("messwert")) { |
217 LMesswert m = new LMesswert(); | 204 Messwert m = new Messwert(); |
218 m.setMessungsId(this.messung.getId()); | 205 m.setMessungsId(this.messung.getId()); |
219 LMesswert wert = mapper.addAttribute(lKey, values, m); | 206 Messwert wert = mapper.addAttribute(lKey, values, m); |
220 if (wert != null) { | 207 if (wert != null) { |
221 if (this.messwerte.get(this.messung) == null) { | 208 if (this.messwerte.get(this.messung) == null) { |
222 this.messwerte.put(this.messung, new ArrayList<LMesswert>()); | 209 this.messwerte.put(this.messung, new ArrayList<Messwert>()); |
223 } | 210 } |
224 this.messwerte.get(this.messung).add( | 211 this.messwerte.get(this.messung).add( |
225 mapper.addAttribute(lKey, values, wert)); | 212 mapper.addAttribute(lKey, values, wert)); |
226 } | 213 } |
227 else { | 214 else { |
236 } | 223 } |
237 } | 224 } |
238 } | 225 } |
239 else if (isValidMessung(lKey, values.toString())) { | 226 else if (isValidMessung(lKey, values.toString())) { |
240 this.messung = mapper.addAttribute(lKey, values, this.messung); | 227 this.messung = mapper.addAttribute(lKey, values, this.messung); |
241 this.messungTranslation = | |
242 mapper.addAttribute(lKey, values, this.messungTranslation); | |
243 } | 228 } |
244 else if (isValidProbe(lKey, values.toString())) { | 229 else if (isValidProbe(lKey, values.toString())) { |
245 this.probe = mapper.addAttribute(lKey, values, this.probe); | 230 this.probe = mapper.addAttribute(lKey, values, this.probe); |
246 this.probeTranslation = mapper.addAttribute(lKey, values, this.probeTranslation); | 231 if (this.probe == null) { |
247 if (this.probe == null || this.probeTranslation == null) { | |
248 this.errors.put(values.toString(), mapper.getErrors()); | 232 this.errors.put(values.toString(), mapper.getErrors()); |
249 throw new LafParserException(values.toString() + " exists"); | 233 throw new LafParserException(values.toString() + " exists"); |
250 } | 234 } |
251 } | 235 } |
252 else if (isValidOrt(lKey, values.toString())) { | 236 else if (isValidOrt(lKey, values.toString())) { |
312 } | 296 } |
313 | 297 |
314 /** | 298 /** |
315 * @return the {@link LProbe} entity. | 299 * @return the {@link LProbe} entity. |
316 */ | 300 */ |
317 public LProbe getProbe() { | 301 public Probe getProbe() { |
318 return this.probe; | 302 return this.probe; |
319 } | 303 } |
320 | 304 |
321 public ProbeTranslation getProbeTranslation() { | |
322 return this.probeTranslation; | |
323 } | |
324 | |
325 /** | 305 /** |
326 * @return List of {@link LMessung} entities. | 306 * @return List of {@link LMessung} entities. |
327 */ | 307 */ |
328 public Map<LMessung, MessungTranslation> getMessungen() { | 308 public List<Messung> getMessungen() { |
329 return this.messungen; | 309 return this.messungen; |
330 } | 310 } |
331 | 311 |
332 /** | 312 /** |
333 * @return List of {@link Ort} entities. | 313 * @return List of {@link Ort} entities. |
337 } | 317 } |
338 | 318 |
339 /** | 319 /** |
340 * @return List of {@link LOrt} entities. | 320 * @return List of {@link LOrt} entities. |
341 */ | 321 */ |
342 public List<LOrtszuordnung> getLOrte() { | 322 public List<Ortszuordnung> getOrtszuordnungen() { |
343 return this.lorte; | 323 return this.ortszuordnungen; |
344 } | 324 } |
345 | 325 |
346 /** | 326 /** |
347 * @return List of {@link LKommentarP} entities. | 327 * @return List of {@link LKommentarP} entities. |
348 */ | 328 */ |
349 public List<LKommentarP> getProbenKommentare() { | 329 public List<KommentarP> getProbenKommentare() { |
350 return this.pKommentare; | 330 return this.pKommentare; |
351 } | 331 } |
352 | 332 |
353 /** | 333 /** |
354 * @return List of {@link LKommentarM} entities. | 334 * @return List of {@link LKommentarM} entities. |
355 */ | 335 */ |
356 public Map<LMessung, List<LKommentarM>> getMessungsKommentare() { | 336 public Map<Messung, List<KommentarM>> getMessungsKommentare() { |
357 return this.mKommentare; | 337 return this.mKommentare; |
358 } | 338 } |
359 | 339 |
360 /** | 340 /** |
361 * @return List of {@link LMesswert} entities. | 341 * @return List of {@link LMesswert} entities. |
362 */ | 342 */ |
363 public Map<LMessung, List<LMesswert>> getMesswerte() { | 343 public Map<Messung, List<Messwert>> getMesswerte() { |
364 return this.messwerte; | 344 return this.messwerte; |
365 } | 345 } |
366 | 346 |
367 /** | 347 /** |
368 * @return List of {@link LZusatzWert} entities. | 348 * @return List of {@link LZusatzWert} entities. |
369 */ | 349 */ |
370 public List<LZusatzWert> getZusatzwerte() { | 350 public List<ZusatzWert> getZusatzwerte() { |
371 return this.zusatzwerte; | 351 return this.zusatzwerte; |
372 } | 352 } |
373 | 353 |
374 /** | 354 /** |
375 * Reset errors and warnings. | 355 * Reset errors and warnings. |
376 */ | 356 */ |
377 public void reset() { | 357 public void reset() { |
378 this.errors = new HashMap<String, List<ReportItem>>(); | 358 this.errors = new HashMap<String, List<ReportItem>>(); |
379 this.warnings = new HashMap<String, List<ReportItem>>(); | 359 this.warnings = new HashMap<String, List<ReportItem>>(); |
380 this.probe = new LProbe(); | 360 this.probe = new Probe(); |
381 this.messungen = new HashMap<LMessung, MessungTranslation>(); | 361 this.messungen = new ArrayList<Messung>(); |
382 this.messung = null; | 362 this.messung = null; |
383 this.lorte = new ArrayList<LOrtszuordnung>(); | 363 this.ortszuordnungen = new ArrayList<Ortszuordnung>(); |
384 this.orte = new ArrayList<Ort>(); | 364 this.orte = new ArrayList<Ort>(); |
385 this.ort.reset(); | 365 this.ort.reset(); |
386 this.messwerte = new HashMap<LMessung, List<LMesswert>>(); | 366 this.messwerte = new HashMap<Messung, List<Messwert>>(); |
387 this.mKommentare = new HashMap<LMessung, List<LKommentarM>>(); | 367 this.mKommentare = new HashMap<Messung, List<KommentarM>>(); |
388 this.pKommentare = new ArrayList<LKommentarP>(); | 368 this.pKommentare = new ArrayList<KommentarP>(); |
389 mapper.reset(); | 369 mapper.reset(); |
390 } | 370 } |
391 | 371 |
392 /** | 372 /** |
393 * Add the current {@link LMessung} entity to the List and create a new one. | 373 * Add the current {@link LMessung} entity to the List and create a new one. |
394 */ | 374 */ |
395 public void newMessung() { | 375 public void newMessung() { |
396 if (this.messung != null && this.messungTranslation != null) { | 376 if (this.messung != null) { |
397 if (this.messung.getFertig() == null) { | 377 if (this.messung.getFertig() == null) { |
398 this.messung.setFertig(false); | 378 this.messung.setFertig(false); |
399 } | 379 } |
400 if (this.messung.getGeplant() == null) { | 380 if (this.messung.getGeplant() == null) { |
401 this.messung.setGeplant(false); | 381 this.messung.setGeplant(false); |
402 } | 382 } |
403 this.messungen.put(this.messung, this.messungTranslation); | 383 this.messungen.add(this.messung); |
404 } | 384 } |
405 this.messung = new LMessung(); | 385 this.messung = new Messung(); |
406 this.messungTranslation = new MessungTranslation(); | |
407 } | 386 } |
408 | 387 |
409 /** | 388 /** |
410 * Add the {@link Ort} and {@link LOrt} entities to the lists and create | 389 * Add the {@link Ort} and {@link LOrt} entities to the lists and create |
411 * a new {@link OrtCreator}. | 390 * a new {@link OrtCreator}. |
414 if (this.ort != null) { | 393 if (this.ort != null) { |
415 Ort o = this.ort.toOrt(); | 394 Ort o = this.ort.toOrt(); |
416 if (o != null) { | 395 if (o != null) { |
417 this.orte.add(o); | 396 this.orte.add(o); |
418 } | 397 } |
419 LOrtszuordnung lo = this.ort.toLOrt(); | 398 Ortszuordnung lo = this.ort.toOrtszuordnung(); |
420 if (lo != null) { | 399 if (lo != null) { |
421 this.lorte.add(lo); | 400 this.ortszuordnungen.add(lo); |
422 } | 401 } |
423 } | 402 } |
424 OrtCreator creator = this.ort; | 403 OrtCreator creator = this.ort; |
425 creator.reset(); | 404 creator.reset(); |
426 creator.setProbeId(this.probe.getId()); | 405 creator.setProbeId(this.probe.getId()); |
449 | 428 |
450 /** | 429 /** |
451 * @return the errors | 430 * @return the errors |
452 */ | 431 */ |
453 public Map<String, List<ReportItem>> getErrors() { | 432 public Map<String, List<ReportItem>> getErrors() { |
454 if (this.probe == null || this.probeTranslation == null) { | 433 if (this.probe == null) { |
455 return this.errors; | 434 return this.errors; |
456 } | 435 } |
457 if (mapper.getErrors() == null || mapper.getErrors().size() == 0) { | 436 if (mapper.getErrors() == null || mapper.getErrors().size() == 0) { |
458 return this.errors; | 437 return this.errors; |
459 } | 438 } |
460 String key = probeTranslation.getProbeIdAlt() == null ? | 439 String key = probe.getIdAlt() == null ? |
461 "probeId" : probeTranslation.getProbeIdAlt(); | 440 "probeId" : probe.getIdAlt(); |
462 List<ReportItem> err = this.errors.get(key); | 441 List<ReportItem> err = this.errors.get(key); |
463 if (err == null) { | 442 if (err == null) { |
464 this.errors.put(key, mapper.getErrors()); | 443 this.errors.put(key, mapper.getErrors()); |
465 } | 444 } |
466 else { | 445 else { |