[PATCH] Added importer models for sediment load and sediment load values

Wald Commits scm-commit at wald.intevation.org
Thu Jul 10 16:57:37 CEST 2014


# HG changeset patch
# User Sascha L. Teichmann <teichmann at intevation.de>
# Date 1405004252 -7200
# Node ID aa054f72e88705d4a728724d29551e8ef72fe869
# Parent  1e327d86c898db96f1ce1063e4e585357639a4ac
Added importer models for sediment load and sediment load values.

diff -r 1e327d86c898 -r aa054f72e887 backend/src/main/java/org/dive4elements/river/importer/ImportMeasurementStation.java
--- a/backend/src/main/java/org/dive4elements/river/importer/ImportMeasurementStation.java	Thu Jul 10 16:11:55 2014 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/ImportMeasurementStation.java	Thu Jul 10 16:57:32 2014 +0200
@@ -58,7 +58,7 @@
         return peer != null;
     }
 
-    public Object getPeer(River river) {
+    public MeasurementStation getPeer(River river) {
         if (peer == null) {
             Gauge gauge = null;
             try {
diff -r 1e327d86c898 -r aa054f72e887 backend/src/main/java/org/dive4elements/river/importer/ImportSedimentLoad.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/backend/src/main/java/org/dive4elements/river/importer/ImportSedimentLoad.java	Thu Jul 10 16:57:32 2014 +0200
@@ -0,0 +1,70 @@
+package org.dive4elements.river.importer;
+
+import java.util.List;
+
+import org.dive4elements.river.model.GrainFraction;
+import org.dive4elements.river.model.SedimentLoad;
+import org.dive4elements.river.model.TimeInterval;
+import org.hibernate.Query;
+import org.hibernate.Session;
+
+public class ImportSedimentLoad
+{
+    private SedimentLoad peer;
+
+    private ImportGrainFraction grainFraction;
+    private ImportTimeInterval  timeInterval;
+    private ImportTimeInterval  sqTimeInterval;
+    private String              description;
+    private Integer             kind;
+
+    public ImportSedimentLoad() {
+    }
+
+    public void storeDependencies() {
+        grainFraction.getPeer();
+        timeInterval.getPeer();
+        sqTimeInterval.getPeer();
+
+        getPeer();
+    }
+
+    public SedimentLoad getPeer() {
+
+        if (peer == null) {
+            Session session = ImporterSession.getInstance().getDatabaseSession();
+            Query query = session.createQuery(
+                "from SedimentLoad where " +
+                "   grainFraction = :grainFraction and " +
+                "   timeInterval = :timeInterval and " +
+                "   sqTimeInterval = :sqTimeInterval and " +
+                "   description = :description and " +
+                "   kind = :kind");
+
+            GrainFraction gf = grainFraction.getPeer();
+            TimeInterval  ti = timeInterval.getPeer();
+
+            TimeInterval sqti = sqTimeInterval != null
+                ? sqTimeInterval.getPeer()
+                : null;
+
+            query.setParameter("grainFraction", gf);
+            query.setParameter("timeInterval", ti);
+            query.setParameter("sqTimeInterval", sqti);
+            query.setParameter("description", description);
+            query.setParameter("kind", kind);
+
+            List<SedimentLoad> loads = query.list();
+            if (loads.isEmpty()) {
+                peer = new SedimentLoad(gf, ti, sqti, description, kind);
+                session.save(peer);
+            }
+            else {
+                peer = loads.get(0);
+            }
+        }
+
+        return peer;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
diff -r 1e327d86c898 -r aa054f72e887 backend/src/main/java/org/dive4elements/river/importer/ImportSedimentLoadValue.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/backend/src/main/java/org/dive4elements/river/importer/ImportSedimentLoadValue.java	Thu Jul 10 16:57:32 2014 +0200
@@ -0,0 +1,69 @@
+package org.dive4elements.river.importer;
+
+import java.util.List;
+
+import org.dive4elements.river.model.MeasurementStation;
+import org.dive4elements.river.model.River;
+import org.dive4elements.river.model.SedimentLoad;
+import org.dive4elements.river.model.SedimentLoadValue;
+import org.hibernate.Query;
+import org.hibernate.Session;
+
+public class ImportSedimentLoadValue {
+
+    private SedimentLoadValue peer;
+
+    private ImportMeasurementStation station;
+    private ImportSedimentLoad       sedimentLoad;
+    private Double                   value;
+
+    public ImportSedimentLoadValue() {
+    }
+
+    public ImportSedimentLoadValue(
+        ImportMeasurementStation station,
+        ImportSedimentLoad       sedimentLoad,
+        Double                   value
+    ) {
+        this.station      = station;
+        this.sedimentLoad = sedimentLoad;
+        this.value        = value;
+    }
+
+    protected SedimentLoadValue getPeer(River river) {
+
+        if (peer == null) {
+            Session session = ImporterSession.getInstance().getDatabaseSession();
+            Query query = session.createQuery(
+                "from SedimentLoadValue where " +
+                "   station = :station and " +
+                "   sedimentLoad = :sedimentLoad and " +
+                "   value = :value");
+
+            MeasurementStation ms = station.getPeer(river);
+            SedimentLoad sl = sedimentLoad.getPeer();
+
+            query.setParameter("station", ms);
+            query.setParameter("sedimentLoad", sl);
+            query.setParameter("value", value);
+
+            List<SedimentLoadValue> values = query.list();
+            if (values.isEmpty()) {
+                peer = new SedimentLoadValue(sl, ms, value);
+                session.save(peer);
+            }
+            else {
+                peer = values.get(0);
+            }
+        }
+
+        return peer;
+    }
+
+    public void storeDependencies(River river) {
+        station.storeDependencies(river);
+        sedimentLoad.storeDependencies();
+        getPeer(river);
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
diff -r 1e327d86c898 -r aa054f72e887 backend/src/main/java/org/dive4elements/river/model/SedimentLoad.java
--- a/backend/src/main/java/org/dive4elements/river/model/SedimentLoad.java	Thu Jul 10 16:11:55 2014 +0200
+++ b/backend/src/main/java/org/dive4elements/river/model/SedimentLoad.java	Thu Jul 10 16:57:32 2014 +0200
@@ -43,6 +43,20 @@
     public SedimentLoad() {
     }
 
+    public SedimentLoad(
+        GrainFraction grainFraction,
+        TimeInterval  timeInterval,
+        TimeInterval  sqTimeInterval,
+        String        description,
+        Integer       kind
+    ) {
+        this.grainFraction  = grainFraction;
+        this.timeInterval   = timeInterval;
+        this.sqTimeInterval = sqTimeInterval;
+        this.description    = description;
+        this.kind           = kind;
+    }
+
     @Id
     @SequenceGenerator(
         name           = "SEQUENCE_SEDIMENT_LOAD_ID_SEQ",
diff -r 1e327d86c898 -r aa054f72e887 backend/src/main/java/org/dive4elements/river/model/SedimentLoadValue.java
--- a/backend/src/main/java/org/dive4elements/river/model/SedimentLoadValue.java	Thu Jul 10 16:11:55 2014 +0200
+++ b/backend/src/main/java/org/dive4elements/river/model/SedimentLoadValue.java	Thu Jul 10 16:57:32 2014 +0200
@@ -35,6 +35,16 @@
     public SedimentLoadValue() {
     }
 
+    public SedimentLoadValue(
+        SedimentLoad       sedimentLoad,
+        MeasurementStation measurementStation,
+        Double             value
+    ) {
+        this.sedimentLoad       = sedimentLoad;
+        this.measurementStation = measurementStation;
+        this.value              = value;
+    }
+
     @Id
     @SequenceGenerator(
         name           = "SEQUENCE_SEDIMENT_LOAD_VALUES_ID_SEQ",


More information about the Dive4Elements-commits mailing list