[Dive4elements-commits] [PATCH] Schema change: add shore offset to sediment density values and be more rigid with input files in parser

Wald Commits scm-commit at wald.intevation.org
Thu Mar 28 16:41:45 CET 2013


# HG changeset patch
# User Tom Gottfried <tom.gottfried at intevation.de>
# Date 1364485290 -3600
# Node ID db6c7268b08ebeb06b1c6b70d2679a8937ddf07e
# Parent  57f802db5c5ab39f2e4116273b6caa660ccaa26c
Schema change: add shore offset to sediment density values and be more rigid with input files in parser

diff -r 57f802db5c5a -r db6c7268b08e flys-backend/doc/schema/oracle-minfo.sql
--- 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),
diff -r 57f802db5c5a -r db6c7268b08e flys-backend/doc/schema/postgresql-minfo.sql
--- 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,
diff -r 57f802db5c5a -r db6c7268b08e flys-backend/src/main/java/de/intevation/flys/importer/ImportSedimentDensityValue.java
--- 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);
diff -r 57f802db5c5a -r db6c7268b08e 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	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)
         );
     }
 
diff -r 57f802db5c5a -r db6c7268b08e flys-backend/src/main/java/de/intevation/flys/model/SedimentDensityValue.java
--- 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;


More information about the Dive4elements-commits mailing list