# HG changeset patch # User Sascha L. Teichmann # Date 1324293685 0 # Node ID fe89d6cf55fb89c9dd665c4a22d9044cd9df5646 # Parent 7d378970d76487f8eb98bedbef09a2419658a56e Added support for official gauge numbers. flys-backend/trunk@3464 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 7d378970d764 -r fe89d6cf55fb flys-backend/ChangeLog --- a/flys-backend/ChangeLog Wed Nov 30 12:14:41 2011 +0000 +++ b/flys-backend/ChangeLog Mon Dec 19 11:21:25 2011 +0000 @@ -1,3 +1,17 @@ +2011-12-19 Sascha L. Teichmann : + + * src/main/java/de/intevation/flys/importer/parsers/StaFileParser.java: + Parse the official 'Pegelnummer' out of the STA files, too. + + * src/main/java/de/intevation/flys/importer/ImportGauge.java: + Adjusted import model. + + * src/main/java/de/intevation/flys/model/Gauge.java: Make the + official gauge number accessible via Hibernate. + + * doc/schema/postgresql.sql, doc/schema/oracle.sql: Added + an official_number to the gauges table. + 2011-11-30 Bjoern Schilberg : * doc/schema/oracle-spatial.sql: Adjust extent of germany to EPSG:31467 diff -r 7d378970d764 -r fe89d6cf55fb flys-backend/doc/schema/oracle.sql --- a/flys-backend/doc/schema/oracle.sql Wed Nov 30 12:14:41 2011 +0000 +++ b/flys-backend/doc/schema/oracle.sql Mon Dec 19 11:21:25 2011 +0000 @@ -113,6 +113,7 @@ datum NUMBER(38,2), name VARCHAR2(255), station NUMBER(38,2), + official_number NUMBER(38,0), range_id NUMBER(38,0), river_id NUMBER(38,0), PRIMARY KEY (id) diff -r 7d378970d764 -r fe89d6cf55fb flys-backend/doc/schema/postgresql.sql --- a/flys-backend/doc/schema/postgresql.sql Wed Nov 30 12:14:41 2011 +0000 +++ b/flys-backend/doc/schema/postgresql.sql Mon Dec 19 11:21:25 2011 +0000 @@ -78,11 +78,12 @@ CREATE SEQUENCE GAUGES_ID_SEQ; CREATE TABLE gauges ( - id int PRIMARY KEY NOT NULL, - name VARCHAR(256) NOT NULL, - river_id int NOT NULL REFERENCES rivers(id), - station NUMERIC NOT NULL UNIQUE, - aeo NUMERIC NOT NULL, + id int PRIMARY KEY NOT NULL, + name VARCHAR(256) NOT NULL, + river_id int NOT NULL REFERENCES rivers(id), + station NUMERIC NOT NULL UNIQUE, + aeo NUMERIC NOT NULL, + official_number int8 UNIQUE, -- Pegelnullpunkt datum NUMERIC NOT NULL, diff -r 7d378970d764 -r fe89d6cf55fb flys-backend/src/main/java/de/intevation/flys/importer/ImportGauge.java --- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportGauge.java Wed Nov 30 12:14:41 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportGauge.java Mon Dec 19 11:21:25 2011 +0000 @@ -38,6 +38,7 @@ protected BigDecimal aeo; protected BigDecimal datum; protected BigDecimal station; + protected Long officialNumber; protected Gauge peer; @@ -111,6 +112,14 @@ this.station = station; } + public Long getOfficialNumber() { + return officialNumber; + } + + public void setOfficialNumber(Long officialNumber) { + this.officialNumber = officialNumber; + } + public ImportDischargeTable getDischargeTable() { return dischargeTable; } @@ -245,6 +254,7 @@ peer = new Gauge( name, river, station, aeo, datum, + officialNumber, range.getPeer(river)); session.save(peer); } diff -r 7d378970d764 -r fe89d6cf55fb flys-backend/src/main/java/de/intevation/flys/importer/parsers/StaFileParser.java --- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/StaFileParser.java Wed Nov 30 12:14:41 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/StaFileParser.java Mon Dec 19 11:21:25 2011 +0000 @@ -60,8 +60,25 @@ log.warn("first line in STA file is too short."); return false; } + String gaugeNumberString = line.substring( 0, 16).trim(); + String gaugeName = line.substring(16, 37).trim(); - gauge.setName(line.substring(16, 37).trim()); + Long gaugeNumber = null; + try { + gaugeNumber = Long.parseLong(gaugeNumberString); + } + catch (NumberFormatException nfe) { + log.warn("'" + gaugeNumberString + + "' is not a valid long number."); + } + + gauge.setName(gaugeName); + gauge.setOfficialNumber(gaugeNumber); + + if (log.isDebugEnabled()) { + log.debug( + "name/number: '" + gaugeName + "' '" + gaugeNumber + "'"); + } String [] values = line.substring(38).trim().split("\\s+", 2); diff -r 7d378970d764 -r fe89d6cf55fb flys-backend/src/main/java/de/intevation/flys/model/Gauge.java --- a/flys-backend/src/main/java/de/intevation/flys/model/Gauge.java Wed Nov 30 12:14:41 2011 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/model/Gauge.java Mon Dec 19 11:21:25 2011 +0000 @@ -36,6 +36,7 @@ private BigDecimal station; private BigDecimal aeo; private BigDecimal datum; + private Long officialNumber; private Range range; private List dischargeTables; @@ -52,14 +53,16 @@ BigDecimal station, BigDecimal aeo, BigDecimal datum, + Long officialNumber, Range range ) { - this.name = name; - this.river = river; - this.station = station; - this.aeo = aeo; - this.datum = datum; - this.range = range; + this.name = name; + this.river = river; + this.station = station; + this.aeo = aeo; + this.datum = datum; + this.officialNumber = officialNumber; + this.range = range; } @Id @@ -125,6 +128,15 @@ this.datum = datum; } + @Column(name = "official_number") + public Long getOfficialNumber() { + return officialNumber; + } + + public void setOfficialNumber(Long officialNumber) { + this.officialNumber = officialNumber; + } + @OneToOne @JoinColumn(name = "range_id" ) public Range getRange() {