# HG changeset patch # User Ingo Weinzierl # Date 1334314755 0 # Node ID 70b4a31a3306f120454c08a4c511be2f6b779bc1 # Parent 3febaed762b870829f3a05d595d3bfae25ae3371 Implemented the method stubs of the parser for sediment density and made some db schema adaptions. flys-backend/trunk@4233 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 3febaed762b8 -r 70b4a31a3306 flys-backend/ChangeLog --- a/flys-backend/ChangeLog Fri Apr 13 09:57:37 2012 +0000 +++ b/flys-backend/ChangeLog Fri Apr 13 10:59:15 2012 +0000 @@ -1,3 +1,17 @@ +2012-04-13 Ingo Weinzierl + + * doc/schema/oracle-minfo.sql, + doc/schema/oracle-drop-minfo.sql: Modified the db schema specific to + MINFO; replaced some columns. + + * src/main/java/de/intevation/flys/importer/parsers/SedimentDensityParser.java: + Implemented the method stubs: parse meta data and data values. + + * src/main/java/de/intevation/flys/importer/ImportSedimentDensityValue.java, + src/main/java/de/intevation/flys/importer/ImportSedimentDensity.java: + Added and replaced some instance variables because the db schema has + changed. + 2012-04-13 Ingo Weinzierl * src/main/java/de/intevation/flys/importer/parsers/LineParser.java: New. diff -r 3febaed762b8 -r 70b4a31a3306 flys-backend/doc/schema/oracle-drop-minfo.sql --- a/flys-backend/doc/schema/oracle-drop-minfo.sql Fri Apr 13 09:57:37 2012 +0000 +++ b/flys-backend/doc/schema/oracle-drop-minfo.sql Fri Apr 13 10:59:15 2012 +0000 @@ -14,8 +14,8 @@ ALTER TABLE bed_height_epoch DROP CONSTRAINT fk_epoch_range; ALTER TABLE depths DROP CONSTRAINT fk_depths_unit_id; ALTER TABLE sediment_density DROP CONSTRAINT fk_sd_depth_id; +ALTER TABLE sediment_density DROP CONSTRAINT fk_sd_unit_id; ALTER TABLE sediment_density_values DROP CONSTRAINT fk_sdv_sediment_density_id; -ALTER TABLE sediment_density_values DROP CONSTRAINT fk_sdv_station_id; DROP TABLE bed_height_type; DROP TABLE location_system; diff -r 3febaed762b8 -r 70b4a31a3306 flys-backend/doc/schema/oracle-minfo.sql --- a/flys-backend/doc/schema/oracle-minfo.sql Fri Apr 13 09:57:37 2012 +0000 +++ b/flys-backend/doc/schema/oracle-minfo.sql Fri Apr 13 10:59:15 2012 +0000 @@ -122,9 +122,11 @@ id NUMBER(38,0) NOT NULL, river_id NUMBER(38,0) NOT NULL, depth_id NUMBER(38,0) NOT NULL, + unit_id NUMBER(38,0) NOT NULL, PRIMARY KEY(id), CONSTRAINT fk_sd_river_id FOREIGN KEY (river_id) REFERENCES rivers(id), - CONSTRAINT fk_sd_depth_id FOREIGN KEY (depth_id) REFERENCES depths(id) + CONSTRAINT fk_sd_depth_id FOREIGN KEY (depth_id) REFERENCES depths(id), + CONSTRAINT fk_sd_unit_id FOREIGN KEY (unit_id) REFERENCES units(id) ); @@ -133,10 +135,9 @@ CREATE TABLE sediment_density_values ( id NUMBER(38,0) NOT NULL, sediment_density_id NUMBER(38,0) NOT NULL, - station_id NUMBER(38,0) NOT NULL, + station NUMBER(38,2) NOT NULL, density NUMBER(38,2) NOT NULL, description VARCHAR(256), PRIMARY KEY(id), - CONSTRAINT fk_sdv_sediment_density_id FOREIGN KEY(sediment_density_id) REFERENCES sediment_density(id), - CONSTRAINT fk_sdv_station_id FOREIGN KEY (station_id) REFERENCES ranges(id) + CONSTRAINT fk_sdv_sediment_density_id FOREIGN KEY(sediment_density_id) REFERENCES sediment_density(id) ); diff -r 3febaed762b8 -r 70b4a31a3306 flys-backend/src/main/java/de/intevation/flys/importer/ImportSedimentDensity.java --- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportSedimentDensity.java Fri Apr 13 09:57:37 2012 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportSedimentDensity.java Fri Apr 13 10:59:15 2012 +0000 @@ -18,6 +18,8 @@ protected ImportDepth depth; + protected ImportUnit unit; + protected List values; @@ -31,6 +33,11 @@ } + public void setUnit(ImportUnit unit) { + this.unit = unit; + } + + public void addValue(ImportSedimentDensityValue value) { values.add(value); } diff -r 3febaed762b8 -r 70b4a31a3306 flys-backend/src/main/java/de/intevation/flys/importer/ImportSedimentDensityValue.java --- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportSedimentDensityValue.java Fri Apr 13 09:57:37 2012 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportSedimentDensityValue.java Fri Apr 13 10:59:15 2012 +0000 @@ -16,13 +16,24 @@ protected SedimentDensityValue peer; - protected ImportRange range; + protected BigDecimal station; protected BigDecimal density; protected String description; + public ImportSedimentDensityValue( + BigDecimal station, + BigDecimal density, + String description + ) { + this.station = station; + this.density = density; + this.description = description; + } + + public void storeDependencies(SedimentDensity sedimentDensity) { log.info("store dependencies"); } diff -r 3febaed762b8 -r 70b4a31a3306 flys-backend/src/main/java/de/intevation/flys/importer/parsers/SedimentDensityParser.java --- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/SedimentDensityParser.java Fri Apr 13 09:57:37 2012 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/SedimentDensityParser.java Fri Apr 13 10:59:15 2012 +0000 @@ -1,11 +1,22 @@ package de.intevation.flys.importer.parsers; +import java.math.BigDecimal; + +import java.text.NumberFormat; +import java.text.ParseException; + import java.util.ArrayList; import java.util.List; +import java.util.Locale; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.apache.log4j.Logger; +import de.intevation.flys.importer.ImportDepth; import de.intevation.flys.importer.ImportSedimentDensity; +import de.intevation.flys.importer.ImportSedimentDensityValue; +import de.intevation.flys.importer.ImportUnit; public class SedimentDensityParser extends LineParser { @@ -14,6 +25,16 @@ Logger.getLogger(SedimentDensityParser.class); + public static final NumberFormat nf = NumberFormat.getInstance(DEFAULT_LOCALE); + + + public static final Pattern META_UNIT = + Pattern.compile("^Einheit: \\[(.*)\\].*"); + + public static final Pattern META_DEPTH = + Pattern.compile("^Tiefe: (\\w++)-(\\w++)( (\\w++))?.*"); + + protected List sedimentDensities; protected ImportSedimentDensity current; @@ -40,7 +61,92 @@ @Override protected void handleLine(String line) { - log.debug("handle line: '" + line + "'"); + if (line.startsWith(START_META_CHAR)) { + handleMetaLine(stripMetaLine(line)); + } + else { + handleDataLine(line); + } + } + + + protected void handleMetaLine(String line) { + if (handleMetaUnit(line)) { + return; + } + else if (handleMetaDepth(line)) { + return; + } + else { + log.warn("Unknown meta line: '" + line + "'"); + } + } + + + protected boolean handleMetaUnit(String line) { + Matcher m = META_UNIT.matcher(line); + + if (m.matches()) { + String unit = m.group(1); + + current.setUnit(new ImportUnit(unit)); + + return true; + } + + return false; + } + + + protected boolean handleMetaDepth(String line) { + Matcher m = META_DEPTH.matcher(line); + + if (m.matches()) { + String lo = m.group(1); + String up = m.group(2); + String unit = m.group(4); + + try { + ImportDepth depth = new ImportDepth( + new BigDecimal(nf.parse(lo).doubleValue()), + new BigDecimal(nf.parse(up).doubleValue()), + new ImportUnit(unit) + ); + + current.setDepth(depth); + + return true; + } + catch (ParseException pe) { + log.warn("Error while parsing numbers in: '" + line + "'"); + } + } + + return false; + } + + + protected void handleDataLine(String line) { + String[] vals = line.split(SEPERATOR_CHAR); + + if (vals == null || vals.length < 3) { + log.warn("skip invalid data line: '" + line + "'"); + return; + } + + try { + BigDecimal km = new BigDecimal(nf.parse(vals[0]).doubleValue()); + BigDecimal density = new BigDecimal(nf.parse(vals[1]).doubleValue()); + + current.addValue(new ImportSedimentDensityValue( + km, + density, + vals[2]) + ); + } + catch (ParseException pe) { + log.warn("Error while parsing numbers in '" + line + "'"); + } }