[PATCH 05 of 12] Importer (s/u-info) extensions: check and log message for missing values (km, date, waterlevel etc.) and wrong waterlevel unit

Wald Commits scm-commit at wald.intevation.org
Mon Mar 23 16:38:43 CET 2020


# HG changeset patch
# User mschaefer
# Date 1584972609 -3600
#      Mon Mar 23 15:10:09 2020 +0100
# Node ID 8a2a777a8372c57343c84427381de4b4c51788dd
# Parent  3b3c7513472e73d41a2edb76c37c01034586a234
Importer (s/u-info) extensions: check and log message for missing values (km, date, waterlevel etc.) and wrong waterlevel unit

diff -r 3b3c7513472e -r 8a2a777a8372 backend/src/main/java/org/dive4elements/river/importer/sinfo/importitem/CollisionSeriesImport.java
--- a/backend/src/main/java/org/dive4elements/river/importer/sinfo/importitem/CollisionSeriesImport.java	Mon Mar 23 15:06:26 2020 +0100
+++ b/backend/src/main/java/org/dive4elements/river/importer/sinfo/importitem/CollisionSeriesImport.java	Mon Mar 23 15:10:09 2020 +0100
@@ -54,7 +54,7 @@
     }
 
     @Override
-    public List<Collision> querySeriesItem(final Session session, final River river) {
+    public List<Collision> querySeriesItem(final Session session, final River river, final boolean doQueryParent) {
         final Query query = session.createQuery("FROM Collision WHERE river=:river AND lower(filename)=:filename");
         query.setParameter("river", river);
         query.setParameter("filename", this.filename.toLowerCase());
diff -r 3b3c7513472e -r 8a2a777a8372 backend/src/main/java/org/dive4elements/river/importer/sinfo/parsers/CollisionParser.java
--- a/backend/src/main/java/org/dive4elements/river/importer/sinfo/parsers/CollisionParser.java	Mon Mar 23 15:06:26 2020 +0100
+++ b/backend/src/main/java/org/dive4elements/river/importer/sinfo/parsers/CollisionParser.java	Mon Mar 23 15:10:09 2020 +0100
@@ -51,7 +51,7 @@
 
     private enum ColTitlePattern {
         DATE("Datum.*"), //
-        GAUGE_W("Pegelstand\\s*\\[(.*)\\].*"), //
+        GAUGE_W("Pegelstand\\s*\\[cm\\].*"), //
         GAUGE_NAME("Bezugspegel.*"), //
         TYPE("Unfallart.*");
 
@@ -153,16 +153,30 @@
                 }
             }
         }
-        if (this.cols.get(ColTitlePattern.DATE) < 0)
-            logWarning("Column of the event dates could not be identified, missing column title 'Datum'");
+        if (this.cols.get(ColTitlePattern.DATE) < 0) {
+            logLineError("Column of the event dates could not be identified, missing column title 'Datum'");
+            this.headerParsingState = ParsingState.STOP;
+            return true;
+        }
+        if (this.cols.get(ColTitlePattern.GAUGE_W) < 0) {
+            logLineError("Column of the waterlevel could not be identified, missing column title 'Pegelstand [cm]'");
+            this.headerParsingState = ParsingState.STOP;
+            return true;
+        }
+        if (this.cols.get(ColTitlePattern.GAUGE_W) < 0) {
+            logLineError("Column of the reference gauge could not be identified, missing column title 'Bezugspegel'");
+            this.headerParsingState = ParsingState.STOP;
+            return true;
+        }
         if (this.cols.get(ColTitlePattern.TYPE) < 0) {
-            logError("Column of the collision types could not be identified, missing column title 'Unfallart'");
+            logLineError("Column of the collision types could not be identified, missing column title 'Unfallart'");
             this.headerParsingState = ParsingState.STOP;
-            return false;
+            return true;
         }
         if (!this.metaPatternsMatched.contains(META_YEAR)) {
             logError("Required meta info for the year is missing");
             this.headerParsingState = ParsingState.STOP;
+            return true;
         }
         return true;
     }
@@ -174,7 +188,7 @@
             eventDate = dateFormat.parse(values[this.cols.get(ColTitlePattern.DATE)]);
         }
         catch (final Exception e) {
-            logError("Invalid date in line " + this.in.getLineNumber());
+            logLineWarning("Invalid or missing date");
             return null;
         }
         final String typeName = values[this.cols.get(ColTitlePattern.TYPE)].trim();
@@ -187,11 +201,12 @@
             this.types.put(typeKey, type);
         }
         String gaugeName = null;
-        if (this.cols.get(ColTitlePattern.GAUGE_NAME) >= 0)
-            gaugeName = values[this.cols.get(ColTitlePattern.GAUGE_NAME)].trim();
-        double gaugeW = Double.NaN;
-        if (this.cols.get(ColTitlePattern.GAUGE_W) >= 0)
-            gaugeW = parseDoubleWithNull(values[this.cols.get(ColTitlePattern.GAUGE_W)]).doubleValue();
-        return new CollisionKmLineImport(km, type, eventDate, gaugeName, gaugeW);
+        gaugeName = values[this.cols.get(ColTitlePattern.GAUGE_NAME)].trim();
+        final Number gaugeW = parseDoubleCheckNull(values, this.cols.get(ColTitlePattern.GAUGE_W));
+        if ((gaugeW == null) || Double.isNaN(gaugeW.doubleValue())) {
+            logLineWarning(INVALID_VALUE_ERROR_FORMAT, "waterlevel");
+            return null;
+        }
+        return new CollisionKmLineImport(km, type, eventDate, gaugeName, gaugeW.doubleValue());
     }
 }


More information about the Dive4Elements-commits mailing list