changeset 1186:ddd4088d211d

merged
author Raimund Renkert <raimund.renkert@intevation.de>
date Mon, 21 Nov 2016 14:53:09 +0100
parents dc303c65c486 (current diff) 4c612aaba378 (diff)
children 3c24d33bf0db
files
diffstat 3 files changed, 94 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/exporter/laf/LafCreator.java	Mon Nov 21 14:49:22 2016 +0100
+++ b/src/main/java/de/intevation/lada/exporter/laf/LafCreator.java	Mon Nov 21 14:53:09 2016 +0100
@@ -47,6 +47,11 @@
 public class LafCreator
 implements Creator
 {
+    // Some format strings corresponding to LAF notation
+    private static final String KEY_FORMAT = "%-30s";
+    private static final String DEFAULT_FORMAT = "%s";
+    private static final String CN = "\"%s\""; // cn, mcn, scn
+
     @Inject
     private Logger logger;
     /**
@@ -64,8 +69,8 @@
     @Override
     public String create(String probeId) {
         String lafProbe = "%PROBE%\n";
-        lafProbe += "UEBERTRAGUNGSFORMAT           7\n";
-        lafProbe += "VERSION                       0084\n";
+        lafProbe += lafLine("UEBERTRAGUNGSFORMAT", "7", CN);
+        lafProbe += lafLine("VERSION", "0084", CN);
         lafProbe += probeToLAF(probeId);
         return lafProbe;
     }
@@ -127,19 +132,18 @@
             "": lafLine("DATENBASIS_S",
                 String.format("%02d", probe.getDatenbasisId()));
         laf += messstelle == null ?
-            "" : lafLine("NETZKENNUNG", messstelle.getNetzbetreiberId());
+            "" : lafLine("NETZKENNUNG", messstelle.getNetzbetreiberId(), CN);
         laf += probe.getMstId() == null ?
-            "" : lafLine("MESSSTELLE", probe.getMstId());
+            "" : lafLine("MESSSTELLE", probe.getMstId(), CN);
         laf += probe.getLaborMstId() == null ?
-            "" : lafLine("MESSLABOR", probe.getLaborMstId());
-        laf += lafLine("PROBE_ID", probe.getIdAlt());
+            "" : lafLine("MESSLABOR", probe.getLaborMstId(), CN);
+        laf += lafLine("PROBE_ID", probe.getIdAlt(), CN);
         laf += probe.getHauptprobenNr() == null ?
-            "" : lafLine("HAUPTPROBENNUMMER", probe.getHauptprobenNr());
+            "" : lafLine("HAUPTPROBENNUMMER", probe.getHauptprobenNr(), CN);
         laf += probe.getBaId() == null ?
-            "" : lafLine("MESSPROGRAMM_S", "\"" + probe.getBaId() + "\"");
+            "" : lafLine("MESSPROGRAMM_S", probe.getBaId(), CN);
         laf += probe.getProbenartId() == null ?
-            "" : lafLine("PROBENART",
-                "\"" + probenart + "\"");
+            "" : lafLine("PROBENART", probenart, CN);
         laf += probe.getSolldatumBeginn() == null ?
             "" : lafLine("SOLL_DATUM_UHRZEIT_A",
                 format.format(probe.getSolldatumBeginn()));
@@ -153,10 +157,10 @@
             "" : lafLine("PROBENAHME_DATUM_UHRZEIT_E",
                 format.format(probe.getProbeentnahmeEnde()));
         laf += probe.getUmwId() == null ?
-            "" : lafLine("UMWELTBEREICH_S", probe.getUmwId());
+            "" : lafLine("UMWELTBEREICH_S", probe.getUmwId(), CN);
         laf += probe.getMediaDesk() == null ?
-            "" : lafLine("DESKRIPTOREN", "\"" +
-                probe.getMediaDesk().replaceAll(" ", "").substring(2) + "\"");
+            "" : lafLine("DESKRIPTOREN",
+                probe.getMediaDesk().replaceAll(" ", "").substring(2), CN);
         laf += probe.getTest() == Boolean.TRUE ?
             lafLine("TESTDATEN", "1") : lafLine("TESTDATEN", "0");
         laf += writeOrt(probe);
@@ -227,7 +231,8 @@
             }
             if (o.getOrtszusatztext() != null &&
                 o.getOrtszusatztext().length() > 0) {
-                laf += lafLine(type + "ORTS_ZUSATZTEXT", o.getOrtszusatztext());
+                laf += lafLine(type + "ORTS_ZUSATZTEXT",
+                    o.getOrtszusatztext(), CN);
             }
             QueryBuilder<Ort> oBuilder =
                 new QueryBuilder<Ort>(
@@ -239,8 +244,11 @@
                     oBuilder.getQuery(),
                     "stamm").getData();
 
-            laf += lafLine(type + "HERKUNFTSLAND_S",
-                String.format("%08d", sOrte.get(0).getStaatId()));
+            if (sOrte.get(0).getStaatId() != null) {
+                laf += lafLine(type + "HERKUNFTSLAND_S",
+                    String.format("%08d", sOrte.get(0).getStaatId()));
+            }
+
             if (sOrte.get(0).getGemId() != null &&
                 sOrte.get(0).getGemId().length() > 0) {
                 laf += lafLine(type + "GEMEINDESCHLUESSEL",
@@ -248,14 +256,15 @@
             }
 
             String koord = String.format("%02d", sOrte.get(0).getKdaId());
-            koord += " ";
-            koord += sOrte.get(0).getKoordXExtern() + " ";
-            koord += sOrte.get(0).getKoordYExtern();
+            koord += " \"";
+            koord += sOrte.get(0).getKoordXExtern() + "\" \"";
+            koord += sOrte.get(0).getKoordYExtern() + "\"";
             laf += lafLine(type + "KOORDINATEN_S", koord);
 
             if (sOrte.get(0).getOzId() != null &&
                 sOrte.get(0).getOzId().length() > 0) {
-                laf += lafLine(type + "ORTS_ZUSATZCODE", sOrte.get(0).getOzId());
+                laf += lafLine(type + "ORTS_ZUSATZCODE",
+                    sOrte.get(0).getOzId(), CN);
             }
             if (sOrte.get(0).getHoeheUeberNn() != null) {
                 laf += lafLine(type + "HOEHE_NN",
@@ -313,7 +322,7 @@
             Response kommentar = repository.filter(kommBuilder.getQuery(), "land");
             List<KommentarM> kommentare = (List<KommentarM>)kommentar.getData();
             laf += lafLine("MESSUNGS_ID", m.getIdAlt().toString());
-            laf += lafLine("NEBENPROBENNUMMER", m.getNebenprobenNr());
+            laf += lafLine("NEBENPROBENNUMMER", m.getNebenprobenNr(), CN);
             laf += m.getMesszeitpunkt() == null ?
                 "" : lafLine(
                     "MESS_DATUM_UHRZEIT",
@@ -321,7 +330,7 @@
             laf += m.getMessdauer() == null ?
                 "" : lafLine("MESSZEIT_SEKUNDEN", m.getMessdauer().toString());
             laf += m.getMmtId() == null ?
-                "" : lafLine("MESSMETHODE_S", m.getMmtId());
+                "" : lafLine("MESSMETHODE_S", m.getMmtId(), CN);
             laf += lafLine("ERFASSUNG_ABGESCHLOSSEN", (m.getFertig() ? "1" : "0"));
             for (Messwert mw : werte) {
                 laf += writeMesswert(mw);
@@ -404,9 +413,21 @@
      * @return LAF conform line.
      */
     private String lafLine(String key, String value) {
-        for (int i = key.length(); i < 30; i++) {
-            key += " ";
-        }
-        return key + value + "\n";
+        return lafLine(key, value, DEFAULT_FORMAT);
     }
+
+    /**
+     * Write a single LAF conform line from key and value.
+     *
+     * @param key    The key.
+     * @param value  The value.
+     * @param format A format string for the value
+     * @return LAF conform line.
+     */
+    private String lafLine(String key, Object value, String format) {
+        return String.format(KEY_FORMAT, key)
+            + String.format(format, value)
+            + "\n";
+    }
+
 }
