changeset 8642:9db1f48bfea9

Enforce strings we rely on.
author Tom Gottfried <tom@intevation.de>
date Fri, 27 Mar 2015 18:54:03 +0100
parents c851d1ea543a
children 999b9ab16738
files backend/doc/schema/postgresql-minfo.sql backend/src/main/java/org/dive4elements/river/importer/parsers/MeasurementStationsParser.java backend/src/main/java/org/dive4elements/river/importer/parsers/SedimentLoadParser.java
diffstat 3 files changed, 11 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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)
--- 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) {
--- 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";

http://dive4elements.wald.intevation.org