[PATCH 04 of 12] Importer (s/u-info) extensions: support of multiple channel data series, check for non-overlapping year ranges
Wald Commits
scm-commit at wald.intevation.org
Mon Mar 23 16:38:42 CET 2020
# HG changeset patch
# User mschaefer
# Date 1584972386 -3600
# Mon Mar 23 15:06:26 2020 +0100
# Node ID 3b3c7513472e73d41a2edb76c37c01034586a234
# Parent dd93bb84561d33cf33501c39544cf247f5c12b04
Importer (s/u-info) extensions: support of multiple channel data series, check for non-overlapping year ranges
diff -r dd93bb84561d -r 3b3c7513472e backend/src/main/java/org/dive4elements/river/importer/sinfo/importitem/ChannelSeriesImport.java
--- a/backend/src/main/java/org/dive4elements/river/importer/sinfo/importitem/ChannelSeriesImport.java Mon Mar 23 15:03:11 2020 +0100
+++ b/backend/src/main/java/org/dive4elements/river/importer/sinfo/importitem/ChannelSeriesImport.java Mon Mar 23 15:06:26 2020 +0100
@@ -60,13 +60,16 @@
}
@Override
- public List<Channel> querySeriesItem(final Session session, final River river) {
- final Query query = session.createQuery("FROM Channel WHERE river=:river");
+ public List<Channel> querySeriesItem(final Session session, final River river, final boolean doQueryParent) {
+ final Query query = session.createQuery("FROM Channel WHERE river=:river AND (lower(filename)=:filename"
+ + " OR (:newfrom BETWEEN year_from AND year_to) OR (:newto BETWEEN year_from AND year_to))");
query.setParameter("river", river);
+ query.setParameter("filename", this.filename.toLowerCase());
+ query.setParameter("newfrom", this.year_from);
+ query.setParameter("newto", this.year_to);
return query.list();
}
-
@Override
public Channel createSeriesItem(final River river) {
return new Channel(river, this.filename, this.kmrange_info, this.notes, this.year_from, this.year_to);
diff -r dd93bb84561d -r 3b3c7513472e backend/src/main/java/org/dive4elements/river/importer/sinfo/parsers/ChannelParser.java
--- a/backend/src/main/java/org/dive4elements/river/importer/sinfo/parsers/ChannelParser.java Mon Mar 23 15:03:11 2020 +0100
+++ b/backend/src/main/java/org/dive4elements/river/importer/sinfo/parsers/ChannelParser.java Mon Mar 23 15:06:26 2020 +0100
@@ -38,9 +38,11 @@
private static final Logger log = Logger.getLogger(ChannelParser.class);
- private static final String IMPORT_FILENAME = "Fahrrinne.csv";
+ private static final Pattern IMPORT_FILENAME = Pattern.compile("Fahrrinne.*\\.csv", Pattern.CASE_INSENSITIVE);
- protected static final Pattern META_YEARS = Pattern.compile("^#\\sZeitraum:\\s*([12]\\d\\d\\d)*\\s*-\\s*([12]\\d\\d\\d)*.*", Pattern.CASE_INSENSITIVE);
+ private static final Pattern META_FIRST = Pattern.compile("^#\\sFahrrinne.*", Pattern.CASE_INSENSITIVE);
+
+ private static final Pattern META_YEARS = Pattern.compile("^#\\sZeitraum:\\s*([12]\\d\\d\\d)*\\s*-\\s*([12]\\d\\d\\d)*.*", Pattern.CASE_INSENSITIVE);
private static final Pattern WIDTH_COLUMNTITLE = Pattern.compile("Sollbreite\\s*\\[(.*)\\].*", Pattern.CASE_INSENSITIVE);
@@ -79,32 +81,49 @@
*/
public static List<ChannelParser> createParsers(final File importDir, final File relativeDir, final ImportRiver river) {
final List<ChannelParser> parsers = new ArrayList<>();
- final File importFile = new File(importDir, IMPORT_FILENAME);
- if (importFile.exists())
- parsers.add(new ChannelParser(importFile, new File(relativeDir, IMPORT_FILENAME), river));
+ if (importDir.exists())
+ for (final File file : listFiles(importDir, IMPORT_FILENAME))
+ parsers.add(new ChannelParser(file, new File(relativeDir, file.getName()), river));
return parsers;
}
@Override
protected boolean handleMetaOther() {
- if (handleMetaYears())
+ if (handleMetaFirst())
+ return true;
+ else if (handleMetaYears())
return true;
else
return false;
}
+ private boolean handleMetaFirst() {
+ final Matcher m = META_FIRST.matcher(this.currentLine);
+ if (m.matches()) {
+ this.metaPatternsMatched.add(META_FIRST);
+ return true;
+ }
+ return false;
+ }
+
private boolean handleMetaYears() {
final Matcher m = META_YEARS.matcher(this.currentLine);
if (m.matches()) {
this.metaPatternsMatched.add(META_YEARS);
- if (m.group(1) != null)
- this.seriesHeader.setYear_from(Integer.valueOf(m.group(1)));
- else
- this.seriesHeader.setYear_from(null);
- if (m.group(2) != null)
- this.seriesHeader.setYear_to(Integer.valueOf(m.group(2)));
- else
- this.seriesHeader.setYear_to(null);
+ try {
+ if (m.group(1) != null)
+ this.seriesHeader.setYear_from(Integer.valueOf(m.group(1)));
+ else
+ throw new NumberFormatException();
+ if (m.group(2) != null)
+ this.seriesHeader.setYear_to(Integer.valueOf(m.group(2)));
+ else
+ throw new NumberFormatException();
+ }
+ catch (final Exception e) {
+ logLineError("Invalid or missing start and/or end year");
+ this.headerParsingState = ParsingState.STOP;
+ }
return true;
}
return false;
@@ -120,9 +139,8 @@
this.widthColIndex = i;
}
if ((this.widthColIndex < 0) || (this.depthColIndex < 0)) {
- logError("Columns of width and/or depth values could not be identified, missing column title 'Sollbreite...'/'Sollhöhe...'");
+ logLineError("Columns of width and/or depth values could not be identified, missing column title 'Sollbreite...'/'Sollhöhe...'");
this.headerParsingState = ParsingState.STOP;
- return false;
}
return true;
}
@@ -137,15 +155,16 @@
@Override
protected ChannelKmLineImport createKmLineImport(final Double km, final String[] values) {
- if (parseDoubleWithNull(values[this.widthColIndex]) == null) {
- logError("Invalid width value in line " + this.in.getLineNumber());
+ final Number width = parseDoubleCheckNull(values, this.widthColIndex);
+ if ((width == null) || Double.isNaN(width.doubleValue())) {
+ logLineError(INVALID_VALUE_ERROR_FORMAT, "width");
return null;
}
- if (parseDoubleWithNull(values[this.depthColIndex]) == null) {
- logError("Invalid depth value in line " + this.in.getLineNumber());
+ final Number depth = parseDoubleCheckNull(values, this.depthColIndex);
+ if ((depth == null) || Double.isNaN(depth.doubleValue())) {
+ logLineError(INVALID_VALUE_ERROR_FORMAT, "depth");
return null;
}
- return new ChannelKmLineImport(km, parseDoubleWithNull(values[this.widthColIndex]).doubleValue(),
- parseDoubleWithNull(values[this.depthColIndex]).doubleValue());
+ return new ChannelKmLineImport(km, width.doubleValue(), depth.doubleValue());
}
}
More information about the Dive4Elements-commits
mailing list