Mercurial > dive4elements > river
changeset 7481:bdb12632c5f5
WST-Parser and doc: reject files with wrong number of columns.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 31 Oct 2013 15:25:31 +0100 |
parents | 2a2e89c01588 |
children | 47905b570eaf |
files | backend/doc/documentation/de/importer-hydr-morph.tex backend/src/main/java/org/dive4elements/river/importer/parsers/WstParser.java |
diffstat | 2 files changed, 28 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/backend/doc/documentation/de/importer-hydr-morph.tex Thu Oct 31 13:11:03 2013 +0100 +++ b/backend/doc/documentation/de/importer-hydr-morph.tex Thu Oct 31 15:25:31 2013 +0100 @@ -399,10 +399,14 @@ obwohl sich das Gewässer noch nicht in der Datenbank befindet (siehe Kapitel \ref{import_data}). -\textbf{Stations in 'XYZ' near line \# not ordered. File rejected.} +\textbf{WST: Stations in 'XYZ' near line \# not ordered. File rejected.} \\Die Stationen in einer WST-Datei sind nicht konsequent auf- oder absteigend geordnet. Die Datei wird verworfen. +\textbf{WST: number of columns is less than expected. File rejected.} +\\Die Anzahl der Spalten in einer Zeile einer WST-Datei stimmt nicht +mit der Angabe im Datei-Kopf überein. Die Datei wird verworfen. + \textbf{File 'XYZ' is broken!} \\Die Datei XYZ ist inkonsistent und führt zu Fehlern.
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/WstParser.java Thu Oct 31 13:11:03 2013 +0100 +++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/WstParser.java Thu Oct 31 15:25:31 2013 +0100 @@ -188,8 +188,14 @@ // handle Q-lines if (line.startsWith("*\u001f")) { - BigDecimal [] data = - parseLineAsDouble(line, columnCount, false, true); + BigDecimal [] data = null; + try { + data = parseLineAsDouble(line, columnCount, false, true); + } + catch(IllegalArgumentException iae) { + log.error(iae.getMessage()); + return; + } if (aktAbfluesse != null) { // add Q-ranges obtained from previous lines if (kmHist1 != null && kmHist2 != null @@ -329,8 +335,14 @@ columnHeaderChecked = true; } - BigDecimal [] data = - parseLineAsDouble(line, columnCount, true, false); + BigDecimal [] data = null; + try { + data = parseLineAsDouble(line, columnCount, true, false); + } + catch(IllegalArgumentException iae) { + log.error(iae.getMessage()); + return; + } BigDecimal kaem = data[0]; @@ -345,7 +357,7 @@ // check consistence of station ordering in file if (kmHist2 != null && kmHist2.compareTo(kmHist1) != kmHist1.compareTo(kaem)) { - throw new ParseException("Stations in " + file + + throw new ParseException("WST: Stations in " + file + " near line " + in.getLineNumber() + " not ordered. File rejected."); } @@ -529,11 +541,15 @@ strings.add(line.substring(0, 8)); } - int pos = 9; + int pos = 0; for (int i = 0; i < tokenCount; ++i) { + pos += 9; + if (pos >= line.length()) { + throw new IllegalArgumentException( + "WST: number of columns is less than expected. File rejected."); + } strings.add(line.substring(pos, Math.min(pos + 8, line.length()))); - pos += 9; } return strings.toArray(new String[strings.size()]);