[Lada-commits] [PATCH] Do not allow empty string for media descriptor

Wald Commits scm-commit at wald.intevation.org
Fri Oct 28 21:22:52 CEST 2016


# HG changeset patch
# User Tom Gottfried <tom at intevation.de>
# Date 1477682384 -7200
# Node ID 1ef08710aaeb0736483547c7823c6209b9fd66b9
# Parent  24f374c771b3e789848d4e35acab0d12a0febd7a
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.

diff -r 24f374c771b3 -r 1ef08710aaeb db_schema/lada_schema.sql
--- 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,
diff -r 24f374c771b3 -r 1ef08710aaeb src/main/java/de/intevation/lada/factory/ProbeFactory.java
--- 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;
     }
 
diff -r 24f374c771b3 -r 1ef08710aaeb src/main/java/de/intevation/lada/validation/rules/probe/Deskriptor.java
--- 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(" ");


More information about the Lada-commits mailing list