comparison backend/src/main/java/org/dive4elements/river/importer/sinfo/parsers/InfrastructureParser.java @ 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 ac41551a8e4d
children
comparison
equal deleted inserted replaced
9658:d86c7cb68b41 9659:75bd347147ad
200 return false; 200 return false;
201 } 201 }
202 202
203 @Override 203 @Override
204 protected boolean handleMetaColumnTitles() { 204 protected boolean handleMetaColumnTitles() {
205 if (super.handleMetaColumnTitles()) { 205 if (!super.handleMetaColumnTitles())
206 for (int i = 1; i <= this.columnTitles.size() - 1; i++) {
207 if (HEIGHT_COLUMNTITLE.matcher(this.columnTitles.get(i)).matches())
208 this.heightColIndex = i;
209 else if (BANK_COLUMNTITLE.matcher(this.columnTitles.get(i)).matches())
210 this.bankColIndex = i;
211 }
212 if (this.bankColIndex < 0)
213 logWarning("Column of river side value could not be identified, missing column title 'Uferseite'");
214 if (this.heightColIndex < 0) {
215 logError("Column of height values could not be identified, missing column title 'Höhe...'");
216 this.headerParsingState = ParsingState.STOP;
217 return false;
218 }
219 return true;
220 }
221 else
222 return false; 206 return false;
207 for (int i = 1; i <= this.columnTitles.size() - 1; i++) {
208 if (HEIGHT_COLUMNTITLE.matcher(this.columnTitles.get(i)).matches())
209 this.heightColIndex = i;
210 else if (BANK_COLUMNTITLE.matcher(this.columnTitles.get(i)).matches())
211 this.bankColIndex = i;
212 }
213 if (this.bankColIndex < 0) {
214 logLineError("Column of river side value could not be identified, missing column title 'Uferseite'");
215 this.headerParsingState = ParsingState.STOP;
216 }
217 if (this.heightColIndex < 0) {
218 logLineError("Column of height values could not be identified, missing column title 'Höhe...'");
219 this.headerParsingState = ParsingState.STOP;
220 }
221 return true;
223 } 222 }
224 223
225 @Override 224 @Override
226 protected InfrastructureKmLineImport createKmLineImport(final Double km, final String[] values) { 225 protected InfrastructureKmLineImport createKmLineImport(final Double km, final String[] values) {
227 if (parseDoubleWithNull(values[this.heightColIndex]) == null) { 226 final Number height = parseDoubleCheckNull(values, this.heightColIndex);
228 logError("Invalid height value in line " + this.in.getLineNumber()); 227 if ((height == null) || Double.isNaN(height.doubleValue())) {
228 logLineError(INVALID_VALUE_ERROR_FORMAT, "height");
229 return null; 229 return null;
230 } 230 }
231 if ((this.bankColIndex >= 0) && this.bankAttributes.containsKey(values[this.bankColIndex].trim().toLowerCase())) { 231 final String bank = ((this.bankColIndex >= 0) && (values.length - 1 >= this.bankColIndex)) ? values[this.bankColIndex].trim().toLowerCase() : null;
232 final InfrastructureKmLineImport kmLine = new InfrastructureKmLineImport(km, parseDoubleWithNull(values[this.heightColIndex]).doubleValue(), 232 if ((bank == null) || !this.bankAttributes.containsKey(bank)) {
233 this.bankAttributes.get(values[this.bankColIndex].trim().toLowerCase())); 233 logLineError("Invalid or missing bank value");
234 logTrace("createKmLineImport(" + km.toString() + ") => " + kmLine.getStation());
235 return kmLine;
236 }
237 else {
238 logError("Invalid bank value in line " + this.in.getLineNumber());
239 return null; 234 return null;
240 } 235 }
236 final InfrastructureKmLineImport kmLine = new InfrastructureKmLineImport(km, height.doubleValue(), this.bankAttributes.get(bank));
237 logTrace("createKmLineImport(" + km.toString() + ") => " + kmLine.getStation());
238 return kmLine;
241 } 239 }
242 } 240 }

http://dive4elements.wald.intevation.org