changeset 2827:85b25e74594f

Added temp classes used during the import process of flow velocity data. flys-backend/trunk@4244 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 17 Apr 2012 08:50:15 +0000
parents c3f8cf0cdf69
children ac13e466a55e
files flys-backend/ChangeLog flys-backend/src/main/java/de/intevation/flys/importer/ImportDischargeZone.java flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityModel.java flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityModelValue.java flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java
diffstat 5 files changed, 281 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/ChangeLog	Tue Apr 17 06:51:39 2012 +0000
+++ b/flys-backend/ChangeLog	Tue Apr 17 08:50:15 2012 +0000
@@ -1,3 +1,13 @@
+2012-04-17  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/importer/ImportDischargeZone.java,
+	  src/main/java/de/intevation/flys/importer/ImportFlowVelocityModelValue.java,
+	  src/main/java/de/intevation/flys/importer/ImportFlowVelocityModel.java:
+	  Temp classes used during the import process of flow velocity data.
+
+	* src/main/java/de/intevation/flys/importer/ImportRiver.java: Implemented
+	  the method that stores flow velocity model data.
+
 2012-04-17  Ingo Weinzierl <ingo@intevation.de>
 
 	* src/main/java/de/intevation/flys/importer/ImportRiver.java: Prepared for
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportDischargeZone.java	Tue Apr 17 08:50:15 2012 +0000
@@ -0,0 +1,96 @@
+package de.intevation.flys.importer;
+
+import java.math.BigDecimal;
+import java.sql.SQLException;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import org.hibernate.Session;
+import org.hibernate.Query;
+import org.hibernate.exception.ConstraintViolationException;
+
+import de.intevation.flys.model.DischargeZone;
+import de.intevation.flys.model.NamedMainValue;
+import de.intevation.flys.model.River;
+
+
+public class ImportDischargeZone {
+
+    private static final Logger log =
+        Logger.getLogger(ImportDischargeZone.class);
+
+
+    private String gaugeName;
+
+    private ImportNamedMainValue mainValue;
+
+    private BigDecimal lowerFactor;
+
+    private BigDecimal upperFactor;
+
+    private DischargeZone peer;
+
+
+    public ImportDischargeZone(
+        ImportNamedMainValue mainValue,
+        String               gaugeName,
+        BigDecimal           lowerFactor,
+        BigDecimal           upperFactor
+    ) {
+        this.mainValue   = mainValue;
+        this.gaugeName   = gaugeName;
+        this.lowerFactor = lowerFactor;
+        this.upperFactor = upperFactor;
+    }
+
+
+    public void storeDependencies(River river)
+    throws SQLException, ConstraintViolationException
+    {
+        log.debug("store dependencies");
+
+        mainValue.getPeer();
+
+        getPeer(river);
+    }
+
+
+    public DischargeZone getPeer(River river) {
+        if (peer == null) {
+            Session session = ImporterSession.getInstance().getDatabaseSession();
+
+            NamedMainValue namedMainValue = mainValue.getPeer();
+
+            Query query = session.createQuery(
+                "from DischargeZone where " +
+                "   river:=river and " +
+                "   gaugeName=:gaugeName and " +
+                "   mainValue=:mainValue"
+            );
+
+            query.setParameter("river", river);
+            query.setParameter("gaugeName", gaugeName);
+            query.setParameter("mainValue", namedMainValue);
+
+            List<DischargeZone> zone = query.list();
+
+            if (zone.isEmpty()) {
+                peer = new DischargeZone(
+                    gaugeName,
+                    river,
+                    namedMainValue,
+                    lowerFactor,
+                    upperFactor);
+
+                session.save(peer);
+            }
+            else {
+                peer = zone.get(0);
+            }
+        }
+
+        return peer;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityModel.java	Tue Apr 17 08:50:15 2012 +0000
@@ -0,0 +1,85 @@
+package de.intevation.flys.importer;
+
+import java.sql.SQLException;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import org.hibernate.Session;
+import org.hibernate.Query;
+import org.hibernate.exception.ConstraintViolationException;
+
+import de.intevation.flys.model.DischargeZone;
+import de.intevation.flys.model.FlowVelocityModel;
+import de.intevation.flys.model.River;
+
+
+public class ImportFlowVelocityModel {
+
+    private static final Logger log =
+        Logger.getLogger(ImportFlowVelocityModel.class);
+
+
+    private String description;
+
+    private ImportDischargeZone dischargeZone;
+
+    private List<ImportFlowVelocityModelValue> values;
+
+    private FlowVelocityModel peer;
+
+
+    public ImportFlowVelocityModel(
+        ImportDischargeZone dischargeZone,
+        String              description
+    ) {
+        this.dischargeZone = dischargeZone;
+        this.description   = description;
+    }
+
+
+    public void storeDependencies(River river)
+    throws SQLException, ConstraintViolationException
+    {
+        log.debug("store dependencies");
+
+        dischargeZone.storeDependencies(river);
+
+        FlowVelocityModel peer = getPeer(river);
+
+        for (ImportFlowVelocityModelValue value: values) {
+            value.storeDependencies(peer);
+        }
+    }
+
+
+    public FlowVelocityModel getPeer(River river) {
+        if (peer == null) {
+            Session session = ImporterSession.getInstance().getDatabaseSession();
+
+            DischargeZone zone = dischargeZone.getPeer(river);
+
+            Query query = session.createQuery(
+                "from FlowVelocityModel where " +
+                "   river:=river and " +
+                "   dischargeZone=:dischargeZone"
+            );
+
+            query.setParameter("river", river);
+            query.setParameter("dischargeZone", zone);
+
+            List<FlowVelocityModel> model = query.list();
+
+            if (model.isEmpty()) {
+                peer = new FlowVelocityModel(river, zone);
+                session.save(peer);
+            }
+            else {
+                peer = model.get(0);
+            }
+        }
+
+        return peer;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportFlowVelocityModelValue.java	Tue Apr 17 08:50:15 2012 +0000
@@ -0,0 +1,74 @@
+package de.intevation.flys.importer;
+
+import java.math.BigDecimal;
+import java.sql.SQLException;
+import java.util.List;
+
+import org.hibernate.Session;
+import org.hibernate.Query;
+import org.hibernate.exception.ConstraintViolationException;
+
+import de.intevation.flys.model.FlowVelocityModel;
+import de.intevation.flys.model.FlowVelocityModelValue;
+
+
+public class ImportFlowVelocityModelValue {
+
+    private BigDecimal station;
+    private BigDecimal totalChannel;
+    private BigDecimal mainChannel;
+    private BigDecimal shearStress;
+
+    private FlowVelocityModelValue peer;
+
+
+    public ImportFlowVelocityModelValue(
+        BigDecimal station,
+        BigDecimal totalChannel,
+        BigDecimal mainChannel,
+        BigDecimal shearStress
+    ) {
+        this.station      = station;
+        this.totalChannel = totalChannel;
+        this.mainChannel  = mainChannel;
+        this.shearStress  = shearStress;
+    }
+
+
+    public void storeDependencies(FlowVelocityModel model)
+    throws SQLException, ConstraintViolationException
+    {
+        getPeer(model);
+    }
+
+
+    public FlowVelocityModelValue getPeer(FlowVelocityModel model) {
+        if (peer == null) {
+            Session session = ImporterSession.getInstance().getDatabaseSession();
+
+            Query query = session.createQuery(
+                "from FlowVelocityModelValue where " +
+                "   model:=model and " +
+                "   station=:station"
+            );
+
+            query.setParameter("model", model);
+            query.setParameter("station", station);
+
+            List<FlowVelocityModelValue> values = query.list();
+
+            if (values.isEmpty()) {
+                peer = new FlowVelocityModelValue(
+                    model, station, totalChannel, mainChannel, shearStress);
+
+                session.save(peer);
+            }
+            else {
+                peer = values.get(0);
+            }
+        }
+
+        return peer;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java	Tue Apr 17 06:51:39 2012 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java	Tue Apr 17 08:50:15 2012 +0000
@@ -112,6 +112,8 @@
 
     protected List<ImportMorphWidth> morphologicalWidths;
 
+    protected List<ImportFlowVelocityModel> flowVelocityModels;
+
     protected ImportWst wst;
 
     protected ImportUnit wstUnit;
@@ -130,6 +132,7 @@
         floodProtection     = new ArrayList<ImportWst>();
         sedimentDensities   = new ArrayList<ImportSedimentDensity>();
         morphologicalWidths = new ArrayList<ImportMorphWidth>();
+        flowVelocityModels  = new ArrayList<ImportFlowVelocityModel>();
     }
 
     public ImportRiver(
@@ -944,7 +947,19 @@
         if (!Config.INSTANCE.skipFlowVelocity()) {
             log.info("store flow velocity");
 
-            // TODO
+            River river = getPeer();
+
+            for (ImportFlowVelocityModel flowVelocityModel: flowVelocityModels){
+                try {
+                    flowVelocityModel.storeDependencies(river);
+                }
+                catch (SQLException sqle) {
+                    log.error("Error while storing flow velocity model.", sqle);
+                }
+                catch (ConstraintViolationException cve) {
+                    log.error("Error while storing flow velocity model.", cve);
+                }
+            }
         }
     }
 

http://dive4elements.wald.intevation.org