changeset 2373:056b3a5aa181

Removed "NOT NULL" constraint from gauges.range_id because there are gauges which dont have a Gueltigkeitsbereich. flys-backend/trunk@3564 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 02 Jan 2012 13:42:27 +0000
parents 027736510a30
children ab1e642e7c85
files flys-backend/ChangeLog flys-backend/doc/schema/postgresql.sql flys-backend/src/main/java/de/intevation/flys/model/River.java
diffstat 3 files changed, 21 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/ChangeLog	Wed Dec 28 12:16:52 2011 +0000
+++ b/flys-backend/ChangeLog	Mon Jan 02 13:42:27 2012 +0000
@@ -1,3 +1,16 @@
+2012-01-02	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* doc/schema/postgresql.sql: Remove 'NOT NULL' constraint from
+	  gauges.range_id because there are gauges which don't have
+	  a 'Gueltigkeitsbereich'
+	
+	  To adjust existing PostgreSQL databases use:
+	
+	      ALTER TABLE gauges ALTER COLUMN range_id DROP NOT NULL;
+
+	* src/main/java/de/intevation/flys/model/River.java: Handle
+	  null references to 'Gueltigkeitsbereiche'.
+
 2011-12-28  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/model/Wst.java: Added a method
--- a/flys-backend/doc/schema/postgresql.sql	Wed Dec 28 12:16:52 2011 +0000
+++ b/flys-backend/doc/schema/postgresql.sql	Mon Jan 02 13:42:27 2012 +0000
@@ -88,7 +88,7 @@
     -- Pegelnullpunkt
     datum    NUMERIC NOT NULL,
     -- Streckengueltigkeit
-    range_id int NOT NULL REFERENCES ranges (id),
+    range_id int REFERENCES ranges (id),
 
     UNIQUE (name, river_id),
     UNIQUE (river_id, station)
--- a/flys-backend/src/main/java/de/intevation/flys/model/River.java	Wed Dec 28 12:16:52 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/model/River.java	Mon Jan 02 13:42:27 2012 +0000
@@ -231,7 +231,9 @@
      * @return the min and max distance of this river.
      */
     public double[] determineMinMaxDistance() {
-        if (gauges == null) {
+        List<Gauge> gauges = getGauges();
+
+        if (gauges == null || gauges.isEmpty()) {
             return null;
         }
 
@@ -240,6 +242,10 @@
         for (Gauge g: gauges) {
             Range r = g.getRange();
 
+            if (r == null) {
+                continue;
+            }
+
             double a  = r.getA().doubleValue();
             minmax[0] = minmax[0] < a ? minmax[0] : a;
 

http://dive4elements.wald.intevation.org