--- a/src/main/java/de/intevation/lada/model/stammdaten/Ort.java	Mon Nov 21 14:49:22 2016 +0100
+++ b/src/main/java/de/intevation/lada/model/stammdaten/Ort.java	Mon Nov 21 14:53:09 2016 +0100
@@ -38,6 +38,9 @@
     @Column(name="hoehe_ueber_nn")
     private Float hoeheUeberNn;
 
+    @Column(name="hoehe_land")
+    private Float hoeheLand;
+
     @Column(name="koord_x_extern")
     private String koordXExtern;
 
@@ -141,6 +144,14 @@
         this.hoeheUeberNn = hoeheUeberNn;
     }
 
+    public Float getHoeheLand() {
+        return this.hoeheLand;
+    }
+
+    public void setHoeheLand(Float hoeheLand) {
+        this.hoeheLand = hoeheLand;
+    }
+
     public String getKoordXExtern() {
         return this.koordXExtern;
     }
--- a/src/main/java/de/intevation/lada/rest/exporter/LafExportService.java	Mon Nov 21 14:49:22 2016 +0100
+++ b/src/main/java/de/intevation/lada/rest/exporter/LafExportService.java	Mon Nov 21 14:53:09 2016 +0100
@@ -14,6 +14,8 @@
 import javax.enterprise.context.RequestScoped;
 import javax.inject.Inject;
 import javax.json.JsonArray;
