changeset 364:d39d3886b97d

Use the new ort creator to produce ort and lort objects from laf attributes.
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 10 Sep 2013 10:16:05 +0200
parents e56527c79a46
children fab80595ed55
files src/main/java/de/intevation/lada/data/importer/AttributeMapper.java src/main/java/de/intevation/lada/data/importer/LAFParser.java src/main/java/de/intevation/lada/data/importer/LAFProducer.java src/main/java/de/intevation/lada/data/importer/LAFWriter.java src/main/java/de/intevation/lada/data/importer/Producer.java src/main/java/de/intevation/lada/data/importer/Writer.java
diffstat 6 files changed, 89 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/data/importer/AttributeMapper.java	Tue Sep 10 10:12:04 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/importer/AttributeMapper.java	Tue Sep 10 10:16:05 2013 +0200
@@ -5,10 +5,7 @@
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
-import java.util.HashMap;
-import java.util.LinkedList;
 import java.util.List;
-import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -24,11 +21,9 @@
 import de.intevation.lada.model.LMessung;
 import de.intevation.lada.model.LMessungId;
 import de.intevation.lada.model.LMesswert;
-import de.intevation.lada.model.LOrt;
 import de.intevation.lada.model.LProbe;
 import de.intevation.lada.model.LProbeInfo;
 import de.intevation.lada.model.LZusatzWert;
-import de.intevation.lada.model.Ort;
 import de.intevation.lada.model.SDatenbasis;
 import de.intevation.lada.model.SMessEinheit;
 import de.intevation.lada.model.SMessgroesse;
@@ -62,6 +57,7 @@
         this.warnings = new ArrayList<ReportData>();
         this.errors = new ArrayList<ReportData>();
     }
+
     public LProbe addAttribute(String key, Object value, LProbe probe) {
         DateFormat format = new SimpleDateFormat("yyyyMMdd HHmm");
         if ("datenbasis_s".equals(key) && probe.getDatenbasisId() == null) {
@@ -352,33 +348,52 @@
                 return null;
             }
         }
-        //TODO: Match the other values.
         return messwert;
     }
 
-    public LOrt addAttribute(
+    public OrtCreator addAttribute(
         String key,
         Object values,
-        LOrt ort
+        OrtCreator ort
     ) {
-        if ("ort_id".equals(key)) {
-            Integer v = Integer.valueOf(values.toString());
-            ort.setOrtId(v);
-        }
         if ("ort_code".equals(key)) {
-            QueryBuilder<Ort> builder =
-                new QueryBuilder<Ort>(ortRepo.getEntityManager(), Ort.class);
-            builder.and("bezeichnung", values.toString());
-            Response response = ortRepo.filter(builder.getQuery());
-            List<Ort> orte = (List<Ort>)response.getData();
-            Integer v = Integer.valueOf(orte.get(0).getOrtId());
-            ort.setOrtId(v);
+            ort.setOrtCode(values.toString());
         }
         if ("ort_typ".equals(key)) {
-            ort.setOrtsTyp(values.toString());
+            ort.setOrtTyp(values.toString());
         }
         if ("ort_zusatz".equals(key)) {
-            ort.setOrtszusatztext(values.toString());
+            ort.setZusatztext(values.toString());
+        }
+        if ("ort_land_lang".equals(key)) {
+            ort.setLandLang(values.toString());
+        }
+        if ("ort_land_kurz".equals(key)) {
+            ort.setLandKurz(values.toString());
+        }
+        if ("ort_land_s".equals(key)) {
+            ort.setLandS(values.toString());
+        }
+        if ("ort_gemeindeschlüssel".equals(key)) {
+            ort.setGemSchluessel(values.toString());
+        }
+        if ("ort_bezeichnung".equals(key)) {
+            ort.setBezeichnung(values.toString());
+        }
+        if ("ort_beschreibung".equals(key)) {
+            ort.setBeschreibung(values.toString());
+        }
+        if ("ort_nuts_code".equals(key)) {
+            ort.setNuts(values.toString());
+        }
+        if ("ort_hoehe_land".equals(key)) {
+            ort.setHoehe(values.toString());
+        }
+        if ("ort_koordinaten".equals(key)) {
+            ort.setKoordinaten(values.toString());
+        }
+        if ("ort_koordinaten_s".equals(key)) {
+            ort.setKoordinatenS(values.toString());
         }
         return ort;
     }
--- a/src/main/java/de/intevation/lada/data/importer/LAFParser.java	Tue Sep 10 10:12:04 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/importer/LAFParser.java	Tue Sep 10 10:16:05 2013 +0200
@@ -117,6 +117,7 @@
             return;
         }
         writer.writeOrte(auth, producer.getOrte());
