[Lada-commits] [PATCH 2 of 4] Use injected ort creator to make the importer more robust

Wald Commits scm-commit at wald.intevation.org
Tue Sep 24 13:57:56 CEST 2013


# HG changeset patch
# User Raimund Renkert <rrenkert at intevation.de>
# Date 1380020893 -7200
# Node ID 3d2c53a10ee6fc69ae68e738721da1267206f935
# Parent  d878ff29e521bc8478a881eb698a078802a6a247
Use injected ort creator to make the importer more robust.

diff -r d878ff29e521 -r 3d2c53a10ee6 src/main/java/de/intevation/lada/data/importer/LAFProducer.java
--- 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());
     }
 
diff -r d878ff29e521 -r 3d2c53a10ee6 src/main/java/de/intevation/lada/data/importer/OrtCreator.java
--- 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 at intevation.de">Raimund Renkert</a>
  */
+ at 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;
+    }
 }


More information about the Lada-commits mailing list