annotate backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightParser.java @ 8975:a0a0a7f912ab

Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
author mschaefer
date Tue, 03 Apr 2018 10:40:57 +0200
parents 5e38e2924c07
children 2693bfaf503d
rev   line source
5844
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5992
4c3ccf2b0304 Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5901
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5844
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5992
4c3ccf2b0304 Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5901
diff changeset
6 * documentation coming with Dive4Elements River for details.
5844
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5829
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
9 package org.dive4elements.river.importer.parsers;
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11 import java.io.File;
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
12 import java.io.FileInputStream;
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
13 import java.io.IOException;
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
14 import java.io.InputStreamReader;
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
15 import java.io.LineNumberReader;
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16 import java.math.BigDecimal;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17 import java.text.NumberFormat;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18 import java.text.ParseException;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
19 import java.util.ArrayList;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20 import java.util.Date;
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
21 import java.util.EnumMap;
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22 import java.util.List;
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
23 import java.util.Locale;
6273
e7526a074c0d Bed height parser: check for duplicate stations
Tom Gottfried <tom.gottfried@intevation.de>
parents: 6236
diff changeset
24 import java.util.TreeSet;
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25 import java.util.regex.Matcher;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26 import java.util.regex.Pattern;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
27
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
28 import org.apache.log4j.Logger;
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
29 import org.dive4elements.river.backend.utils.DateUtil;
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
30 import org.dive4elements.river.backend.utils.EpsilonComparator;
8559
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents: 8557
diff changeset
31 import org.dive4elements.river.importer.ImportBedHeight;
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
32 import org.dive4elements.river.importer.ImportBedHeightType;
8559
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents: 8557
diff changeset
33 import org.dive4elements.river.importer.ImportBedHeightValue;
5829
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
34 import org.dive4elements.river.importer.ImportElevationModel;
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
35 import org.dive4elements.river.importer.ImportLocationSystem;
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
36 import org.dive4elements.river.importer.ImportRange;
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
37 import org.dive4elements.river.importer.ImportTimeInterval;
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
38 import org.dive4elements.river.importer.ImportUnit;
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
39 import org.dive4elements.river.importer.ImporterSession;
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
40 import org.dive4elements.river.model.BedHeightType;
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41
8557
29ab66ce06aa Abstract parser for bed heights is obsolete.
"Tom Gottfried <tom@intevation.de>"
parents: 8556
diff changeset
42 public class BedHeightParser {
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
43
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44 private static final Logger log =
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
45 Logger.getLogger(BedHeightParser.class);
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47 public static final String ENCODING = "ISO-8859-1";
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49 public static final Locale DEFAULT_LOCALE = Locale.GERMAN;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51 public static final String START_META_CHAR = "#";
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52 public static final String SEPERATOR_CHAR = ";";
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54 public static final Pattern META_YEAR =
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
55 Pattern.compile("^Jahr: [^0-9]*(\\d*).*", Pattern.CASE_INSENSITIVE);
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
57 public static final Pattern META_TIMEINTERVAL =
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
58 Pattern.compile("^Zeitraum: Epoche (\\d*)-(\\d*).*", Pattern.CASE_INSENSITIVE);
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
59
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60 public static final Pattern META_TYPE =
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
61 Pattern.compile("^Aufnahmeart: (.*).*", Pattern.CASE_INSENSITIVE);
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
62
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
63 public static final Pattern META_LOCATION_SYSTEM =
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
64 Pattern.compile("^Lagesystem: (.*).*", Pattern.CASE_INSENSITIVE);
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66 public static final Pattern META_CUR_ELEVATION_SYSTEM =
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
67 Pattern.compile("^H.hensystem:\\s(.*)?? \\[(.*)\\].*", Pattern.CASE_INSENSITIVE);
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69 public static final Pattern META_OLD_ELEVATION_SYSTEM =
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
70 Pattern.compile("^urspr.ngliches H.hensystem:\\s(.*)?? \\[(.*)\\].*", Pattern.CASE_INSENSITIVE);
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
72 public static final Pattern META_RANGE =
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
73 Pattern.compile("^Strecke:\\D*(\\d++.?\\d*) ?- ?(\\d++.?\\d*).*", Pattern.CASE_INSENSITIVE);
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
74
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
75 public static final Pattern META_EVALUATION_BY =
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
76 Pattern.compile("^Auswerter: (.*).*", Pattern.CASE_INSENSITIVE);
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
77
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
78 public static final Pattern META_SOUNDING_WIDTH = Pattern.compile("^ausgewertete Peilbreite:\\s*(\\S.*).*", Pattern.CASE_INSENSITIVE);
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
79
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
80 public static final Pattern META_COMMENTS =
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
81 Pattern.compile("^Weitere Bemerkungen: (.*).*", Pattern.CASE_INSENSITIVE);
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
82
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
83 private static final Pattern META_COLUMNTITLES = Pattern.compile("^Fluss-km\\s*;.+", Pattern.CASE_INSENSITIVE);
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
84
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
85 private enum ColTitlePattern {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
86 KM("Fluss-km.*"), //
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
87 HEIGHT("mittlere Sohlh.he\\s*\\[(.*)\\].*"), //
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
88 UNCERTAINTY("Unsicherheit\\s*\\[(.*)\\].*"), //
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
89 GAP("Datenl.cke.*"), //
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
90 WIDTH("Peilbreite\\s*\\[(.*)\\].*"), //
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
91 MINHEIGHT("Minimale Sohlh.he\\s*\\[(.*)\\].*"), //
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
92 MAXHEIGHT("Maximale Sohlh.he\\s*\\[(.*)\\].*");
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
93
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
94 private final Pattern pattern;
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
95
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
96 private ColTitlePattern(final String regexp) {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
97 this.pattern = Pattern.compile(regexp, Pattern.CASE_INSENSITIVE);
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
98 }
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
99
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
100 public Pattern getPattern() {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
101 return this.pattern;
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
102 }
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
103 }
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
104
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
105 private final EnumMap<ColTitlePattern, Integer> cols = new EnumMap<>(ColTitlePattern.class);
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
106
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
107 protected static NumberFormat nf = NumberFormat.getInstance(DEFAULT_LOCALE);
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
108
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
109
8559
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents: 8557
diff changeset
110 protected List<ImportBedHeight> bedHeights;
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
111
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
112
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
113 protected ImportBedHeight newImportBedHeight(final String description) {
8559
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents: 8557
diff changeset
114 return new ImportBedHeight(description);
8557
29ab66ce06aa Abstract parser for bed heights is obsolete.
"Tom Gottfried <tom@intevation.de>"
parents: 8556
diff changeset
115 }
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
116
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
117
6273
e7526a074c0d Bed height parser: check for duplicate stations
Tom Gottfried <tom.gottfried@intevation.de>
parents: 6236
diff changeset
118 protected TreeSet<Double> kmExists;
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
119
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
120 public BedHeightParser() {
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
121 this.bedHeights = new ArrayList<>();
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
122 this.kmExists = new TreeSet<>(EpsilonComparator.CMP);
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
123 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
124
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
125
8559
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents: 8557
diff changeset
126 public List<ImportBedHeight> getBedHeights() {
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
127 return this.bedHeights;
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
128 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
129
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
130
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
131 public void parse(final File file) throws IOException {
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
132 log.info("Parsing bed height single file '" + file + "'");
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
133 final ImportBedHeight obj = newImportBedHeight(file.getName().replaceAll("\\.csv", ""));
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
134 this.kmExists.clear();
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
135 this.cols.clear();
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
136 for (final ColTitlePattern col : ColTitlePattern.values())
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
137 this.cols.put(col, -1);
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
138 LineNumberReader in = null;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
139 try {
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
140 in = new LineNumberReader(new InputStreamReader(new FileInputStream(file), ENCODING));
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
141
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
142 String line = null;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
143 while ((line = in.readLine()) != null) {
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
144 if ((line = line.trim()).length() == 0) {
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
145 continue;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
146 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
147
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
148 if (line.startsWith(START_META_CHAR)) {
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
149 handleMetaLine(obj, line);
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
150 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
151 else {
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
152 handleDataLine(obj, line);
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
153 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
154 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
155
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
156 log.info("File contained " + obj.getValueCount() + " values.");
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
157 this.bedHeights.add(obj);
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
158 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
159 finally {
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
160 if (in != null) {
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
161 in.close();
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
162 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
163 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
164 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
165
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
166
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
167 protected static String stripMetaLine(final String line) {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
168 final String tmp = line.substring(1, line.length());
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
169
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
170 if (tmp.startsWith(" ")) {
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
171 return tmp.substring(1, tmp.length());
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
172 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
173 else {
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
174 return tmp;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
175 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
176 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
177
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
178
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
179 protected void handleMetaLine(final ImportBedHeight obj, final String line) {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
180 final String meta = stripMetaLine(line);
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
181
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
182 if (handleMetaYear(obj, meta)) {
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
183 return;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
184 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
185 else if (handleMetaTimeInterval(obj, meta)) {
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
186 return;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
187 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
188 else if (handleMetaComment(obj, meta)) {
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
189 return;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
190 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
191 else if (handleMetaEvaluationBy(obj, meta)) {
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
192 return;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
193 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
194 else if (handleMetaRange(obj, meta)) {
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
195 return;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
196 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
197 else if (handleMetaType(obj, meta)) {
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
198 return;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
199 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
200 else if (handleMetaLocationSystem(obj, meta)) {
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
201 return;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
202 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
203 else if (handleMetaCurElevationModel(obj, meta)) {
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
204 return;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
205 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
206 else if (handleMetaOldElevationModel(obj, meta)) {
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
207 return;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
208 }
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
209 else if (handleMetaSoundingWidth(obj, meta)) {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
210 return;
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
211 }
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
212 else if (handleMetaColumnTitles(obj, meta)) {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
213 return;
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
214 }
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
215 else {
3662
0d27d02b1208 backend: Completed the error messages of the importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2811
diff changeset
216 log.warn("BHP: Meta line did not match any known type: " + line);
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
217 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
218 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
219
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
220
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
221 protected boolean handleMetaYear(final ImportBedHeight obj, final String line) {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
222 final Matcher m = META_YEAR.matcher(line);
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
223 if (m.matches()) {
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
224 final String tmp = m.group(1).trim();
5327
5376aa576604 Allow empty years in bed height parser.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5278
diff changeset
225 if (tmp.length() > 0) {
5376aa576604 Allow empty years in bed height parser.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5278
diff changeset
226 obj.setYear(Integer.parseInt(tmp));
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
227 }
5327
5376aa576604 Allow empty years in bed height parser.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5278
diff changeset
228 else {
5376aa576604 Allow empty years in bed height parser.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5278
diff changeset
229 log.warn("BHP: No year given.");
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
230 }
5327
5376aa576604 Allow empty years in bed height parser.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5278
diff changeset
231 return true;
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
232 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
233 return false;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
234 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
235
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
236
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
237 protected boolean handleMetaTimeInterval(final ImportBedHeight obj, final String line) {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
238 final Matcher m = META_TIMEINTERVAL.matcher(line);
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
239 if (m.matches()) {
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
240 final String lo = m.group(1).trim();
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
241 final String up = m.group(2).trim();
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
242 log.debug("Found time interval: " + lo + " - " + up);
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
243 try {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
244 final int lower = Integer.valueOf(lo);
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
245 final int upper = Integer.valueOf(up);
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
246 final Date fromYear = DateUtil.getStartDateFromYear(lower);
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
247 final Date toYear = DateUtil.getEndDateFromYear(upper);
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
248 obj.setTimeInterval(new ImportTimeInterval(fromYear, toYear));
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
249 }
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
250 catch (final NumberFormatException e) {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
251 log.warn("BHP: could not parse timeinterval", e);
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
252 }
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
253 return true;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
254 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
255 return false;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
256 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
257
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
258
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
259 protected boolean handleMetaComment(final ImportBedHeight obj, final String line) {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
260 final Matcher m = META_COMMENTS.matcher(line);
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
261 if (m.matches()) {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
262 final String tmp = m.group(1).replace(SEPERATOR_CHAR, "").trim();
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
263 obj.setComment(tmp);
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
264 return true;
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
265 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
266 return false;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
267 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
268
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
269
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
270 protected boolean handleMetaEvaluationBy(final ImportBedHeight obj, final String line) {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
271 final Matcher m = META_EVALUATION_BY.matcher(line);
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
272 if (m.matches()) {
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
273 final String tmp = m.group(1).replace(";", "").trim();
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
274 obj.setEvaluationBy(tmp);
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
275 return true;
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
276 }
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
277 return false;
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
278 }
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
279
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
280
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
281 protected boolean handleMetaRange(final ImportBedHeight obj, final String line) {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
282 final Matcher m = META_RANGE.matcher(line);
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
283 if (m.matches() && m.groupCount() >= 2) {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
284 final String a = m.group(1).replace(";", "").trim();
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
285 final String b = m.group(2).replace(";", "").trim();
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
286 try {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
287 final BigDecimal lower = new BigDecimal(nf.parse(a).doubleValue());
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
288 final BigDecimal upper = new BigDecimal(nf.parse(b).doubleValue());
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
289 obj.setRange(new ImportRange(lower, upper));
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
290 return true;
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
291 }
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
292 catch (final ParseException e) {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
293 log.warn("BHP: could not parse range", e);
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
294 }
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
295 }
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
296 return false;
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
297 }
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
298
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
299
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
300 protected boolean handleMetaType(final ImportBedHeight obj, final String line) {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
301 final Matcher m = META_TYPE.matcher(line);
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
302 if (m.matches()) {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
303 final String tmp = m.group(1).replace(";", "").trim();
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
304 final BedHeightType bht = BedHeightType.fetchBedHeightTypeForType(tmp, ImporterSession.getInstance().getDatabaseSession());
5273
db196abd16ca Use lookup table from bedd_height from database in importer.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3960
diff changeset
305 if (bht != null) {
db196abd16ca Use lookup table from bedd_height from database in importer.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3960
diff changeset
306 obj.setType(new ImportBedHeightType(bht));
3798
90f91ba077a8 Made importer more robust
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3662
diff changeset
307 return true;
90f91ba077a8 Made importer more robust
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3662
diff changeset
308 }
5901
92bc0aa3831d BHP: more informative error instead of warning if file can not be imported.
Tom Gottfried <tom@intevation.de>
parents: 5845
diff changeset
309 log.error("Unknown bed height type: '" + tmp + "'. File ignored.");
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
310 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
311 return false;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
312 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
313
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
314
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
315 protected boolean handleMetaLocationSystem(final ImportBedHeight obj, final String line) {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
316 final Matcher m = META_LOCATION_SYSTEM.matcher(line);
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
317 if (m.matches()) {
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
318 final String tmp = m.group(1).replace(";", "").trim();
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
319 obj.setLocationSystem(new ImportLocationSystem(tmp, tmp));
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
320 return true;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
321 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
322 return false;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
323 }
8557
29ab66ce06aa Abstract parser for bed heights is obsolete.
"Tom Gottfried <tom@intevation.de>"
parents: 8556
diff changeset
324
8689
ea676691e533 (issue1763) Reduce code-duplication (patch by Sascha Teichmann).
Tom Gottfried <tom@intevation.de>
parents: 8688
diff changeset
325
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
326 protected boolean handleMetaCurElevationModel(final ImportBedHeight obj, final String line) {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
327 final Matcher m = META_CUR_ELEVATION_SYSTEM.matcher(line);
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
328 if (m.matches()) {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
329 final String name = m.group(1).trim();
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
330 final String unit = m.group(2).trim();
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
331 obj.setCurElevationModel(new ImportElevationModel(name, new ImportUnit(unit)));
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
332 return true;
8689
ea676691e533 (issue1763) Reduce code-duplication (patch by Sascha Teichmann).
Tom Gottfried <tom@intevation.de>
parents: 8688
diff changeset
333 }
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
334 return false;
8689
ea676691e533 (issue1763) Reduce code-duplication (patch by Sascha Teichmann).
Tom Gottfried <tom@intevation.de>
parents: 8688
diff changeset
335 }
ea676691e533 (issue1763) Reduce code-duplication (patch by Sascha Teichmann).
Tom Gottfried <tom@intevation.de>
parents: 8688
diff changeset
336
8557
29ab66ce06aa Abstract parser for bed heights is obsolete.
"Tom Gottfried <tom@intevation.de>"
parents: 8556
diff changeset
337
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
338 protected boolean handleMetaOldElevationModel(final ImportBedHeight obj, final String line) {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
339 final Matcher m = META_OLD_ELEVATION_SYSTEM.matcher(line);
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
340 if (m.matches()) {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
341 final String name = m.group(1).trim();
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
342 final String unit = m.group(2).trim();
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
343 obj.setOldElevationModel(new ImportElevationModel(name, new ImportUnit(unit)));
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
344 return true;
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
345 }
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
346 return false;
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
347 }
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
348
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
349 protected boolean handleMetaSoundingWidth(final ImportBedHeight obj, final String line) {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
350 final Matcher m = META_SOUNDING_WIDTH.matcher(line);
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
351 if (m.matches()) {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
352 final String tmp = m.group(1).replace(SEPERATOR_CHAR, "").trim();
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
353 obj.setSoundingWidthInfo(tmp);
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
354 return true;
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
355 }
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
356 return false;
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
357 }
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
358
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
359
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
360 /**
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
361 * Tries to parse a line as column titles line
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
362 */
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
363 protected boolean handleMetaColumnTitles(final ImportBedHeight obj, final String line) {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
364 final Matcher m = META_COLUMNTITLES.matcher(line);
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
365 if (m.matches()) {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
366 final Matcher cm;
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
367 final String[] titles = line.split(SEPERATOR_CHAR, 0);
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
368 for (int i = 0; i <= titles.length - 1; i++) {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
369 for (final ColTitlePattern col : ColTitlePattern.values()) {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
370 if (col.getPattern().matcher(titles[i]).matches()) {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
371 this.cols.put(col, i);
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
372 break;
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
373 }
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
374 }
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
375 }
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
376 return true;
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
377 }
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
378 return false;
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
379 }
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
380
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
381 protected void handleDataLine(final ImportBedHeight obj, final String line) {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
382 final String[] values = line.split(SEPERATOR_CHAR, 0);
8681
1f878c82262f (issue1763) Fix filtering of lines when parsing bed heights.
Tom Gottfried <tom@intevation.de>
parents: 8561
diff changeset
383 if (values.length < 2) {
1f878c82262f (issue1763) Fix filtering of lines when parsing bed heights.
Tom Gottfried <tom@intevation.de>
parents: 8561
diff changeset
384 // Do not import line without data or only km
8557
29ab66ce06aa Abstract parser for bed heights is obsolete.
"Tom Gottfried <tom@intevation.de>"
parents: 8556
diff changeset
385 return;
29ab66ce06aa Abstract parser for bed heights is obsolete.
"Tom Gottfried <tom@intevation.de>"
parents: 8556
diff changeset
386 }
29ab66ce06aa Abstract parser for bed heights is obsolete.
"Tom Gottfried <tom@intevation.de>"
parents: 8556
diff changeset
387 Double km;
29ab66ce06aa Abstract parser for bed heights is obsolete.
"Tom Gottfried <tom@intevation.de>"
parents: 8556
diff changeset
388 try {
29ab66ce06aa Abstract parser for bed heights is obsolete.
"Tom Gottfried <tom@intevation.de>"
parents: 8556
diff changeset
389 km = new Double(nf.parse(values[0]).doubleValue());
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
390 if (this.kmExists.contains(km)) {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
391 log.warn("duplicate station '" + values[0] + "': -> ignored");
8557
29ab66ce06aa Abstract parser for bed heights is obsolete.
"Tom Gottfried <tom@intevation.de>"
parents: 8556
diff changeset
392 return;
29ab66ce06aa Abstract parser for bed heights is obsolete.
"Tom Gottfried <tom@intevation.de>"
parents: 8556
diff changeset
393 }
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
394 this.kmExists.add(km);
8557
29ab66ce06aa Abstract parser for bed heights is obsolete.
"Tom Gottfried <tom@intevation.de>"
parents: 8556
diff changeset
395 }
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
396 catch (final ParseException e) {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
397 log.error("Error parsing km '" + values[0] + "': " + e.getMessage());
8557
29ab66ce06aa Abstract parser for bed heights is obsolete.
"Tom Gottfried <tom@intevation.de>"
parents: 8556
diff changeset
398 return;
29ab66ce06aa Abstract parser for bed heights is obsolete.
"Tom Gottfried <tom@intevation.de>"
parents: 8556
diff changeset
399 }
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
400 final ImportBedHeightValue value = new ImportBedHeightValue(obj, km, parse(values, ColTitlePattern.HEIGHT),
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
401 parse(values, ColTitlePattern.UNCERTAINTY), parse(values, ColTitlePattern.GAP), parse(values, ColTitlePattern.WIDTH),
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
402 parse(values, ColTitlePattern.MINHEIGHT), parse(values, ColTitlePattern.MAXHEIGHT));
8557
29ab66ce06aa Abstract parser for bed heights is obsolete.
"Tom Gottfried <tom@intevation.de>"
parents: 8556
diff changeset
403
29ab66ce06aa Abstract parser for bed heights is obsolete.
"Tom Gottfried <tom@intevation.de>"
parents: 8556
diff changeset
404 obj.addValue(value);
29ab66ce06aa Abstract parser for bed heights is obsolete.
"Tom Gottfried <tom@intevation.de>"
parents: 8556
diff changeset
405 }
8975
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
406
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
407 private Double parse(final String[] values, final ColTitlePattern col) {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
408 final int idx = this.cols.get(col).intValue();
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
409 if ((idx >= 0) && (idx < values.length) && !values[idx].trim().isEmpty()) {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
410 try {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
411 return nf.parse(values[idx]).doubleValue();
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
412 }
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
413 catch (final ParseException e) {
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
414 log.warn("unparseable " + col.toString() + " '" + values[idx] + "'");
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
415 }
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
416 }
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
417 return null;
a0a0a7f912ab Added new columns bed_height.comment and sounding_width_info; extended the bed height parser for the new meta data and the min/max_height columns
mschaefer
parents: 8856
diff changeset
418 }
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
419 }

http://dive4elements.wald.intevation.org