changeset 1122:1ef08710aaeb

Do not allow empty string for media descriptor. For the sake of clearness NULL should be used for a missing value. This avoids extra checks e.g. for generating LAF exports. The CHECK constraints in the database could be more elaborate.
author Tom Gottfried <tom@intevation.de>
date Fri, 28 Oct 2016 21:19:44 +0200
parents 24f374c771b3
children cbd34e671683
files db_schema/lada_schema.sql src/main/java/de/intevation/lada/factory/ProbeFactory.java src/main/java/de/intevation/lada/validation/rules/probe/Deskriptor.java
diffstat 3 files changed, 24 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/db_schema/lada_schema.sql	Fri Oct 28 18:49:41 2016 +0200
+++ b/db_schema/lada_schema.sql	Fri Oct 28 21:19:44 2016 +0200
@@ -122,7 +122,7 @@
     ba_id integer DEFAULT 1 REFERENCES stammdaten.betriebsart,
     gem_id character varying(8) REFERENCES stammdaten.verwaltungseinheit,
     ort_id integer NOT NULL REFERENCES stammdaten.ort,
-    media_desk character varying(100),
+    media_desk character varying(100) CHECK(media_desk LIKE '% %'),
     umw_id character varying(3) REFERENCES stammdaten.umwelt,
     probenart_id integer NOT NULL REFERENCES stammdaten.probenart,
     probenintervall character varying(2) NOT NULL,
@@ -200,7 +200,7 @@
     datenbasis_id smallint REFERENCES stammdaten.datenbasis,
     ba_id integer REFERENCES stammdaten.betriebsart,
     probenart_id smallint NOT NULL REFERENCES stammdaten.probenart,
-    media_desk character varying(100),
+    media_desk character varying(100) CHECK(media_desk LIKE '% %'),
     media character varying(100),
     umw_id character varying(3) REFERENCES stammdaten.umwelt,
     probeentnahme_beginn timestamp with time zone,
--- a/src/main/java/de/intevation/lada/factory/ProbeFactory.java	Fri Oct 28 18:49:41 2016 +0200
+++ b/src/main/java/de/intevation/lada/factory/ProbeFactory.java	Fri Oct 28 21:19:44 2016 +0200
@@ -415,11 +415,14 @@
      * @return The updated probe object.
      */
     public Probe findUmweltId(Probe probe) {
-        String[] mediaDesk = probe.getMediaDesk().split(" ");
-        if (mediaDesk.length <= 1) {
-            return probe;
+        String mediaDesk = probe.getMediaDesk();
+        if (mediaDesk != null) {
+            String[] mediaDeskParts = mediaDesk.split(" ");
+            if (mediaDeskParts.length <= 1) {
+                return probe;
+            }
+            probe.setUmwId(findUmwelt(mediaDeskParts));
         }
-        probe.setUmwId(findUmwelt(mediaDesk));
         return probe;
     }
 
@@ -431,11 +434,14 @@
      * @return The updated probe object.
      */
     public Probe findMediaDesk(Probe probe) {
-        Object result = repository.queryFromString(
+        String mediaDesk = probe.getMediaDesk();
+        if (mediaDesk != null) {
+            Object result = repository.queryFromString(
                 "SELECT get_media_from_media_desk( :mediaDesk );", "stamm")
-            .setParameter("mediaDesk", probe.getMediaDesk())
-            .getSingleResult();
-        probe.setMedia(result != null ? result.toString() : "");
+                .setParameter("mediaDesk", mediaDesk)
+                .getSingleResult();
+            probe.setMedia(result != null ? result.toString() : "");
+        }
         return probe;
     }
 
@@ -447,11 +453,14 @@
      * @return The updated messprogramm.
      */
     public Messprogramm findUmweltId(Messprogramm messprogramm) {
-        String[] mediaDesk = messprogramm.getMediaDesk().split(" ");
-        if (mediaDesk.length <= 1) {
-            return messprogramm;
+        String mediaDesk = messprogramm.getMediaDesk();
+        if (mediaDesk != null) {
+            String[] mediaDeskParts = mediaDesk.split(" ");
+            if (mediaDeskParts.length <= 1) {
+                return messprogramm;
+            }
+            messprogramm.setUmwId(findUmwelt(mediaDeskParts));
         }
-        messprogramm.setUmwId(findUmwelt(mediaDesk));
         return messprogramm;
     }
 
--- a/src/main/java/de/intevation/lada/validation/rules/probe/Deskriptor.java	Fri Oct 28 18:49:41 2016 +0200
+++ b/src/main/java/de/intevation/lada/validation/rules/probe/Deskriptor.java	Fri Oct 28 21:19:44 2016 +0200
@@ -38,7 +38,7 @@
     @Override
     public Violation execute(Object object) {
         Probe probe = (Probe)object;
-        if (probe.getMediaDesk() == null || probe.getMediaDesk().equals("")) {
+        if (probe.getMediaDesk() == null) {
             return null;
         }
         String[] mediaDesk = probe.getMediaDesk().split(" ");
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)