annotate backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightParser.java @ 8989:2693bfaf503d

Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
author mschaefer
date Mon, 09 Apr 2018 09:07:00 +0200
parents a0a0a7f912ab
children 8aa7d9eaaa21
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;
8989
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8975
diff changeset
40 import org.dive4elements.river.importer.common.AbstractParser;
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
41 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
42
8557
29ab66ce06aa Abstract parser for bed heights is obsolete.
"Tom Gottfried <tom@intevation.de>"
parents: 8556
diff changeset
43 public class BedHeightParser {
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
45 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
46 Logger.getLogger(BedHeightParser.class);
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48 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
49
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50 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
51
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52 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
53 public static final String SEPERATOR_CHAR = ";";
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55 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
56 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
57
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
58 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
59 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
60
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
61 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
62 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
63
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64 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
65 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
66
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
67 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
68 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
69
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70 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
71 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
72
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73 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
74 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
75
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
76 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
77 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
78
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
79 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
80
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
81 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
82 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
83
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
84 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
85
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
86 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
87 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
88 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
89 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
90 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
91 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
92 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
93 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
94
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 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
96
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 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
98 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
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
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 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
102 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
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
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 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
107
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
108 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
109
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
110
8559
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents: 8557
diff changeset
111 protected List<ImportBedHeight> bedHeights;
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
112
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
113
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
114 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
115 return new ImportBedHeight(description);
8557
29ab66ce06aa Abstract parser for bed heights is obsolete.
"Tom Gottfried <tom@intevation.de>"
parents: 8556
diff changeset
116 }
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
117
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
118
6273
e7526a074c0d Bed height parser: check for duplicate stations
Tom Gottfried <tom.gottfried@intevation.de>
parents: 6236
diff changeset
119 protected TreeSet<Double> kmExists;
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
120
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
121 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
122 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
123 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
124 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
125
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
126
8559
6d8d7425a6b5 Bed heights are just bed heights since a while ('single' is obsolete).
"Tom Gottfried <tom@intevation.de>"
parents: 8557
diff changeset
127 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
128 return this.bedHeights;
2811
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
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
131
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
132 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
133 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
134 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
135 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
136 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
137 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
138 this.cols.put(col, -1);
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
139 LineNumberReader in = null;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
140 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
141 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
142
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
143 String line = null;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
144 while ((line = in.readLine()) != null) {
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
145 if ((line = line.trim()).length() == 0) {
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
146 continue;
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
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
149 if (line.startsWith(START_META_CHAR)) {
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
150 handleMetaLine(obj, line);
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
151 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
152 else {
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
153 handleDataLine(obj, line);
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
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
157 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
158 this.bedHeights.add(obj);
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
159 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
160 finally {
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
161 if (in != null) {
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
162 in.close();
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
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
167
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
168 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
169 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
170
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
171 if (tmp.startsWith(" ")) {
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
172 return tmp.substring(1, tmp.length());
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
173 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
174 else {
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
175 return tmp;
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
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
179
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
180 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
181 final String meta = stripMetaLine(line);
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
182
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
183 if (handleMetaYear(obj, meta)) {
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
184 return;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
185 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
186 else if (handleMetaTimeInterval(obj, meta)) {
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
187 return;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
188 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
189 else if (handleMetaComment(obj, meta)) {
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
190 return;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
191 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
192 else if (handleMetaEvaluationBy(obj, meta)) {
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
193 return;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
194 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
195 else if (handleMetaRange(obj, meta)) {
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
196 return;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
197 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
198 else if (handleMetaType(obj, meta)) {
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
199 return;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
200 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
201 else if (handleMetaLocationSystem(obj, meta)) {
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
202 return;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
203 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
204 else if (handleMetaCurElevationModel(obj, meta)) {
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
205 return;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
206 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
207 else if (handleMetaOldElevationModel(obj, meta)) {
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
208 return;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
209 }
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
210 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
211 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
212 }
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 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
214 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
215 }
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
216 else {
3662
0d27d02b1208 backend: Completed the error messages of the importer.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2811
diff changeset
217 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
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
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
221
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
222 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
223 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
224 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
225 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
226 if (tmp.length() > 0) {
5376aa576604 Allow empty years in bed height parser.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5278
diff changeset
227 obj.setYear(Integer.parseInt(tmp));
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
228 }
5327
5376aa576604 Allow empty years in bed height parser.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5278
diff changeset
229 else {
5376aa576604 Allow empty years in bed height parser.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5278
diff changeset
230 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
231 }
5327
5376aa576604 Allow empty years in bed height parser.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5278
diff changeset
232 return true;
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
233 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
234 return false;
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
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
237
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
238 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
239 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
240 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
241 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
242 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
243 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
244 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
245 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
246 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
247 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
248 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
249 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
250 }
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 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
252 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
253 }
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
254 return true;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
255 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
256 return false;
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
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
259
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
260 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
261 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
262 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
263 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
264 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
265 return true;
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
266 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
267 return false;
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
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
270
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
271 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
272 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
273 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
274 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
275 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
276 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
277 }
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 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
279 }
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
280
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
281
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
282 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
283 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
284 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
285 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
286 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
287 try {
8989
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8975
diff changeset
288 final BigDecimal lower = AbstractParser.parseDecimal(a);
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8975
diff changeset
289 final BigDecimal upper = AbstractParser.parseDecimal(b);
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
290 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
291 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
292 }
8989
2693bfaf503d Fixed several BigDecimal(double) creations by BigDecimal(String) parsing to avoid unnecessary decimal digits
mschaefer
parents: 8975
diff changeset
293 catch (final Exception e) {
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
294 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
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 }
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 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
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
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 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
302 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
303 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
304 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
305 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
306 if (bht != null) {
db196abd16ca Use lookup table from bedd_height from database in importer.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3960
diff changeset
307 obj.setType(new ImportBedHeightType(bht));
3798
90f91ba077a8 Made importer more robust
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3662
diff changeset
308 return true;
90f91ba077a8 Made importer more robust
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3662
diff changeset
309 }
5901
92bc0aa3831d BHP: more informative error instead of warning if file can not be imported.
Tom Gottfried <tom@intevation.de>
parents: 5845
diff changeset
310 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
311 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
312 return false;
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
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
315
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
316 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
317 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
318 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
319 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
320 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
321 return true;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
322 }
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
323 return false;
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
324 }
8557
29ab66ce06aa Abstract parser for bed heights is obsolete.
"Tom Gottfried <tom@intevation.de>"
parents: 8556
diff changeset
325
8689
ea676691e533 (issue1763) Reduce code-duplication (patch by Sascha Teichmann).
Tom Gottfried <tom@intevation.de>
parents: 8688
diff changeset
326
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
327 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
328 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
329 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
330 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
331 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
332 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
333 return true;
8689
ea676691e533 (issue1763) Reduce code-duplication (patch by Sascha Teichmann).
Tom Gottfried <tom@intevation.de>
parents: 8688
diff changeset
334 }
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
335 return false;
8689
ea676691e533 (issue1763) Reduce code-duplication (patch by Sascha Teichmann).
Tom Gottfried <tom@intevation.de>
parents: 8688
diff changeset
336 }
ea676691e533 (issue1763) Reduce code-duplication (patch by Sascha Teichmann).
Tom Gottfried <tom@intevation.de>
parents: 8688
diff changeset
337
8557
29ab66ce06aa Abstract parser for bed heights is obsolete.
"Tom Gottfried <tom@intevation.de>"
parents: 8556
diff changeset
338
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
339 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
340 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
341 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
342 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
343 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
344 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
345 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
346 }
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 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
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
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 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
351 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
352 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
353 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
354 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
355 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
356 }
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 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
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 /**
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 * 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
363 */
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 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
365 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
366 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
367 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
368 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
369 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
370 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
371 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
372 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
373 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
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 }
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 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
378 }
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 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
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
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 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
383 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
384 if (values.length < 2) {
1f878c82262f (issue1763) Fix filtering of lines when parsing bed heights.
Tom Gottfried <tom@intevation.de>
parents: 8561
diff changeset
385 // 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
386 return;
29ab66ce06aa Abstract parser for bed heights is obsolete.
"Tom Gottfried <tom@intevation.de>"
parents: 8556
diff changeset
387 }
29ab66ce06aa Abstract parser for bed heights is obsolete.
"Tom Gottfried <tom@intevation.de>"
parents: 8556
diff changeset
388 Double km;
29ab66ce06aa Abstract parser for bed heights is obsolete.
"Tom Gottfried <tom@intevation.de>"
parents: 8556
diff changeset
389 try {
29ab66ce06aa Abstract parser for bed heights is obsolete.
"Tom Gottfried <tom@intevation.de>"
parents: 8556
diff changeset
390 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
391 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
392 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
393 return;
29ab66ce06aa Abstract parser for bed heights is obsolete.
"Tom Gottfried <tom@intevation.de>"
parents: 8556
diff changeset
394 }
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
395 this.kmExists.add(km);
8557
29ab66ce06aa Abstract parser for bed heights is obsolete.
"Tom Gottfried <tom@intevation.de>"
parents: 8556
diff changeset
396 }
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
397 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
398 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
399 return;
29ab66ce06aa Abstract parser for bed heights is obsolete.
"Tom Gottfried <tom@intevation.de>"
parents: 8556
diff changeset
400 }
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
401 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
402 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
403 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
404
29ab66ce06aa Abstract parser for bed heights is obsolete.
"Tom Gottfried <tom@intevation.de>"
parents: 8556
diff changeset
405 obj.addValue(value);
29ab66ce06aa Abstract parser for bed heights is obsolete.
"Tom Gottfried <tom@intevation.de>"
parents: 8556
diff changeset
406 }
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
407
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 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
409 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
410 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
411 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
412 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
413 }
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 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
415 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
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 }
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 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
419 }
2811
8926571e47fb Finished importing MINFO bed heights (single and epoch).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
420 }

http://dive4elements.wald.intevation.org