comparison backend/src/main/java/org/dive4elements/river/importer/sinfo/parsers/CollisionParser.java @ 9654:8a2a777a8372

Importer (s/u-info) extensions: check and log message for missing values (km, date, waterlevel etc.) and wrong waterlevel unit
author mschaefer
date Mon, 23 Mar 2020 15:10:09 +0100
parents 67a42c9c46a7
children 7c1da1b3f6b8
comparison
equal deleted inserted replaced
9653:3b3c7513472e 9654:8a2a777a8372
49 49
50 private static final Pattern META_YEAR = Pattern.compile("^#\\sJahr:\\s*([12]\\d\\d\\d).*", Pattern.CASE_INSENSITIVE); 50 private static final Pattern META_YEAR = Pattern.compile("^#\\sJahr:\\s*([12]\\d\\d\\d).*", Pattern.CASE_INSENSITIVE);
51 51
52 private enum ColTitlePattern { 52 private enum ColTitlePattern {
53 DATE("Datum.*"), // 53 DATE("Datum.*"), //
54 GAUGE_W("Pegelstand\\s*\\[(.*)\\].*"), // 54 GAUGE_W("Pegelstand\\s*\\[cm\\].*"), //
55 GAUGE_NAME("Bezugspegel.*"), // 55 GAUGE_NAME("Bezugspegel.*"), //
56 TYPE("Unfallart.*"); 56 TYPE("Unfallart.*");
57 57
58 private final Pattern pattern; 58 private final Pattern pattern;
59 59
151 this.cols.put(col, i); 151 this.cols.put(col, i);
152 break; 152 break;
153 } 153 }
154 } 154 }
155 } 155 }
156 if (this.cols.get(ColTitlePattern.DATE) < 0) 156 if (this.cols.get(ColTitlePattern.DATE) < 0) {
157 logWarning("Column of the event dates could not be identified, missing column title 'Datum'"); 157 logLineError("Column of the event dates could not be identified, missing column title 'Datum'");
158 this.headerParsingState = ParsingState.STOP;
159 return true;
160 }
161 if (this.cols.get(ColTitlePattern.GAUGE_W) < 0) {
162 logLineError("Column of the waterlevel could not be identified, missing column title 'Pegelstand [cm]'");
163 this.headerParsingState = ParsingState.STOP;
164 return true;
165 }
166 if (this.cols.get(ColTitlePattern.GAUGE_W) < 0) {
167 logLineError("Column of the reference gauge could not be identified, missing column title 'Bezugspegel'");
168 this.headerParsingState = ParsingState.STOP;
169 return true;
170 }
158 if (this.cols.get(ColTitlePattern.TYPE) < 0) { 171 if (this.cols.get(ColTitlePattern.TYPE) < 0) {
159 logError("Column of the collision types could not be identified, missing column title 'Unfallart'"); 172 logLineError("Column of the collision types could not be identified, missing column title 'Unfallart'");
160 this.headerParsingState = ParsingState.STOP; 173 this.headerParsingState = ParsingState.STOP;
161 return false; 174 return true;
162 } 175 }
163 if (!this.metaPatternsMatched.contains(META_YEAR)) { 176 if (!this.metaPatternsMatched.contains(META_YEAR)) {
164 logError("Required meta info for the year is missing"); 177 logError("Required meta info for the year is missing");
165 this.headerParsingState = ParsingState.STOP; 178 this.headerParsingState = ParsingState.STOP;
179 return true;
166 } 180 }
167 return true; 181 return true;
168 } 182 }
169 183
170 @Override 184 @Override
172 Date eventDate = null; 186 Date eventDate = null;
173 try { 187 try {
174 eventDate = dateFormat.parse(values[this.cols.get(ColTitlePattern.DATE)]); 188 eventDate = dateFormat.parse(values[this.cols.get(ColTitlePattern.DATE)]);
175 } 189 }
176 catch (final Exception e) { 190 catch (final Exception e) {
177 logError("Invalid date in line " + this.in.getLineNumber()); 191 logLineWarning("Invalid or missing date");
178 return null; 192 return null;
179 } 193 }
180 final String typeName = values[this.cols.get(ColTitlePattern.TYPE)].trim(); 194 final String typeName = values[this.cols.get(ColTitlePattern.TYPE)].trim();
181 final String typeKey = typeName.toLowerCase(); 195 final String typeKey = typeName.toLowerCase();
182 CollisionTypeImport type = null; 196 CollisionTypeImport type = null;
185 else { 199 else {
186 type = new CollisionTypeImport(typeName); 200 type = new CollisionTypeImport(typeName);
187 this.types.put(typeKey, type); 201 this.types.put(typeKey, type);
188 } 202 }
189 String gaugeName = null; 203 String gaugeName = null;
190 if (this.cols.get(ColTitlePattern.GAUGE_NAME) >= 0) 204 gaugeName = values[this.cols.get(ColTitlePattern.GAUGE_NAME)].trim();
191 gaugeName = values[this.cols.get(ColTitlePattern.GAUGE_NAME)].trim(); 205 final Number gaugeW = parseDoubleCheckNull(values, this.cols.get(ColTitlePattern.GAUGE_W));
192 double gaugeW = Double.NaN; 206 if ((gaugeW == null) || Double.isNaN(gaugeW.doubleValue())) {
193 if (this.cols.get(ColTitlePattern.GAUGE_W) >= 0) 207 logLineWarning(INVALID_VALUE_ERROR_FORMAT, "waterlevel");
194 gaugeW = parseDoubleWithNull(values[this.cols.get(ColTitlePattern.GAUGE_W)]).doubleValue(); 208 return null;
195 return new CollisionKmLineImport(km, type, eventDate, gaugeName, gaugeW); 209 }
210 return new CollisionKmLineImport(km, type, eventDate, gaugeName, gaugeW.doubleValue());
196 } 211 }
197 } 212 }

http://dive4elements.wald.intevation.org