changeset 192:f1fce41347ea

Added missing ImportGauge.getPeer() method flys-backend/trunk@1530 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 21 Mar 2011 10:27:14 +0000
parents c4fb5141ce11
children 31c48d54f09d
files flys-backend/ChangeLog flys-backend/src/main/java/de/intevation/flys/importer/ImportGauge.java flys-backend/src/main/java/de/intevation/flys/importer/StaFileParser.java flys-backend/src/main/java/de/intevation/flys/model/Gauge.java
diffstat 4 files changed, 60 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/ChangeLog	Mon Mar 21 10:01:56 2011 +0000
+++ b/flys-backend/ChangeLog	Mon Mar 21 10:27:14 2011 +0000
@@ -1,3 +1,14 @@
+2011-03-21	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/model/Gauge.java:
+	  Added convinience contructor.
+
+	* src/main/java/de/intevation/flys/importer/ImportGauge.java:
+	  Fixed getPeer() method.
+
+	* src/main/java/de/intevation/flys/importer/StaFileParser.java:
+	  Fixed parsing of STA files.
+
 2011-03-21	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/importer/ImportRiver.java,
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportGauge.java	Mon Mar 21 10:01:56 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportGauge.java	Mon Mar 21 10:27:14 2011 +0000
@@ -2,11 +2,16 @@
 
 import java.io.File;
 
+import java.util.List;
+
 import java.math.BigDecimal;
 
 import de.intevation.flys.model.River;
 import de.intevation.flys.model.Gauge;
 
+import org.hibernate.Session;
+import org.hibernate.Query;
+
 import java.io.IOException;
 
 public class ImportGauge
@@ -19,6 +24,7 @@
     protected String      name;
     protected BigDecimal  aeo;
     protected BigDecimal  datum;
+    protected BigDecimal  station;
 
     protected Gauge  peer;
 
@@ -75,17 +81,43 @@
         this.datum = datum;
     }
 
+    public BigDecimal getStation() {
+        return station;
+    }
+
+    public void setStation(BigDecimal station) {
+        this.station = station;
+    }
+
     public void parseDependencies() throws IOException {
         StaFileParser sfp = new StaFileParser();
         sfp.parse(this);
     }
 
     public void storeDependencies(River river) {
+        Gauge gauge = getPeer(river);
         // TODO: Implement me!
     }
 
     public Gauge getPeer(River river) {
         if (peer == null) {
+            Session session = Importer.sessionHolder.get();
+            Query query = session.createQuery(
+                "from Gauge where name=:name " +
+                "and river.id=:id");
+            query.setString("name", name);
+            query.setInteger("id", river.getId());
+            List<Gauge> gauges = query.list();
+            if (gauges.isEmpty()) {
+                peer = new Gauge(
+                    name, river,
+                    station, aeo, datum, 
+                    range.getPeer(river));
+                session.save(peer);
+            }
+            else {
+                peer = gauges.get(0);
+            }
         }
         return peer;
     }
--- a/flys-backend/src/main/java/de/intevation/flys/importer/StaFileParser.java	Mon Mar 21 10:01:56 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/StaFileParser.java	Mon Mar 21 10:27:14 2011 +0000
@@ -80,7 +80,7 @@
             }
 
             try {
-                gauge.setDatum(
+                gauge.setStation(
                     new BigDecimal(line.substring(29, 36).trim()));
             }
             catch (NumberFormatException nfe) {
--- a/flys-backend/src/main/java/de/intevation/flys/model/Gauge.java	Mon Mar 21 10:01:56 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/model/Gauge.java	Mon Mar 21 10:27:14 2011 +0000
@@ -30,6 +30,22 @@
     public Gauge() {
     }
 
+    public Gauge(
+        String     name,
+        River      river,
+        BigDecimal station,
+        BigDecimal aeo,
+        BigDecimal datum,
+        Range      range
+    ) {
+        this.name    = name;
+        this.river   = river;
+        this.station = station;
+        this.aeo     = aeo;
+        this.datum   = datum;
+        this.range   = range;
+    }
+
     @Id
     @SequenceGenerator(
         name           = "SEQUENCE_GAUGES_ID_SEQ",

http://dive4elements.wald.intevation.org