Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightSingleParser.java @ 3955:26685b846a29
Let importer handle gappy single bed height values.
flys-backend/trunk@5612 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Thu, 27 Sep 2012 10:23:23 +0000 |
parents | 0d27d02b1208 |
children | 323063c0f7a0 |
comparison
equal
deleted
inserted
replaced
3954:ffb2aac9a5b6 | 3955:26685b846a29 |
---|---|
1 package de.intevation.flys.importer.parsers; | 1 package de.intevation.flys.importer.parsers; |
2 | |
3 | 2 |
4 import java.math.BigDecimal; | 3 import java.math.BigDecimal; |
5 | 4 |
6 import java.text.ParseException; | 5 import java.text.ParseException; |
7 | |
8 | |
9 | |
10 | 6 |
11 import org.apache.log4j.Logger; | 7 import org.apache.log4j.Logger; |
12 | 8 |
13 import de.intevation.flys.importer.ImportBedHeight; | 9 import de.intevation.flys.importer.ImportBedHeight; |
14 import de.intevation.flys.importer.ImportBedHeightSingle; | 10 import de.intevation.flys.importer.ImportBedHeightSingle; |
27 return new ImportBedHeightSingle(description); | 23 return new ImportBedHeightSingle(description); |
28 } | 24 } |
29 | 25 |
30 | 26 |
31 | 27 |
28 /** | |
29 * Create ImportBedHeightSingleValue from a line of csv file, add | |
30 * it to the ImportBedHeight. | |
31 */ | |
32 @Override | 32 @Override |
33 protected void handleDataLine(ImportBedHeight obj, String line) { | 33 protected void handleDataLine(ImportBedHeight obj, String line) { |
34 String[] values = line.split(SEPERATOR_CHAR); | 34 String[] values = line.split(SEPERATOR_CHAR); |
35 | 35 |
36 if (values == null || values.length < 6) { | 36 if (values == null || (values.length != 1 && values.length < 6)) { |
37 //log.warn("BSP: Error while parsing data line: '" + line + "'"); | 37 //log.warn("BSP: Error while parsing data line: '" + line + "'"); |
38 return; | |
39 } | |
40 | |
41 BigDecimal km; | |
42 | |
43 try { | |
44 km = new BigDecimal(nf.parse(values[0]).doubleValue()); | |
45 } | |
46 catch (ParseException e) { | |
47 // We expect a lot of ";;;;;;" lines. | |
48 //log.warn("BSP: Error while parsing km of data row.", e); | |
49 return; | |
50 } | |
51 | |
52 // Handle gaps like "10,0;;;;;". | |
53 if (values.length == 1) { | |
54 ImportBedHeightSingleValue value = new ImportBedHeightSingleValue( | |
55 (ImportBedHeightSingle) obj, | |
56 km, | |
57 null, null, null, null, null); | |
58 log.debug("Added a gap/null row"); | |
59 obj.addValue(value); | |
60 return; | |
61 } | |
62 | |
63 // Because we cannot enforce consistency of values with complete data | |
64 // via null constraints in the database (as there are "gap" values), | |
65 // do this checks manually. | |
66 if (values[3].length() == 0 || values[4].length() == 0 | |
67 || values[5].length() == 0) { | |
68 //log.warn("BSP: Error while parsing data row (manual null constraint violated)."); | |
38 return; | 69 return; |
39 } | 70 } |
40 | 71 |
41 try { | 72 try { |
42 ImportBedHeightSingleValue value = new ImportBedHeightSingleValue( | 73 ImportBedHeightSingleValue value = new ImportBedHeightSingleValue( |
43 (ImportBedHeightSingle) obj, | 74 (ImportBedHeightSingle) obj, |
44 new BigDecimal(nf.parse(values[0]).doubleValue()), | 75 km, |
45 new BigDecimal(nf.parse(values[1]).doubleValue()), | 76 new BigDecimal(nf.parse(values[1]).doubleValue()), |
46 new BigDecimal(nf.parse(values[2]).doubleValue()), | 77 new BigDecimal(nf.parse(values[2]).doubleValue()), |
47 new BigDecimal(nf.parse(values[3]).doubleValue()), | 78 new BigDecimal(nf.parse(values[3]).doubleValue()), |
48 new BigDecimal(nf.parse(values[4]).doubleValue()), | 79 new BigDecimal(nf.parse(values[4]).doubleValue()), |
49 new BigDecimal(nf.parse(values[5]).doubleValue()) | 80 new BigDecimal(nf.parse(values[5]).doubleValue()) |