+import javax.json.JsonValue;
+import javax.json.JsonNumber;
 import javax.json.JsonObject;
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.Consumes;
@@ -24,10 +26,15 @@
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.ResponseBuilder;
 
+import de.intevation.lada.model.land.Probe;
 import de.intevation.lada.exporter.ExportConfig;
 import de.intevation.lada.exporter.ExportFormat;
 import de.intevation.lada.exporter.Exporter;
 import de.intevation.lada.util.annotation.AuthorizationConfig;
+import de.intevation.lada.util.annotation.RepositoryConfig;
+import de.intevation.lada.util.data.QueryBuilder;
+import de.intevation.lada.util.data.Repository;
+import de.intevation.lada.util.data.RepositoryType;
 import de.intevation.lada.util.auth.Authorization;
 import de.intevation.lada.util.auth.AuthorizationType;
 import de.intevation.lada.util.auth.UserInfo;
@@ -52,6 +59,13 @@
 public class LafExportService {
 
     /**
+     * The data repository granting read-only access.
+     */
+    @Inject
+    @RepositoryConfig(type=RepositoryType.RO)
+    private Repository repository;
+
+    /**
      * The exporter.
      */
     @Inject
@@ -84,21 +98,34 @@
         JsonObject proben,
         @Context HttpServletRequest request
     ) {
-        JsonArray array = proben.getJsonArray("proben");
+        List<Integer> providedIds = new ArrayList<Integer>();
+        for (JsonValue id : proben.getJsonArray("proben")) {
+            if (id instanceof JsonNumber) {
+                providedIds.add(((JsonNumber)id).intValue());
+            }
+        }
+
+        QueryBuilder<Probe> pBuilder = new QueryBuilder<Probe>(
+            repository.entityManager("land"), Probe.class);
+        pBuilder.andIn("id", providedIds);
+        List<Probe> pObjects = repository.filterPlain(
+            pBuilder.getQuery(), "land");
+
+        if (pObjects.isEmpty()) {
+            return Response.status(Response.Status.NOT_FOUND).build();
+        }
+
         List<Integer> probeIds = new ArrayList<Integer>();
-        String fileName = "export.laf";
+        for (Probe p : pObjects) {
+            probeIds.add(p.getId());
+        }
         UserInfo userInfo = authorization.getInfo(request);
-        for (int i = 0; i < array.size(); i++) {
-            Integer probeId = array.getInt(i);
-            //if (authorization.isAuthorized(userInfo, probeId)) {
-                probeIds.add(probeId);
-            //}
-        }
         InputStream exported = exporter.export(probeIds, userInfo);
+
         ResponseBuilder response = Response.ok((Object)exported);
         response.header(
             "Content-Disposition",
-            "attachment; filename=\"" + fileName + "\"");
+            "attachment; filename=\"export.laf\"");
         return response.build();
     }
 }
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)