changeset 9659:75bd347147ad

Importer (s/u-info) extensions: infrastructures: detecting, logging, cancelling in case of wrong column titles, detecting, logging and skipping lines with duplicate km+bank
author mschaefer
date Mon, 23 Mar 2020 15:37:37 +0100
parents d86c7cb68b41
children f0cad5212f49
files backend/src/main/java/org/dive4elements/river/importer/sinfo/importitem/InfrastructureKmLineImport.java backend/src/main/java/org/dive4elements/river/importer/sinfo/importitem/InfrastructureSeriesImport.java backend/src/main/java/org/dive4elements/river/importer/sinfo/parsers/InfrastructureParser.java
diffstat 3 files changed, 41 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/backend/src/main/java/org/dive4elements/river/importer/sinfo/importitem/InfrastructureKmLineImport.java	Mon Mar 23 15:33:40 2020 +0100
+++ b/backend/src/main/java/org/dive4elements/river/importer/sinfo/importitem/InfrastructureKmLineImport.java	Mon Mar 23 15:37:37 2020 +0100
@@ -49,6 +49,10 @@
         this.height = height;
     }
 
+    public ImportAttribute getBankAttribute() {
+        return this.bankAttribute;
+    }
+
     @Override
     protected InfrastructureValue queryValueItem(final Session session, final Infrastructure parent) {
         final Query query = session.createQuery("FROM InfrastructureValue WHERE (infrastructure=:parent) AND (attribute=:bank)"
--- a/backend/src/main/java/org/dive4elements/river/importer/sinfo/importitem/InfrastructureSeriesImport.java	Mon Mar 23 15:33:40 2020 +0100
+++ b/backend/src/main/java/org/dive4elements/river/importer/sinfo/importitem/InfrastructureSeriesImport.java	Mon Mar 23 15:37:37 2020 +0100
@@ -79,17 +79,27 @@
     }
 
     @Override
-    public List<Infrastructure> querySeriesItem(final Session session, final River river) {
+    public List<Infrastructure> querySeriesItem(final Session session, final River river, final boolean doQueryParent) {
         final Query query = session.createQuery("FROM Infrastructure WHERE river=:river AND lower(filename)=:filename");
         query.setParameter("river", river);
         query.setParameter("filename", this.filename.toLowerCase());
         return query.list();
     }
 
-
     @Override
     public Infrastructure createSeriesItem(final River river) {
         return new Infrastructure(river, this.filename, this.kmrange_info, this.notes, this.type.getPeer(), this.group.getPeer(), this.year, this.provider,
                 this.evaluation_by);
     }
+
+    @Override
+    public boolean addValue(final InfrastructureKmLineImport value) {
+        for (final InfrastructureKmLineImport item : this.values) {
+            if (item.getStation() != value.getStation())
+                continue;
+            if (item.getBankAttribute() == value.getBankAttribute())
+                return false;
+        }
+        return super.addValue(value);
+    }
 }
\ No newline at end of file
--- a/backend/src/main/java/org/dive4elements/river/importer/sinfo/parsers/InfrastructureParser.java	Mon Mar 23 15:33:40 2020 +0100
+++ b/backend/src/main/java/org/dive4elements/river/importer/sinfo/parsers/InfrastructureParser.java	Mon Mar 23 15:37:37 2020 +0100
@@ -202,41 +202,39 @@
 
     @Override
     protected boolean handleMetaColumnTitles() {
-        if (super.handleMetaColumnTitles()) {
-            for (int i = 1; i <= this.columnTitles.size() - 1; i++) {
-                if (HEIGHT_COLUMNTITLE.matcher(this.columnTitles.get(i)).matches())
-                    this.heightColIndex = i;
-                else if (BANK_COLUMNTITLE.matcher(this.columnTitles.get(i)).matches())
-                    this.bankColIndex = i;
-            }
-            if (this.bankColIndex < 0)
-                logWarning("Column of river side value could not be identified, missing column title 'Uferseite'");
-            if (this.heightColIndex < 0) {
-                logError("Column of height values could not be identified, missing column title 'Höhe...'");
-                this.headerParsingState = ParsingState.STOP;
-                return false;
-            }
-            return true;
+        if (!super.handleMetaColumnTitles())
+            return false;
+        for (int i = 1; i <= this.columnTitles.size() - 1; i++) {
+            if (HEIGHT_COLUMNTITLE.matcher(this.columnTitles.get(i)).matches())
+                this.heightColIndex = i;
+            else if (BANK_COLUMNTITLE.matcher(this.columnTitles.get(i)).matches())
+                this.bankColIndex = i;
         }
-        else
-            return false;
+        if (this.bankColIndex < 0) {
+            logLineError("Column of river side value could not be identified, missing column title 'Uferseite'");
+            this.headerParsingState = ParsingState.STOP;
+        }
+        if (this.heightColIndex < 0) {
+            logLineError("Column of height values could not be identified, missing column title 'Höhe...'");
+            this.headerParsingState = ParsingState.STOP;
+        }
+        return true;
     }
 
     @Override
     protected InfrastructureKmLineImport createKmLineImport(final Double km, final String[] values) {
-        if (parseDoubleWithNull(values[this.heightColIndex]) == null) {
-            logError("Invalid height value in line " + this.in.getLineNumber());
+        final Number height = parseDoubleCheckNull(values, this.heightColIndex);
+        if ((height == null) || Double.isNaN(height.doubleValue())) {
+            logLineError(INVALID_VALUE_ERROR_FORMAT, "height");
             return null;
         }
-        if ((this.bankColIndex >= 0) && this.bankAttributes.containsKey(values[this.bankColIndex].trim().toLowerCase())) {
-            final InfrastructureKmLineImport kmLine = new InfrastructureKmLineImport(km, parseDoubleWithNull(values[this.heightColIndex]).doubleValue(),
-                    this.bankAttributes.get(values[this.bankColIndex].trim().toLowerCase()));
-            logTrace("createKmLineImport(" + km.toString() + ") => " + kmLine.getStation());
-            return kmLine;
-        }
-        else {
-            logError("Invalid bank value in line " + this.in.getLineNumber());
+        final String bank = ((this.bankColIndex >= 0) && (values.length - 1 >= this.bankColIndex)) ? values[this.bankColIndex].trim().toLowerCase() : null;
+        if ((bank == null) || !this.bankAttributes.containsKey(bank)) {
+            logLineError("Invalid or missing bank value");
             return null;
         }
+        final InfrastructureKmLineImport kmLine = new InfrastructureKmLineImport(km, height.doubleValue(), this.bankAttributes.get(bank));
+        logTrace("createKmLineImport(" + km.toString() + ") => " + kmLine.getStation());
+        return kmLine;
     }
 }

http://dive4elements.wald.intevation.org