changeset 202:29a408f80a89

Finished import of WSTs. flys-backend/trunk@1553 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 23 Mar 2011 16:33:36 +0000
parents 3169b559ca3c
children bfee0e05b4e7
files flys-backend/ChangeLog flys-backend/src/main/java/de/intevation/flys/importer/ImportWstColumn.java flys-backend/src/main/java/de/intevation/flys/importer/ImportWstColumnValue.java flys-backend/src/main/java/de/intevation/flys/importer/WstParser.java flys-backend/src/main/java/de/intevation/flys/model/WstColumnValue.java
diffstat 5 files changed, 116 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/ChangeLog	Wed Mar 23 15:22:32 2011 +0000
+++ b/flys-backend/ChangeLog	Wed Mar 23 16:33:36 2011 +0000
@@ -1,3 +1,28 @@
+2011-03-22	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	Finished import of WSTs.
+
+	TODO 1: Speed it up! It takes on a high end machine over 7(!)
+	        minutes only for the data of the Saar.
+	TODO 2: Double precision floating point representations produced
+	        by the the parsers leed to unique constraint violations
+			in the backend on a second run. So the import is currently
+			only working on freshly initialized data bases.
+			More consequent working with BigDecimal and some
+			rounding may be of help here.
+
+	* src/main/java/de/intevation/flys/model/WstColumnValue.java:
+	  Added convinience constructors.
+
+	* src/main/java/de/intevation/flys/importer/ImportWstColumnValue.java:
+	  Added getPeer() method.
+
+	* src/main/java/de/intevation/flys/importer/ImportWstColumn.java:
+	  Add a list of the ImportWstColumnValues produced by the WST parser.
+
+	* src/main/java/de/intevation/flys/importer/WstParser.java: Add
+	  the (km, w) values to the ImportWstColumns.
+
 2011-03-22	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/importer/WstParser.java:
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportWstColumn.java	Wed Mar 23 15:22:32 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportWstColumn.java	Wed Mar 23 16:33:36 2011 +0000
@@ -10,6 +10,8 @@
 import java.util.List;
 import java.util.ArrayList;
 
+import java.math.BigDecimal;
+
 public class ImportWstColumn
 {
     protected ImportWst wst;
@@ -17,11 +19,13 @@
     protected String    description;
 
     protected List<ImportWstColumnQRange> columnQRanges;
+    protected List<ImportWstColumnValue>  columnValues;
 
     protected WstColumn peer;
 
     public ImportWstColumn() {
         columnQRanges = new ArrayList<ImportWstColumnQRange>();
+        columnValues  = new ArrayList<ImportWstColumnValue>();
     }
 
     public ImportWstColumn(
@@ -59,6 +63,11 @@
         this.description = description;
     }
 
+    public void addColumnValue(BigDecimal position, BigDecimal w) {
+        columnValues.add(
+            new ImportWstColumnValue(this, position, w));
+    }
+
     public void addColumnQRange(ImportWstQRange columnQRange) {
         columnQRanges.add(
             new ImportWstColumnQRange(this, columnQRange));
@@ -69,7 +78,9 @@
         for (ImportWstColumnQRange columnQRange: columnQRanges) {
             columnQRange.getPeer(river);
         }
-        // TODO: Implement me!
+        for (ImportWstColumnValue columnValue: columnValues) {
+            columnValue.getPeer(river);
+        }
     }
 
     public WstColumn getPeer(River river) {
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportWstColumnValue.java	Wed Mar 23 15:22:32 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportWstColumnValue.java	Wed Mar 23 16:33:36 2011 +0000
@@ -1,17 +1,79 @@
 package de.intevation.flys.importer;
 
 import de.intevation.flys.model.WstColumnValue;
+import de.intevation.flys.model.WstColumn;
+import de.intevation.flys.model.River;
+
+import java.math.BigDecimal;
+
+import org.hibernate.Session;
+import org.hibernate.Query;
+
+import java.util.List;
 
 public class ImportWstColumnValue
 {
-    protected WstColumnValue peer;
+    protected BigDecimal      position;
+    protected BigDecimal      w;
+    protected ImportWstColumn wstColumn;
+
+    protected WstColumnValue  peer;
 
     public ImportWstColumnValue() {
     }
 
-    public WstColumnValue getPeer() {
+    public ImportWstColumnValue(
+        ImportWstColumn wstColumn,
+        BigDecimal      position,
+        BigDecimal      w
+    ) {
+        this.wstColumn = wstColumn;
+        this.position  = position;
+        this.w         = w;
+    }
+
+    public BigDecimal getPosition() {
+        return position;
+    }
+
+    public void setPosition(BigDecimal position) {
+        this.position = position;
+    }
+
+    public BigDecimal getW() {
+        return w;
+    }
+
+    public void setW(BigDecimal w) {
+        this.w = w;
+    }
+
+    public ImportWstColumn getWstColumn() {
+        return wstColumn;
+    }
+
+    public void setWstColumn(ImportWstColumn wstColumn) {
+        this.wstColumn = wstColumn;
+    }
+
+    public WstColumnValue getPeer(River river) {
         if (peer == null) {
-            // TODO: Implement me!
+            WstColumn c = wstColumn.getPeer(river);
+            Session session = Importer.sessionHolder.get();
+            Query query = session.createQuery(
+                "from WstColumnValue where " +
+                "wstColumn=:c and position=:p and w=:w");
+            query.setParameter("c", c);
+            query.setParameter("p", position);
+            query.setParameter("w", w);
+            List<WstColumnValue> values = query.list();
+            if (values.isEmpty()) {
+                peer = new WstColumnValue(c, position, w);
+                session.save(peer);
+            }
+            else {
+                peer = values.get(0);
+            }
         }
         return peer;
     }
--- a/flys-backend/src/main/java/de/intevation/flys/importer/WstParser.java	Wed Mar 23 15:22:32 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/WstParser.java	Wed Mar 23 16:33:36 2011 +0000
@@ -290,15 +290,17 @@
     }
 
     protected void addValue(double km, double w, String columnName) {
-        // TODO: store me!
+        ImportWstColumn column = wst.getColumn(columnName);
+        column.addColumnValue(new BigDecimal(km), new BigDecimal(w));
     }
 
     private static final NumberFormat NF = getNumberFormat();
 
-    private static getNumberFormat() {
+    private static final NumberFormat getNumberFormat() {
         NumberFormat nf = NumberFormat.getInstance();
         nf.setMinimumFractionDigits(2);
         nf.setMaximumFractionDigits(2);
+        return nf;
     }
 
     protected static String format(double value) {
--- a/flys-backend/src/main/java/de/intevation/flys/model/WstColumnValue.java	Wed Mar 23 15:22:32 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/model/WstColumnValue.java	Wed Mar 23 16:33:36 2011 +0000
@@ -27,6 +27,16 @@
     public WstColumnValue() {
     }
 
+    public WstColumnValue(
+        WstColumn  wstColumn,
+        BigDecimal position,
+        BigDecimal w
+    ) {
+        this.wstColumn = wstColumn;
+        this.position  = position;
+        this.w         = w;
+    }
+
     @Id
     @SequenceGenerator(
         name           = "SEQUENCE_WST_COLUMN_VALUES_ID_SEQ",

http://dive4elements.wald.intevation.org