+        writer.writeLOrte(auth, producer.getLOrte());
         writer.writeMessungKommentare(auth, producer.getMessungsKommentare());
         writer.writeMesswerte(auth, producer.getMesswerte());
         List<ReportData> err = this.errors.get(probeId);
@@ -179,7 +180,7 @@
             }
             else if (current == '%' && !header && !value) {
                 headerString = "";
-
+                producer.finishOrt();
                 key = false;
                 header = true;
             }
--- a/src/main/java/de/intevation/lada/data/importer/LAFProducer.java	Tue Sep 10 10:12:04 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/importer/LAFProducer.java	Tue Sep 10 10:16:05 2013 +0200
@@ -23,6 +23,7 @@
 import de.intevation.lada.model.LProbe;
 import de.intevation.lada.model.LZusatzWert;
 import de.intevation.lada.model.LZusatzWertId;
+import de.intevation.lada.model.Ort;
 import de.intevation.lada.model.SProbenZusatz;
 
 @Named("lafproducer")
@@ -36,12 +37,13 @@
 
     private LProbe probe;
     private LMessung messung;
-    private LOrt ort;
+    private OrtCreator ort;
 
     private List<LKommentarP> pKommentare;
     private List<LKommentarM> mKommentare;
     private List<LMessung> messungen;
-    private List<LOrt> orte;
+    private List<LOrt> lorte;
+    private List<Ort> orte;
     private List<LMesswert> messwerte;
     private List<LZusatzWert> zusatzwerte;
 
@@ -62,7 +64,7 @@
         this.pKommentare = new ArrayList<LKommentarP>();
         this.mKommentare = new ArrayList<LKommentarM>();
         this.messungen = new ArrayList<LMessung>();
-        this.orte = new ArrayList<LOrt>();
+        this.lorte = new ArrayList<LOrt>();
         this.messwerte = new ArrayList<LMesswert>();
         String fileName = System.getProperty("de.intevation.lada.importconfig");
         LAFFormat format = new LAFFormat();
@@ -215,11 +217,15 @@
     }
 
     @Override
-    public List<LOrt> getOrte() {
+    public List<Ort> getOrte() {
         return this.orte;
     }
 
     @Override
+    public List<LOrt> getLOrte() {
+        return this.lorte;
+    }
+    @Override
     public List<LKommentarP> getProbenKommentare() {
         return this.pKommentare;
     }
@@ -246,7 +252,8 @@
         this.probe = new LProbe();
         this.messungen = new ArrayList<LMessung>();
         this.messung = null;
-        this.orte = new ArrayList<LOrt>();
+        this.lorte = new ArrayList<LOrt>();
+        this.orte = new ArrayList<Ort>();
         this.ort = null;
         this.messwerte = new ArrayList<LMesswert>();
         this.mKommentare = new ArrayList<LKommentarM>();
@@ -267,9 +274,16 @@
 
     public void newOrt() {
         if (this.ort != null) {
-            this.orte.add(this.ort);
+            Ort o = this.ort.toOrt();
+            if (o != null) {
+                this.orte.add(o);
+            }
+            LOrt lo = this.ort.toLOrt();
+            if (lo != null) {
+                this.lorte.add(lo);
+            }
         }
-        this.ort = new LOrt();
+        this.ort = new OrtCreator();
         this.ort.setProbeId(this.probe.getProbeId());
     }
 
@@ -308,4 +322,12 @@
         }
         return this.errors;
     }
+
+    @Override
+    public void finishOrt() {
+        if (orte.isEmpty()) {
+            return;
+        }
+        
+    }
 }
