annotate backend/src/main/java/org/dive4elements/river/importer/parsers/SQRelationParser.java @ 9650:a2a42a6bac6b

Importer (s/u-info) extensions: outer try/catch for parse and log of line no, catching parsing exception if not enough value fields, parsing error and warning log messages with line number, detecting and rejecting duplicate data series, better differentiation between error and warning log messages
author mschaefer
date Mon, 23 Mar 2020 14:57:03 +0100
parents 5e38e2924c07
children 0a5239a1e46e
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: 5845
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: 5845
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;
3328
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10
3329
cc8fc6b29649 Store sq relations into database after parsing.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3328
diff changeset
11 import java.io.File;
cc8fc6b29649 Store sq relations into database after parsing.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3328
diff changeset
12 import java.io.IOException;
3328
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13 import java.text.NumberFormat;
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14 import java.text.ParseException;
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15 import java.util.ArrayList;
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16 import java.util.List;
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17 import java.util.regex.Matcher;
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18 import java.util.regex.Pattern;
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
19
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20 import org.apache.log4j.Logger;
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
21
8412
17db08570637 SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents: 8187
diff changeset
22 import org.dive4elements.river.model.River;
17db08570637 SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents: 8187
diff changeset
23 import org.dive4elements.river.model.MeasurementStation;
17db08570637 SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents: 8187
diff changeset
24
17db08570637 SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents: 8187
diff changeset
25 import org.dive4elements.river.importer.ImporterSession;
5829
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
26 import org.dive4elements.river.importer.ImportSQRelation;
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
27 import org.dive4elements.river.importer.ImportSQRelationValue;
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
28 import org.dive4elements.river.importer.ImportTimeInterval;
8187
3bb1c62ad732 Moved package org.dive4elements.river.utils to org.dive4elements.river.backend.utils.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 7927
diff changeset
29 import org.dive4elements.river.backend.utils.DateUtil;
3328
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
31
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32 public class SQRelationParser extends LineParser {
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34 private static final Logger log =
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35 Logger.getLogger(SQRelationParser.class);
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
37 private static final Pattern TIMERANGE_REGEX =
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
38 Pattern.compile(".*Zeitraum.*\\s(\\w*)-(\\w*).*");
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40 private static final NumberFormat nf =
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41 NumberFormat.getInstance(DEFAULT_LOCALE);
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
43 private List<ImportSQRelation> relations;
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
45 private ImportSQRelation current;
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46
3329
cc8fc6b29649 Store sq relations into database after parsing.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3328
diff changeset
47 private String currentDescription;
cc8fc6b29649 Store sq relations into database after parsing.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3328
diff changeset
48
8412
17db08570637 SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents: 8187
diff changeset
49 protected River river;
3328
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50
8412
17db08570637 SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents: 8187
diff changeset
51 public SQRelationParser(River river) {
3328
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52 relations = new ArrayList<ImportSQRelation>();
8412
17db08570637 SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents: 8187
diff changeset
53 this.river = river;
3328
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54 }
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
57 public List<ImportSQRelation> getSQRelations() {
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
58 return relations;
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
59 }
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
61 @Override
3329
cc8fc6b29649 Store sq relations into database after parsing.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3328
diff changeset
62 public void parse(File file) throws IOException {
cc8fc6b29649 Store sq relations into database after parsing.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3328
diff changeset
63 this.currentDescription = file.getName();
cc8fc6b29649 Store sq relations into database after parsing.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3328
diff changeset
64 super.parse(file);
cc8fc6b29649 Store sq relations into database after parsing.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3328
diff changeset
65 }
cc8fc6b29649 Store sq relations into database after parsing.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3328
diff changeset
66
cc8fc6b29649 Store sq relations into database after parsing.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3328
diff changeset
67
cc8fc6b29649 Store sq relations into database after parsing.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3328
diff changeset
68 @Override
3328
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69 protected void reset() {
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70 current = new ImportSQRelation();
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71 }
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
72
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
74 @Override
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
75 protected void finish() {
3329
cc8fc6b29649 Store sq relations into database after parsing.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3328
diff changeset
76 if (current != null) {
cc8fc6b29649 Store sq relations into database after parsing.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3328
diff changeset
77 current.setDescription(currentDescription);
cc8fc6b29649 Store sq relations into database after parsing.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3328
diff changeset
78 relations.add(current);
cc8fc6b29649 Store sq relations into database after parsing.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3328
diff changeset
79 }
3328
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
80 }
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
81
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
82
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
83 @Override
4193
f63b39799d2d Adapted DB schema (added relation measurement_station); improved importer to read files from filesystem with measurement stations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3329
diff changeset
84 protected void handleLine(int lineNum, String line) {
3328
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
85 if (line.startsWith(START_META_CHAR)) {
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
86 handleMetaLine(stripMetaLine(line));
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
87 }
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
88 else {
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
89 handleDataLine(line);
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
90 }
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
91 }
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
92
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
93
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
94 protected void handleMetaLine(String line) {
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
95 Matcher m = TIMERANGE_REGEX.matcher(line);
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
96
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
97 if (m.matches()) {
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
98 String lo = m.group(1);
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
99 String hi = m.group(2);
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
100
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
101 log.debug("Found timerange " + lo + " - " + hi);
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
102
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
103 try {
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
104 int low = nf.parse(lo).intValue();
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
105 int high = nf.parse(hi).intValue();
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
106
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
107 current.setTimeInterval(new ImportTimeInterval(
7927
07cc4cd9233e Add new DateUtil class.
"Tom Gottfried <tom@intevation.de>"
parents: 7252
diff changeset
108 DateUtil.getStartDateFromYear(low),
07cc4cd9233e Add new DateUtil class.
"Tom Gottfried <tom@intevation.de>"
parents: 7252
diff changeset
109 DateUtil.getEndDateFromYear(high)
3328
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
110 ));
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
111 }
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
112 catch (ParseException nfe) {
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
113 log.warn("Cannot parse time range.", nfe);
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
114 }
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
115 }
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
116 }
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
117
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
118
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
119 protected void handleDataLine(String line) {
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
120 String[] cols = line.split(SEPERATOR_CHAR);
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
121
8690
11c88a2f695a Handle empty strings as missing values without warning when parsing SQ-relations.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
122 String parameter = cols[1].trim();
11c88a2f695a Handle empty strings as missing values without warning when parsing SQ-relations.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
123 Double km = parseDouble(cols, 3);
11c88a2f695a Handle empty strings as missing values without warning when parsing SQ-relations.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
124 Double a = parseDouble(cols, 6);
11c88a2f695a Handle empty strings as missing values without warning when parsing SQ-relations.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
125 Double b = parseDouble(cols, 7);
11c88a2f695a Handle empty strings as missing values without warning when parsing SQ-relations.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
126 Double qMax = parseDouble(cols, 8);
11c88a2f695a Handle empty strings as missing values without warning when parsing SQ-relations.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
127 Double rSq = parseDouble(cols, 9);
11c88a2f695a Handle empty strings as missing values without warning when parsing SQ-relations.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
128 Integer nTot = parseInteger(cols, 10);
11c88a2f695a Handle empty strings as missing values without warning when parsing SQ-relations.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
129 Integer nOutlier = parseInteger(cols, 11);
11c88a2f695a Handle empty strings as missing values without warning when parsing SQ-relations.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
130 Double cFer = parseDouble(cols, 12);
11c88a2f695a Handle empty strings as missing values without warning when parsing SQ-relations.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
131 Double cDuan = parseDouble(cols, 13);
7252
c894b7b45c4c Replaced some tabs by spaces. Guys, please configure your editors not to insert tabs!
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
132
c894b7b45c4c Replaced some tabs by spaces. Guys, please configure your editors not to insert tabs!
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
133 if (km == null || a == null || b == null
8690
11c88a2f695a Handle empty strings as missing values without warning when parsing SQ-relations.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
134 || qMax == null || parameter.length() == 0
7252
c894b7b45c4c Replaced some tabs by spaces. Guys, please configure your editors not to insert tabs!
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
135 ) {
c894b7b45c4c Replaced some tabs by spaces. Guys, please configure your editors not to insert tabs!
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
136 if (km == null) {
8856
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8692
diff changeset
137 log.error(
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8692
diff changeset
138 "No km for measurement station: "
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8692
diff changeset
139 + "Can not reference measurement station: "
7252
c894b7b45c4c Replaced some tabs by spaces. Guys, please configure your editors not to insert tabs!
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
140 + line);
c894b7b45c4c Replaced some tabs by spaces. Guys, please configure your editors not to insert tabs!
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
141 }
c894b7b45c4c Replaced some tabs by spaces. Guys, please configure your editors not to insert tabs!
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
142 if (a == null || b == null
8690
11c88a2f695a Handle empty strings as missing values without warning when parsing SQ-relations.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
143 || qMax == null || parameter.length() == 0
7252
c894b7b45c4c Replaced some tabs by spaces. Guys, please configure your editors not to insert tabs!
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
144 ) {
8856
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8692
diff changeset
145 log.error(
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8692
diff changeset
146 "Incomplete SQ-relation row "
5e38e2924c07 Fix code style.
Tom Gottfried <tom@intevation.de>
parents: 8692
diff changeset
147 + "(missing a, b, Qmax or parameter): "
7252
c894b7b45c4c Replaced some tabs by spaces. Guys, please configure your editors not to insert tabs!
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
148 + line);
c894b7b45c4c Replaced some tabs by spaces. Guys, please configure your editors not to insert tabs!
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
149 }
c894b7b45c4c Replaced some tabs by spaces. Guys, please configure your editors not to insert tabs!
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5992
diff changeset
150 return;
5429
13596605e81f Added new columns to sq relation importer to import all values from csv and use
Raimund Renkert <rrenkert@intevation.de>
parents: 4193
diff changeset
151 }
8412
17db08570637 SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents: 8187
diff changeset
152
8692
67e53dbe05d2 (issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents: 8690
diff changeset
153 MeasurementStation mStation = ImporterSession.getInstance()
67e53dbe05d2 (issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents: 8690
diff changeset
154 .getMeasurementStation(
67e53dbe05d2 (issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents: 8690
diff changeset
155 river,
67e53dbe05d2 (issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents: 8690
diff changeset
156 km,
67e53dbe05d2 (issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents: 8690
diff changeset
157 parameter.equals("A") || parameter.equals("B")
67e53dbe05d2 (issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents: 8690
diff changeset
158 ? MeasurementStation.MEASUREMENT_TYPE_SUSP
67e53dbe05d2 (issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents: 8690
diff changeset
159 : MeasurementStation.MEASUREMENT_TYPE_BEDLOAD);
8412
17db08570637 SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents: 8187
diff changeset
160
8692
67e53dbe05d2 (issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents: 8690
diff changeset
161 if (mStation == null) {
67e53dbe05d2 (issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents: 8690
diff changeset
162 log.warn("No measurement station fitting parameter " +
67e53dbe05d2 (issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents: 8690
diff changeset
163 parameter + " at km " + km + ". Line ignored.");
67e53dbe05d2 (issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents: 8690
diff changeset
164 return;
8412
17db08570637 SCHEMA CHANGE: removed superfluous columns station and river_id from measurement_stations and adapted other components accordingly.
Tom Gottfried <tom@intevation.de>
parents: 8187
diff changeset
165 }
8692
67e53dbe05d2 (issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents: 8690
diff changeset
166
67e53dbe05d2 (issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents: 8690
diff changeset
167 current.addValue(new ImportSQRelationValue(
67e53dbe05d2 (issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents: 8690
diff changeset
168 parameter,
67e53dbe05d2 (issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents: 8690
diff changeset
169 mStation,
67e53dbe05d2 (issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents: 8690
diff changeset
170 a,
67e53dbe05d2 (issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents: 8690
diff changeset
171 b,
67e53dbe05d2 (issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents: 8690
diff changeset
172 qMax,
67e53dbe05d2 (issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents: 8690
diff changeset
173 rSq,
67e53dbe05d2 (issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents: 8690
diff changeset
174 nTot,
67e53dbe05d2 (issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents: 8690
diff changeset
175 nOutlier,
67e53dbe05d2 (issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents: 8690
diff changeset
176 cFer,
67e53dbe05d2 (issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents: 8690
diff changeset
177 cDuan
67e53dbe05d2 (issue1750) Consistently attach parameters of suspended respectively bedload material to measurement station of respective type.
Tom Gottfried <tom@intevation.de>
parents: 8690
diff changeset
178 ));
5429
13596605e81f Added new columns to sq relation importer to import all values from csv and use
Raimund Renkert <rrenkert@intevation.de>
parents: 4193
diff changeset
179 }
13596605e81f Added new columns to sq relation importer to import all values from csv and use
Raimund Renkert <rrenkert@intevation.de>
parents: 4193
diff changeset
180
8690
11c88a2f695a Handle empty strings as missing values without warning when parsing SQ-relations.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
181 private Double parseDouble(String[] values, int idx) {
11c88a2f695a Handle empty strings as missing values without warning when parsing SQ-relations.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
182 if (idx >= 0 && idx < values.length && !values[idx].isEmpty()) {
11c88a2f695a Handle empty strings as missing values without warning when parsing SQ-relations.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
183 try {
11c88a2f695a Handle empty strings as missing values without warning when parsing SQ-relations.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
184 return nf.parse(values[idx]).doubleValue();
11c88a2f695a Handle empty strings as missing values without warning when parsing SQ-relations.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
185 }
11c88a2f695a Handle empty strings as missing values without warning when parsing SQ-relations.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
186 catch (ParseException e) {
11c88a2f695a Handle empty strings as missing values without warning when parsing SQ-relations.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
187 log.warn("Unparseable value '" + values[idx] + "'");
11c88a2f695a Handle empty strings as missing values without warning when parsing SQ-relations.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
188 }
3328
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
189 }
8690
11c88a2f695a Handle empty strings as missing values without warning when parsing SQ-relations.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
190 return null;
5429
13596605e81f Added new columns to sq relation importer to import all values from csv and use
Raimund Renkert <rrenkert@intevation.de>
parents: 4193
diff changeset
191 }
13596605e81f Added new columns to sq relation importer to import all values from csv and use
Raimund Renkert <rrenkert@intevation.de>
parents: 4193
diff changeset
192
8690
11c88a2f695a Handle empty strings as missing values without warning when parsing SQ-relations.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
193 private Integer parseInteger(String[] values, int idx) {
11c88a2f695a Handle empty strings as missing values without warning when parsing SQ-relations.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
194 if (idx >= 0 && idx < values.length && !values[idx].isEmpty()) {
11c88a2f695a Handle empty strings as missing values without warning when parsing SQ-relations.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
195 try {
11c88a2f695a Handle empty strings as missing values without warning when parsing SQ-relations.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
196 return nf.parse(values[idx]).intValue();
11c88a2f695a Handle empty strings as missing values without warning when parsing SQ-relations.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
197 }
11c88a2f695a Handle empty strings as missing values without warning when parsing SQ-relations.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
198 catch (ParseException e) {
11c88a2f695a Handle empty strings as missing values without warning when parsing SQ-relations.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
199 log.warn("Unparseable value '" + values[idx] + "'");
11c88a2f695a Handle empty strings as missing values without warning when parsing SQ-relations.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
200 }
5429
13596605e81f Added new columns to sq relation importer to import all values from csv and use
Raimund Renkert <rrenkert@intevation.de>
parents: 4193
diff changeset
201 }
8690
11c88a2f695a Handle empty strings as missing values without warning when parsing SQ-relations.
Tom Gottfried <tom@intevation.de>
parents: 8412
diff changeset
202 return null;
3328
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
203 }
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
204 }
a41f279a66e2 Added parser and import classes to import MINFO sq relations.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
205 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org