changeset 9654:8a2a777a8372

Importer (s/u-info) extensions: check and log message for missing values (km, date, waterlevel etc.) and wrong waterlevel unit
author mschaefer
date Mon, 23 Mar 2020 15:10:09 +0100
parents 3b3c7513472e
children 1f57381b3bb5
files backend/src/main/java/org/dive4elements/river/importer/sinfo/importitem/CollisionSeriesImport.java backend/src/main/java/org/dive4elements/river/importer/sinfo/parsers/CollisionParser.java
diffstat 2 files changed, 28 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- 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());
--- 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());
     }
 }

http://dive4elements.wald.intevation.org