changeset 372:3d2c53a10ee6

Use injected ort creator to make the importer more robust.
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 24 Sep 2013 13:08:13 +0200
parents d878ff29e521
children bc6d0785986f
files src/main/java/de/intevation/lada/data/importer/LAFProducer.java src/main/java/de/intevation/lada/data/importer/OrtCreator.java
diffstat 2 files changed, 84 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/data/importer/LAFProducer.java	Tue Sep 24 13:06:38 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/importer/LAFProducer.java	Tue Sep 24 13:08:13 2013 +0200
@@ -39,6 +39,7 @@
 
     private LProbe probe;
     private LMessung messung;
+    @Inject
     private OrtCreator ort;
 
     private List<LKommentarP> pKommentare;
@@ -183,7 +184,7 @@
             }
         }
         else if (isValidOrt(lKey, values.toString())) {
-            this.ort = mapper.addAttribute(lKey, values, this.ort);
+            this.ort.addAttribute(lKey, values);
         }
     }
 
@@ -320,7 +321,7 @@
         this.messung = null;
         this.lorte = new ArrayList<LOrt>();
         this.orte = new ArrayList<Ort>();
-        this.ort = null;
+        this.ort.reset();
         this.messwerte = new ArrayList<LMesswert>();
         this.mKommentare = new ArrayList<LKommentarM>();
         this.pKommentare = new ArrayList<LKommentarP>();
@@ -356,7 +357,7 @@
                 this.lorte.add(lo);
             }
         }
-        this.ort = new OrtCreator();
+        this.ort.reset();
         this.ort.setProbeId(this.probe.getProbeId());
     }
 
--- a/src/main/java/de/intevation/lada/data/importer/OrtCreator.java	Tue Sep 24 13:06:38 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/importer/OrtCreator.java	Tue Sep 24 13:08:13 2013 +0200
@@ -2,6 +2,7 @@
 
 import java.util.List;
 
+import javax.ejb.Stateless;
 import javax.inject.Inject;
 import javax.inject.Named;
 
@@ -18,6 +19,7 @@
  *
  * @author <a href="mailto:rrenkert@intevation.de">Raimund Renkert</a>
  */
+@Stateless
 public class OrtCreator
 {
     @Inject
@@ -305,6 +307,61 @@
     }
 
     /**
+     * Add an attribute to the OrtCreator. The creator is used to build the
+     * two objects Ort and LOrt.
+     *
+     * @param key       The key mapping to a object member.
+     * @param value     The value to set.
+     * @param ort       The creator object.
+     * @return The updated creator object.
+     */
+    public void addAttribute(
+        String key,
+        Object value
+    ) {
+        if ("ort_code".equals(key)) {
+            this.setOrtCode(value.toString());
+        }
+        if ("ort_typ".equals(key)) {
+            this.setOrtTyp(value.toString());
+        }
+        if ("ort_zusatz".equals(key)) {
+            this.setZusatztext(value.toString());
+        }
+        if ("ort_land_lang".equals(key)) {
+            this.setLandLang(value.toString());
+        }
+        if ("ort_land_kurz".equals(key)) {
+            this.setLandKurz(value.toString());
+        }
+        if ("ort_land_s".equals(key)) {
+            this.setLandS(value.toString());
+        }
+        if ("ort_gemeindeschlüssel".equals(key)) {
+            this.setGemSchluessel(value.toString());
+        }
+        if ("ort_bezeichnung".equals(key)) {
+            this.setBezeichnung(value.toString());
+        }
+        if ("ort_beschreibung".equals(key)) {
+            this.setBeschreibung(value.toString());
+        }
+        if ("ort_nuts_code".equals(key)) {
+            this.setNuts(value.toString());
+        }
+        if ("ort_hoehe_land".equals(key)) {
+            this.setHoehe(value.toString());
+        }
+        if ("ort_koordinaten".equals(key)) {
+            this.setKoordinaten(value.toString());
+        }
+        if ("ort_koordinaten_s".equals(key)) {
+            this.setKoordinatenS(value.toString());
+        }
+    }
+
+
+    /**
      * Create the Ort object.
      *
      * @return The new Ort.
@@ -610,7 +667,8 @@
      */
     public LOrt toLOrt() {
         if (this.ortId == null &&
-            (this.ortCode == null || this.ortCode.length() == 0)) {
+            (this.ortCode == null || this.ortCode.length() == 0) ||
+            this.probeId == null) {
             return null;
         }
         if(this.ortCode != null && this.ortCode.length() > 0) {
@@ -631,4 +689,25 @@
         return ort;
     }
 
+    public void reset() {
+        this.beschreibung = null;
+        this.bezeichnung = null;
+        this.gemName = null;
+        this.gemSchluessel = null;
+        this.hoehe = null;
+        this.koord = null;
+        this.koordArt = null;
+        this.koordinaten = null;
+        this.koordinatenS = null;
+        this.koordS = null;
+        this.landKurz = null;
+        this.landLang = null;
+        this.landS = null;
+        this.nuts = null;
+        this.ortCode = null;
+        this.ortId = null;
+        this.ortTyp = null;
+        this.probeId = null;
+        this.zusatztext = null;
+    }
 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)