[PATCH] Enforce strings we rely on

Wald Commits scm-commit at wald.intevation.org
Fri Mar 27 18:54:07 CET 2015


# HG changeset patch
# User Tom Gottfried <tom at intevation.de>
# Date 1427478843 -3600
# Node ID 9db1f48bfea99ccbfc82d263e644bc82e7012cf4
# Parent  c851d1ea543a9154ddf88dc206e128708fbc86a1
Enforce strings we rely on.

diff -r c851d1ea543a -r 9db1f48bfea9 backend/doc/schema/postgresql-minfo.sql
--- a/backend/doc/schema/postgresql-minfo.sql	Fri Mar 27 17:42:27 2015 +0100
+++ b/backend/doc/schema/postgresql-minfo.sql	Fri Mar 27 18:54:03 2015 +0100
@@ -325,6 +325,7 @@
     operator                 VARCHAR(64),
     commentary               VARCHAR(512),
     PRIMARY KEY (id),
+    CHECK(measurement_type IN ('Geschiebe', 'Schwebstoff')),
     CONSTRAINT fk_ms_range_id FOREIGN KEY (range_id)
         REFERENCES ranges(id) ON DELETE CASCADE,
     CONSTRAINT fk_ms_reference_gauge_id FOREIGN KEY (reference_gauge_id)
diff -r c851d1ea543a -r 9db1f48bfea9 backend/src/main/java/org/dive4elements/river/importer/parsers/MeasurementStationsParser.java
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/MeasurementStationsParser.java	Fri Mar 27 17:42:27 2015 +0100
+++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/MeasurementStationsParser.java	Fri Mar 27 18:54:03 2015 +0100
@@ -36,6 +36,9 @@
 
     public static final int MAX_COMMENT_LENGTH = 512;
 
+    public static final String MEASUREMENT_TYPE_BEDLOAD = "Geschiebe";
+    public static final String MEASUREMENT_TYPE_SUSP = "Schwebstoff";
+
     private static final Logger log = Logger
         .getLogger(MeasurementStationsParser.class);
 
@@ -140,12 +143,14 @@
 
     protected String getMeasurementType(String[] cols, int lineNum)
         throws MeasurementStationParserException {
-        if (cols[2] == null || cols[2].length() == 0) {
+        String mtype = cols[2].trim();
+        if (!(MEASUREMENT_TYPE_BEDLOAD.equals(mtype) ||
+                MEASUREMENT_TYPE_SUSP.equals(mtype))) {
             throw new MeasurementStationParserException(
                 "invalid measurement type in line " + lineNum);
         }
 
-        return cols[2];
+        return mtype;
     }
 
     protected String getRiverside(String[] cols, int lineNum) {
diff -r c851d1ea543a -r 9db1f48bfea9 backend/src/main/java/org/dive4elements/river/importer/parsers/SedimentLoadParser.java
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/SedimentLoadParser.java	Fri Mar 27 17:42:27 2015 +0100
+++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/SedimentLoadParser.java	Fri Mar 27 18:54:03 2015 +0100
@@ -22,16 +22,15 @@
 import org.dive4elements.river.model.River;
 import org.dive4elements.river.model.MeasurementStation;
 
+import static org.dive4elements.river.importer.parsers.MeasurementStationsParser.MEASUREMENT_TYPE_BEDLOAD;
+import static org.dive4elements.river.importer.parsers.MeasurementStationsParser.MEASUREMENT_TYPE_SUSP;
+
 /** Parses sediment load longitudinal section files. */
 public class SedimentLoadParser extends AbstractSedimentLoadParser {
     private static final Logger log =
         Logger.getLogger(SedimentLoadParser.class);
 
 
-    public static final String MEASUREMENT_TYPE_BEDLOAD = "Geschiebe";
-
-    public static final String MEASUREMENT_TYPE_SUSP = "Schwebstoff";
-
     public static final String GRAINFRACTION_NAME_SUSP = "suspended_sediment";
 
     public static final String GRAINFRACTION_NAME_TOTAL = "total";


More information about the Dive4Elements-commits mailing list