changeset 2371:fe89d6cf55fb

Added support for official gauge numbers. flys-backend/trunk@3464 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 19 Dec 2011 11:21:25 +0000
parents 7d378970d764
children 027736510a30
files flys-backend/ChangeLog flys-backend/doc/schema/oracle.sql flys-backend/doc/schema/postgresql.sql flys-backend/src/main/java/de/intevation/flys/importer/ImportGauge.java flys-backend/src/main/java/de/intevation/flys/importer/parsers/StaFileParser.java flys-backend/src/main/java/de/intevation/flys/model/Gauge.java
diffstat 6 files changed, 67 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- 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	<sascha.teichmann@intevation.de>:
+
+	* 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 <bjoern.schilberg@intevation.de>:
 
 	* doc/schema/oracle-spatial.sql: Adjust extent of germany to EPSG:31467
--- 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)
--- 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,
--- 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);
             }
--- 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);
 
--- 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<DischargeTable> 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() {

http://dive4elements.wald.intevation.org