changeset 5507:db6c7268b08e

Schema change: add shore offset to sediment density values and be more rigid with input files in parser
author Tom Gottfried <tom.gottfried@intevation.de>
date Thu, 28 Mar 2013 16:41:30 +0100
parents 57f802db5c5a
children c6e552348934
files flys-backend/doc/schema/oracle-minfo.sql flys-backend/doc/schema/postgresql-minfo.sql flys-backend/src/main/java/de/intevation/flys/importer/ImportSedimentDensityValue.java flys-backend/src/main/java/de/intevation/flys/importer/parsers/SedimentDensityParser.java flys-backend/src/main/java/de/intevation/flys/model/SedimentDensityValue.java
diffstat 5 files changed, 36 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/doc/schema/oracle-minfo.sql	Thu Mar 28 15:55:34 2013 +0100
+++ b/flys-backend/doc/schema/oracle-minfo.sql	Thu Mar 28 16:41:30 2013 +0100
@@ -137,6 +137,7 @@
     id                  NUMBER(38,0) NOT NULL,
     sediment_density_id NUMBER(38,0) NOT NULL,
     station             NUMBER(38,2) NOT NULL,
+    shore_offset	NUMBER(38,2),
     density             NUMBER(38,2) NOT NULL,
     description         VARCHAR(256),
     year                NUMBER(38,0),
--- a/flys-backend/doc/schema/postgresql-minfo.sql	Thu Mar 28 15:55:34 2013 +0100
+++ b/flys-backend/doc/schema/postgresql-minfo.sql	Thu Mar 28 16:41:30 2013 +0100
@@ -137,6 +137,7 @@
     id                  int NOT NULL,
     sediment_density_id int NOT NULL,
     station             NUMERIC NOT NULL,
+    shore_offset	NUMERIC,
     density             NUMERIC NOT NULL,
     description         VARCHAR(256),
     year                int,
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportSedimentDensityValue.java	Thu Mar 28 15:55:34 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportSedimentDensityValue.java	Thu Mar 28 16:41:30 2013 +0100
@@ -23,6 +23,8 @@
 
     protected BigDecimal station;
 
+    protected BigDecimal shoreOffset;
+
     protected BigDecimal density;
 
     private BigDecimal year;
@@ -32,11 +34,13 @@
 
     public ImportSedimentDensityValue(
         BigDecimal station,
+        BigDecimal shoreOffset,
         BigDecimal density,
         BigDecimal year,
         String     description
     ) {
         this.station     = station;
+        this.shoreOffset = shoreOffset;
         this.density     = density;
         this.year        = year;
         this.description = description;
@@ -60,12 +64,14 @@
                 "from SedimentDensityValue where " +
                 "   sedimentDensity=:sedimentDensity and " +
                 "   station=:station and " +
+                "   shoreOffset=:shoreOffset and " +
                 "   density=:density and " +
                 "   year=:year and " +
                 "   description=:description");
 
             query.setParameter("sedimentDensity", sedimentDensity);
             query.setParameter("station", station);
+            query.setParameter("shoreOffset", shoreOffset);
             query.setParameter("density", density);
             query.setParameter("year", year);
             query.setParameter("description", description);
@@ -77,6 +83,7 @@
                 peer = new SedimentDensityValue(
                     sedimentDensity,
                     station,
+                    shoreOffset,
                     density,
                     year,
                     description);
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/SedimentDensityParser.java	Thu Mar 28 15:55:34 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/SedimentDensityParser.java	Thu Mar 28 16:41:30 2013 +0100
@@ -85,27 +85,12 @@
         if (handleMetaDepth(line)) {
             return;
         }
-        else if (handleMetaColumns(line)) {
-            return;
-        }
         else {
             log.warn("Unknown meta line: '" + line + "'");
         }
     }
 
 
-    private boolean handleMetaColumns(String line) {
-        String[] columns = line.split(";");
-        for (int i = 0; i < columns.length; i++) {
-            if (columns[i].contains("Sedimentdichte")) {
-                this.densitsyColumn = i;
-                return true;
-            }
-        }
-        return false;
-    }
-
-
     protected boolean handleMetaDepth(String line) {
         Matcher m = META_DEPTH.matcher(line);
 
@@ -145,18 +130,25 @@
             return;
         }
 
-        BigDecimal km;
-        BigDecimal density;
+        BigDecimal km = null;
+        BigDecimal shoreOffset = null;
+        BigDecimal density = null;
         try {
-            km      = new BigDecimal(nf.parse(vals[0]).doubleValue());
-            density = new BigDecimal(nf.parse(vals[this.densitsyColumn]).doubleValue());
-
+            km          = new BigDecimal(nf.parse(vals[0]).doubleValue());
+            density     = new BigDecimal(nf.parse(vals[2]).doubleValue());
+	    if (!vals[1].isEmpty()) {
+		shoreOffset = new BigDecimal(nf.parse(vals[1]).doubleValue());
+	    }
         }
         catch (ParseException pe) {
             log.warn("Unparseable numbers in '" + line + "'");
-            return;
         }
 
+	if (km == null || density == null) {
+	    log.warn("SDP: No km nor density given. Skip line");
+	    return;
+	}
+
         BigDecimal year = null;
         try {
             year =
@@ -176,9 +168,10 @@
 
         current.addValue(new ImportSedimentDensityValue(
             km,
+	    shoreOffset,
             density,
             year,
-            vals[vals.length - 1])
+	    currentDescription)
         );
     }
 
--- a/flys-backend/src/main/java/de/intevation/flys/model/SedimentDensityValue.java	Thu Mar 28 15:55:34 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/model/SedimentDensityValue.java	Thu Mar 28 16:41:30 2013 +0100
@@ -23,6 +23,7 @@
     private SedimentDensity sedimentDensity;
 
     private BigDecimal station;
+    private BigDecimal shoreOffset;
     private BigDecimal density;
     private BigDecimal year;
 
@@ -36,12 +37,14 @@
     public SedimentDensityValue(
         SedimentDensity sedimentDensity,
         BigDecimal      station,
+	BigDecimal      shoreOffset,
         BigDecimal      density,
         BigDecimal      year,
         String          desc
     ) {
         this.sedimentDensity = sedimentDensity;
         this.station         = station;
+	this.shoreOffset     = shoreOffset;
         this.density         = density;
         this.year            = year;
         this.description     = desc;
@@ -83,6 +86,15 @@
         this.station = station;
     }
 
+    @Column(name = "shore_offset")
+    public BigDecimal getShoreOffset() {
+        return shoreOffset;
+    }
+
+    public void setShoreOffset(BigDecimal shoreOffset) {
+        this.shoreOffset = shoreOffset;
+    }
+
     @Column(name = "density")
     public BigDecimal getDensity() {
         return density;

http://dive4elements.wald.intevation.org