comparison src/main/java/de/intevation/lada/data/importer/AttributeMapper.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 4f9cde6277b0
comparison
equal deleted inserted replaced
365:fab80595ed55 366:567ce7697fc7
30 import de.intevation.lada.model.SProbenZusatz; 30 import de.intevation.lada.model.SProbenZusatz;
31 import de.intevation.lada.model.SProbenart; 31 import de.intevation.lada.model.SProbenart;
32 import de.intevation.lada.model.SUmwelt; 32 import de.intevation.lada.model.SUmwelt;
33 import de.intevation.lada.rest.Response; 33 import de.intevation.lada.rest.Response;
34 34
35 /**
36 * The AttributeMapper is used to set object attributes via string based
37 * key value pairs. The key represents a member of an entity object.
38 *
39 * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a>
40 */
35 @Stateless 41 @Stateless
36 public class AttributeMapper 42 public class AttributeMapper
37 { 43 {
38 @Inject 44 @Inject
39 private EntityManager em; 45 private EntityManager em;
51 private Repository sRepository; 57 private Repository sRepository;
52 58
53 private List<ReportData> warnings; 59 private List<ReportData> warnings;
54 private List<ReportData> errors; 60 private List<ReportData> errors;
55 61
62 /**
63 * Default constructor to create a new AttributeMapper object.
64 */
56 public AttributeMapper() { 65 public AttributeMapper() {
57 this.warnings = new ArrayList<ReportData>(); 66 this.warnings = new ArrayList<ReportData>();
58 this.errors = new ArrayList<ReportData>(); 67 this.errors = new ArrayList<ReportData>();
59 } 68 }
60 69
70 /**
71 * Add an attribute to the given LProbe object.
72 *
73 * @param key The key mapping to a object member.
74 * @param value The value to set.
75 * @param probe The entity object.
76 * @return The updated entity object.
77 */
61 public LProbe addAttribute(String key, Object value, LProbe probe) { 78 public LProbe addAttribute(String key, Object value, LProbe probe) {
62 DateFormat format = new SimpleDateFormat("yyyyMMdd HHmm"); 79 DateFormat format = new SimpleDateFormat("yyyyMMdd HHmm");
63 if ("datenbasis_s".equals(key) && probe.getDatenbasisId() == null) { 80 if ("datenbasis_s".equals(key) && probe.getDatenbasisId() == null) {
64 Integer v = Integer.valueOf(value.toString()); 81 Integer v = Integer.valueOf(value.toString());
65 probe.setDatenbasisId(v); 82 probe.setDatenbasisId(v);
201 probe.setProbenartId(Integer.valueOf(art.get(0).getProbenartId())); 218 probe.setProbenartId(Integer.valueOf(art.get(0).getProbenartId()));
202 } 219 }
203 return probe; 220 return probe;
204 } 221 }
205 222
223 /**
224 * Add an attribute to the given LKommentarP object.
225 *
226 * @param key The key mapping to a object member.
227 * @param value The value to set.
228 * @param kommentar The entity object.
229 * @return The updated entity object.
230 */
206 public LKommentarP addAttribute( 231 public LKommentarP addAttribute(
207 String key, 232 String key,
208 Object values, 233 Object value,
209 LKommentarP kommentar 234 LKommentarP kommentar
210 ) { 235 ) {
211 DateFormat format = new SimpleDateFormat("yyyyMMdd HHmm"); 236 DateFormat format = new SimpleDateFormat("yyyyMMdd HHmm");
212 String v = values.toString(); 237 String v = value.toString();
213 String erzeuger = v.substring(1, 5); 238 String erzeuger = v.substring(1, 5);
214 String date = v.substring(8, 21); 239 String date = v.substring(8, 21);
215 Date d; 240 Date d;
216 try { 241 try {
217 d = format.parse(date); 242 d = format.parse(date);
218 kommentar.setKDatum(d); 243 kommentar.setKDatum(d);
219 } 244 }
220 catch (ParseException e) { 245 catch (ParseException e) {
221 this.warnings.add(new ReportData(key, values.toString(), 674)); 246 this.warnings.add(new ReportData(key, value.toString(), 674));
222 } 247 }
223 String text = v.substring(23, v.length() -1); 248 String text = v.substring(23, v.length() -1);
224 kommentar.setErzeuger(erzeuger); 249 kommentar.setErzeuger(erzeuger);
225 kommentar.setKText(text); 250 kommentar.setKText(text);
226 return kommentar; 251 return kommentar;
227 } 252 }
228 253
254 /**
255 * Add an attribute to the given LKommentarM object.
256 *
257 * @param key The key mapping to a object member.
258 * @param value The value to set.
259 * @param kommentar The entity object.
260 * @return The updated entity object.
261 */
229 public LKommentarM addAttribute( 262 public LKommentarM addAttribute(
230 String key, 263 String key,
231 Object values, 264 Object value,
232 LKommentarM kommentar 265 LKommentarM kommentar
233 ) { 266 ) {
234 DateFormat format = new SimpleDateFormat("yyyyMMdd HHmm"); 267 DateFormat format = new SimpleDateFormat("yyyyMMdd HHmm");
235 String v = values.toString(); 268 String v = value.toString();
236 String erzeuger = v.substring(1, 5); 269 String erzeuger = v.substring(1, 5);
237 String date = v.substring(8, 21); 270 String date = v.substring(8, 21);
238 Date d; 271 Date d;
239 try { 272 try {
240 d = format.parse(date); 273 d = format.parse(date);
241 kommentar.setKDatum(d); 274 kommentar.setKDatum(d);
242 } 275 }
243 catch (ParseException e) { 276 catch (ParseException e) {
244 this.warnings.add(new ReportData(key, values.toString(), 674)); 277 this.warnings.add(new ReportData(key, value.toString(), 674));
245 } 278 }
246 String text = v.substring(23, v.length() -1); 279 String text = v.substring(23, v.length() -1);
247 kommentar.setErzeuger(erzeuger); 280 kommentar.setErzeuger(erzeuger);
248 kommentar.setKText(text); 281 kommentar.setKText(text);
249 return kommentar; 282 return kommentar;
250 } 283 }
251 284
285 /**
286 * Add an attribute to the given LMessung object.
287 *
288 * @param key The key mapping to a object member.
289 * @param value The value to set.
290 * @param messung The entity object.
291 * @return The updated entity object.
292 */
252 public LMessung addAttribute( 293 public LMessung addAttribute(
253 String key, 294 String key,
254 Object values, 295 Object value,
255 LMessung messung 296 LMessung messung
256 ) { 297 ) {
257 DateFormat format = new SimpleDateFormat("yyyyMMdd HHmm"); 298 DateFormat format = new SimpleDateFormat("yyyyMMdd HHmm");
258 if ("messungs_id".equals(key)) { 299 if ("messungs_id".equals(key)) {
259 LMessungId id = messung.getId(); 300 LMessungId id = messung.getId();
260 Integer v = Integer.valueOf(values.toString()); 301 Integer v = Integer.valueOf(value.toString());
261 id.setMessungsId(v); 302 id.setMessungsId(v);
262 messung.setMessungsId(v); 303 messung.setMessungsId(v);
263 messung.setId(id); 304 messung.setId(id);
264 } 305 }
265 else if ("nebenprobennummer".equals(key)) { 306 else if ("nebenprobennummer".equals(key)) {
266 messung.setNebenprobenNr(values.toString()); 307 messung.setNebenprobenNr(value.toString());
267 } 308 }
268 else if ("mess_datum_uhrzeit".equals(key)) { 309 else if ("mess_datum_uhrzeit".equals(key)) {
269 try { 310 try {
270 Date d = format.parse(values.toString()); 311 Date d = format.parse(value.toString());
271 messung.setMesszeitpunkt(d); 312 messung.setMesszeitpunkt(d);
272 } 313 }
273 catch (ParseException e) { 314 catch (ParseException e) {
274 this.warnings.add(new ReportData(key, values.toString(), 674)); 315 this.warnings.add(new ReportData(key, value.toString(), 674));
275 } 316 }
276 } 317 }
277 else if ("messzeit_sekunden".equals(key)) { 318 else if ("messzeit_sekunden".equals(key)) {
278 Integer i = Integer.valueOf(values.toString()); 319 Integer i = Integer.valueOf(value.toString());
279 messung.setMessdauer(i); 320 messung.setMessdauer(i);
280 } 321 }
281 else if ("messmethode_s".equals(key)) { 322 else if ("messmethode_s".equals(key)) {
282 messung.setMmtId(values.toString()); 323 messung.setMmtId(value.toString());
283 } 324 }
284 else if ("bearbeitungsstatus".equals(key)) { 325 else if ("bearbeitungsstatus".equals(key)) {
285 //ignored.!? 326 //ignored.!?
286 } 327 }
287 else if ("erfassung_abgeschlossen".equals(key)) { 328 else if ("erfassung_abgeschlossen".equals(key)) {
288 if(!values.toString().equals("0")) { 329 if(!value.toString().equals("0")) {
289 messung.setFertig(true); 330 messung.setFertig(true);
290 } 331 }
291 else { 332 else {
292 messung.setFertig(false); 333 messung.setFertig(false);
293 } 334 }
294 } 335 }
295 return messung; 336 return messung;
296 } 337 }
297 338
339 /**
340 * Add an attribute to the given LMesswert object.
341 *
342 * @param key The key mapping to a object member.
343 * @param value The value to set.
344 * @param messwert The entity object.
345 * @return The updated entity object.
346 */
298 public LMesswert addAttribute( 347 public LMesswert addAttribute(
299 String key, 348 String key,
300 Object values, 349 Object value,
301 LMesswert messwert 350 LMesswert messwert
302 ) { 351 ) {
303 Pattern p = Pattern.compile( 352 Pattern p = Pattern.compile(
304 "(\".+\")( .+ )(\".+\")( .*)( .{1,12})( .{1,9})(.{0,9})(.{0,3})"); 353 "(\".+\")( .+ )(\".+\")( .*)( .{1,12})( .{1,9})(.{0,9})(.{0,3})");
305 //TODO Does not perfectly match... Use better matching for floats. 354 //TODO Does not perfectly match... Use better matching for floats.
306 Matcher m = p.matcher(values.toString()); 355 Matcher m = p.matcher(value.toString());
307 if (m.matches()) { 356 if (m.matches()) {
308 String messgroesse = m.group(1).substring(1, m.group(1).length() - 1); 357 String messgroesse = m.group(1).substring(1, m.group(1).length() - 1);
309 String wert = m.group(2); 358 String wert = m.group(2);
310 String einheit = m.group(3).substring(1, m.group(3).length() - 1); 359 String einheit = m.group(3).substring(1, m.group(3).length() - 1);
311 if (wert.startsWith(" <")) { 360 if (wert.startsWith(" <")) {
349 } 398 }
350 } 399 }
351 return messwert; 400 return messwert;
352 } 401 }
353 402
403 /**
404 * Add an attribute to the OrtCreator. The creator is used to build the
405 * two objects Ort and LOrt.
406 *
407 * @param key The key mapping to a object member.
408 * @param value The value to set.
409 * @param ort The creator object.
410 * @return The updated creator object.
411 */
354 public OrtCreator addAttribute( 412 public OrtCreator addAttribute(
355 String key, 413 String key,
356 Object values, 414 Object value,
357 OrtCreator ort 415 OrtCreator ort
358 ) { 416 ) {
359 if ("ort_code".equals(key)) { 417 if ("ort_code".equals(key)) {
360 ort.setOrtCode(values.toString()); 418 ort.setOrtCode(value.toString());
361 } 419 }
362 if ("ort_typ".equals(key)) { 420 if ("ort_typ".equals(key)) {
363 ort.setOrtTyp(values.toString()); 421 ort.setOrtTyp(value.toString());
364 } 422 }
365 if ("ort_zusatz".equals(key)) { 423 if ("ort_zusatz".equals(key)) {
366 ort.setZusatztext(values.toString()); 424 ort.setZusatztext(value.toString());
367 } 425 }
368 if ("ort_land_lang".equals(key)) { 426 if ("ort_land_lang".equals(key)) {
369 ort.setLandLang(values.toString()); 427 ort.setLandLang(value.toString());
370 } 428 }
371 if ("ort_land_kurz".equals(key)) { 429 if ("ort_land_kurz".equals(key)) {
372 ort.setLandKurz(values.toString()); 430 ort.setLandKurz(value.toString());
373 } 431 }
374 if ("ort_land_s".equals(key)) { 432 if ("ort_land_s".equals(key)) {
375 ort.setLandS(values.toString()); 433 ort.setLandS(value.toString());
376 } 434 }
377 if ("ort_gemeindeschlüssel".equals(key)) { 435 if ("ort_gemeindeschlüssel".equals(key)) {
378 ort.setGemSchluessel(values.toString()); 436 ort.setGemSchluessel(value.toString());
379 } 437 }
380 if ("ort_bezeichnung".equals(key)) { 438 if ("ort_bezeichnung".equals(key)) {
381 ort.setBezeichnung(values.toString()); 439 ort.setBezeichnung(value.toString());
382 } 440 }
383 if ("ort_beschreibung".equals(key)) { 441 if ("ort_beschreibung".equals(key)) {
384 ort.setBeschreibung(values.toString()); 442 ort.setBeschreibung(value.toString());
385 } 443 }
386 if ("ort_nuts_code".equals(key)) { 444 if ("ort_nuts_code".equals(key)) {
387 ort.setNuts(values.toString()); 445 ort.setNuts(value.toString());
388 } 446 }
389 if ("ort_hoehe_land".equals(key)) { 447 if ("ort_hoehe_land".equals(key)) {
390 ort.setHoehe(values.toString()); 448 ort.setHoehe(value.toString());
391 } 449 }
392 if ("ort_koordinaten".equals(key)) { 450 if ("ort_koordinaten".equals(key)) {
393 ort.setKoordinaten(values.toString()); 451 ort.setKoordinaten(value.toString());
394 } 452 }
395 if ("ort_koordinaten_s".equals(key)) { 453 if ("ort_koordinaten_s".equals(key)) {
396 ort.setKoordinatenS(values.toString()); 454 ort.setKoordinatenS(value.toString());
397 } 455 }
398 return ort; 456 return ort;
399 } 457 }
400 458
459 /**
460 * Add an attribute to the given LZusatzwert object.
461 *
462 * @param lKey The key mapping to a object member.
463 * @param value The value to set.
464 * @param wert The entity object.
465 * @return The updated entity object.
466 */
401 public LZusatzWert addAttribute( 467 public LZusatzWert addAttribute(
402 String lKey, 468 String lKey,
403 Object values, 469 Object value,
404 LZusatzWert wert 470 LZusatzWert wert
405 ) { 471 ) {
406 String v = values.toString().substring(1); 472 String v = value.toString().substring(1);
407 int ndx = v.indexOf("\""); 473 int ndx = v.indexOf("\"");
408 String groesse = v.substring(0, ndx); 474 String groesse = v.substring(0, ndx);
409 v = v.substring(ndx + 2); 475 v = v.substring(ndx + 2);
410 ndx = v.indexOf(" "); 476 ndx = v.indexOf(" ");
411 String w = v.substring(0, ndx); 477 String w = v.substring(0, ndx);
428 wert.setMesswertPzs(Float.valueOf(w)); 494 wert.setMesswertPzs(Float.valueOf(w));
429 wert.setMessfehler(Float.valueOf(fehler)); 495 wert.setMessfehler(Float.valueOf(fehler));
430 return wert; 496 return wert;
431 } 497 }
432 498
499 /**
500 * Add an attribute to the given LZusatzwert object.
501 *
502 * @param lKey The key mapping to a object member.
503 * @param value The value to set.
504 * @param wert The entity object.
505 * @return The updated entity object.
506 */
433 public LZusatzWert addAttributeS( 507 public LZusatzWert addAttributeS(
434 String lKey, 508 String lKey,
435 Object values, 509 Object value,
436 LZusatzWert wert 510 LZusatzWert wert
437 ) { 511 ) {
438 String v = values.toString().substring(1); 512 String v = value.toString().substring(1);
439 int ndx = v.indexOf("\""); 513 int ndx = v.indexOf("\"");
440 String groesse = v.substring(0, ndx); 514 String groesse = v.substring(0, ndx);
441 v = v.substring(ndx + 2); 515 v = v.substring(ndx + 2);
442 ndx = v.indexOf(" "); 516 ndx = v.indexOf(" ");
443 String w = v.substring(0, ndx); 517 String w = v.substring(0, ndx);
449 wert.setPzsId(groesse); 523 wert.setPzsId(groesse);
450 wert.setMesswertPzs(Float.valueOf(w)); 524 wert.setMesswertPzs(Float.valueOf(w));
451 wert.setMessfehler(Float.valueOf(fehler)); 525 wert.setMessfehler(Float.valueOf(fehler));
452 return wert; 526 return wert;
453 } 527 }
528
454 /** 529 /**
455 * @return the warnings 530 * @return the warnings
456 */ 531 */
457 public List<ReportData> getWarnings() { 532 public List<ReportData> getWarnings() {
458 return warnings; 533 return warnings;
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)