diff backend/src/main/java/org/dive4elements/river/importer/sinfo/importitem/InfrastructureKmLineImport.java @ 8971:50416a0df385

Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
author mschaefer
date Tue, 03 Apr 2018 10:18:30 +0200
parents
children 75bd347147ad
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/backend/src/main/java/org/dive4elements/river/importer/sinfo/importitem/InfrastructureKmLineImport.java	Tue Apr 03 10:18:30 2018 +0200
@@ -0,0 +1,72 @@
+/* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
+ * Software engineering by
+ *  Björnsen Beratende Ingenieure GmbH
+ *  Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
+ *
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+
+package org.dive4elements.river.importer.sinfo.importitem;
+
+import java.util.List;
+
+import org.dive4elements.river.importer.ImportAttribute;
+import org.dive4elements.river.importer.common.AbstractKmLineImport;
+import org.dive4elements.river.model.sinfo.Infrastructure;
+import org.dive4elements.river.model.sinfo.InfrastructureValue;
+import org.hibernate.Query;
+import org.hibernate.Session;
+
+/**
+ * Imported infrastructure of a river station.
+ *
+ * @author Matthias Schäfer
+ *
+ */
+public class InfrastructureKmLineImport extends AbstractKmLineImport<Infrastructure, InfrastructureValue> {
+
+    /***** FIELDS *****/
+
+    private double height;
+
+    private final ImportAttribute bankAttribute;
+
+
+    /***** CONSTRUCTOR *****/
+
+    public InfrastructureKmLineImport(final Double km, final double height, final ImportAttribute bankAttribute) {
+        super(km.doubleValue());
+        this.height = height;
+        this.bankAttribute = bankAttribute;
+    }
+
+
+    /***** METHODS *****/
+
+    public void setHeight(final double height) {
+        this.height = height;
+    }
+
+    @Override
+    protected InfrastructureValue queryValueItem(final Session session, final Infrastructure parent) {
+        final Query query = session.createQuery("FROM InfrastructureValue WHERE (infrastructure=:parent) AND (attribute=:bank)"
+                + " AND (station BETWEEN (:station-0.0001) AND (:station+0.0001))");
+        query.setParameter("parent", parent);
+        query.setParameter("station", this.station);
+        query.setParameter("bank", this.bankAttribute.getPeer());
+        final List rows = query.list();
+        if (!rows.isEmpty())
+            return (InfrastructureValue) rows.get(0);
+        else
+            return null;
+    }
+
+
+    @Override
+    protected InfrastructureValue createValueItem(final Infrastructure parent) {
+        return new InfrastructureValue(parent, this.station, this.bankAttribute.getPeer(), this.height);
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org