[Dive4elements-commits] [PATCH 2 of 3] Allow null values in measurement_station columns without 'not null' constraints

Wald Commits scm-commit at wald.intevation.org
Wed Mar 27 11:49:03 CET 2013


# HG changeset patch
# User Raimund Renkert <rrenkert at intevation.de>
# Date 1364381276 -3600
# Node ID 278d8759c92b3028a95db9f76f621a048e15fc61
# Parent  84beabb3897c3eae72cfc634525c7f304b0dd2b3
Allow null values in measurement_station columns without 'not null' constraints.

diff -r 84beabb3897c -r 278d8759c92b flys-backend/src/main/java/de/intevation/flys/importer/ImportMeasurementStation.java
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportMeasurementStation.java	Wed Mar 27 11:46:00 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportMeasurementStation.java	Wed Mar 27 11:47:56 2013 +0100
@@ -58,10 +58,8 @@
             try {
                 gauge = getGaugeFromDB();
                 if (gauge == null) {
-                    log.warn("Skip measurement station '" + name
-                        + "': unable to find gauge with name '" + this.gauge
+                    log.warn("No gauge found for measurement station '" + name
                         + "'");
-                    return null;
                 }
             }
             catch (Exception e) {
@@ -70,28 +68,29 @@
 
             Range range = this.range.getPeer(river);
             if (range == null) {
-                log.warn("Skip measurement station '" + name
-                    + "': unable to get range");
-                return null;
+                log.warn("No range found for measurement station'" + name + "'");
             }
 
             TimeInterval observationTimerange = this.observationTimerange
                 .getPeer();
             if (observationTimerange == null) {
-                log.warn("Skip measurement station '" + name
-                    + "': unable to get time interval for observation time");
-                return null;
+                log.warn("No time range found for measurement station '"
+                    + name + "'");
             }
 
             Session session = ImporterSession.getInstance()
                 .getDatabaseSession();
 
             org.hibernate.Query query = session
-                .createQuery("FROM MeasurementStation "
-                    + "   WHERE river=:river AND station=:station");
+                .createQuery(
+                    "FROM MeasurementStation " +
+                    "WHERE river=:river" +
+                    "   AND station=:station " +
+                    "   AND measurement_type=:measurement_type ");
 
             query.setParameter("river", river);
             query.setParameter("station", station);
+            query.setParameter("measurement_type", measurementType);
 
             List<MeasurementStation> stations = query.list();
 
diff -r 84beabb3897c -r 278d8759c92b flys-backend/src/main/java/de/intevation/flys/importer/parsers/MeasurementStationsParser.java
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/MeasurementStationsParser.java	Wed Mar 27 11:46:00 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/MeasurementStationsParser.java	Wed Mar 27 11:47:56 2013 +0100
@@ -112,16 +112,15 @@
         }
     }
 
-    protected ImportRange getRange(String[] cols)
-        throws MeasurementStationParserException {
+    protected ImportRange getRange(String[] cols) {
         if (cols[4] == null || cols[4].length() == 0) {
-            throw new MeasurementStationParserException("invalid lower range '"
-                + cols[4] + "'");
+            log.warn("No upper value for range found in '" + cols[4] + "'");
+            return null;
         }
 
         if (cols[5] == null || cols[5].length() == 0) {
-            throw new MeasurementStationParserException("invalid lower range '"
-                + cols[5] + "'");
+            log.warn("No upper value for range found in '" + cols[5] + "'");
+            return null;
         }
 
         try {
@@ -131,8 +130,8 @@
             return new ImportRange(new BigDecimal(lower), new BigDecimal(upper));
         }
         catch (ParseException e) {
-            throw new MeasurementStationParserException(
-                "unable to parse range: " + e.getMessage());
+            log.warn("unable to parse range: " + e.getMessage());
+            return null;
         }
     }
 
@@ -150,21 +149,17 @@
         return cols[3];
     }
 
-    protected String getGauge(String[] cols)
-        throws MeasurementStationParserException {
+    protected String getGauge(String[] cols) {
         if (cols[6] == null || cols[6].length() == 0) {
-            throw new MeasurementStationParserException("invalid gauge '"
-                + cols[6] + "'");
+            log.warn("invalid gauge found: '" + cols[6] + "'");
         }
 
         return cols[6];
     }
 
-    protected ImportTimeInterval getObservationTimerange(String[] cols)
-        throws MeasurementStationParserException {
+    protected ImportTimeInterval getObservationTimerange(String[] cols) {
         if (cols[8] == null || cols[8].length() == 0) {
-            throw new MeasurementStationParserException(
-                "invalid observation time '" + cols[8] + "'");
+                log.warn("Found invalid observation time '" + cols[8] + "'");
         }
 
         try {
@@ -173,13 +168,13 @@
             if (date != null) {
                 return new ImportTimeInterval(date);
             }
-
-            throw new MeasurementStationParserException(
-                "invalid observation time '" + cols[8] + "'");
+            log.warn("Observation time date invalid: '" + cols[8] + "'");
         }
         catch (ParseException pe) {
-            throw new MeasurementStationParserException(pe.getMessage());
+            log.warn("Observation time date not parseable: '" + cols[8] + "'");
+            return null;
         }
+        return null;
     }
 
     protected String getOperator(String[] cols) {


More information about the Dive4elements-commits mailing list