--- a/src/main/java/de/intevation/lada/data/importer/LAFWriter.java	Tue Sep 10 10:12:04 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/importer/LAFWriter.java	Tue Sep 10 10:16:05 2013 +0200
@@ -2,7 +2,6 @@
 
 import java.math.BigInteger;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -14,7 +13,6 @@
 import javax.persistence.Query;
 
 import de.intevation.lada.auth.AuthenticationResponse;
-import de.intevation.lada.data.QueryBuilder;
 import de.intevation.lada.data.Repository;
 import de.intevation.lada.model.LKommentarM;
 import de.intevation.lada.model.LKommentarP;
@@ -22,8 +20,7 @@
 import de.intevation.lada.model.LMesswert;
 import de.intevation.lada.model.LOrt;
 import de.intevation.lada.model.LProbe;
-import de.intevation.lada.model.LProbeInfo;
-import de.intevation.lada.rest.Response;
+import de.intevation.lada.model.Ort;
 import de.intevation.lada.validation.ValidationException;
 import de.intevation.lada.validation.Validator;
 
@@ -55,6 +52,9 @@
     private Repository messungRepository;
     @Inject
     @Named("lortrepository")
+    private Repository lortRepository;
+    @Inject
+    @Named("ortrepository")
     private Repository ortRepository;
     @Inject
     @Named("lkommentarRepository")
@@ -151,12 +151,20 @@
     }
 
     @Override
-    public boolean writeOrte(AuthenticationResponse auth, List<LOrt> orte) {
+    public boolean writeOrte(AuthenticationResponse auth, List<Ort> orte) {
+        for (Ort ort :orte) {
+            ortRepository.create(ort);
+        }
+        return true;
+    }
+
+    @Override
+    public boolean writeLOrte(AuthenticationResponse auth, List<LOrt> orte) {
         for(LOrt ort: orte) {
             try {
                 Map<String, Integer> warn =
                     ortValidator.validate(ort, false);
-                ortRepository.create(ort);
+                lortRepository.create(ort);
                 if (warn != null) {
                     for (String key : warn.keySet()) {
                         warnings.add(
@@ -362,8 +370,7 @@
         if (probe.getSolldatumEnde() != null) {
             insert.setParameter("solldatum_ende", probe.getSolldatumEnde());
         }
-        int res = insert.executeUpdate();
-        int i = res;
+        insert.executeUpdate();
     }
 
     private boolean authorized(LProbe probe, AuthenticationResponse auth) {
--- a/src/main/java/de/intevation/lada/data/importer/Producer.java	Tue Sep 10 10:12:04 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/importer/Producer.java	Tue Sep 10 10:16:05 2013 +0200
@@ -10,15 +10,18 @@
 import de.intevation.lada.model.LOrt;
 import de.intevation.lada.model.LProbe;
 import de.intevation.lada.model.LZusatzWert;
+import de.intevation.lada.model.Ort;
 
 
 public interface Producer
 {
     public void addData(String key, Object values)
         throws LAFParserException;
+    public void finishOrt();
     public LProbe getProbe();
     public List<LMessung> getMessungen();
-    public List<LOrt> getOrte();
+    public List<LOrt> getLOrte();
+    public List<Ort> getOrte();
     public List<LKommentarP> getProbenKommentare();
     public List<LKommentarM> getMessungsKommentare();
     public List<LMesswert> getMesswerte();
--- a/src/main/java/de/intevation/lada/data/importer/Writer.java	Tue Sep 10 10:12:04 2013 +0200
+++ b/src/main/java/de/intevation/lada/data/importer/Writer.java	Tue Sep 10 10:16:05 2013 +0200
@@ -9,6 +9,7 @@
 import de.intevation.lada.model.LMesswert;
 import de.intevation.lada.model.LOrt;
 import de.intevation.lada.model.LProbe;
+import de.intevation.lada.model.Ort;
 
 
 public interface Writer
@@ -17,7 +18,8 @@
     public boolean writeMessungen(
         AuthenticationResponse auth,
         List<LMessung> messungen);
-    public boolean writeOrte(AuthenticationResponse auth, List<LOrt> orte);
+    public boolean writeLOrte(AuthenticationResponse auth, List<LOrt> orte);
+    public boolean writeOrte(AuthenticationResponse auth, List<Ort> orte);
     public boolean writeProbenKommentare(
         AuthenticationResponse auth,
         List<LKommentarP> kommentare);
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)