diff backend/src/main/java/org/dive4elements/river/importer/ImportSedimentLoadLS.java @ 8059:bde5f5ec7c72

SCHEMA CHANGE and Importer: get time intervals of SQ-relations from metalines in sediment load files.
author Tom Gottfried <tom@intevation.de>
date Fri, 18 Jul 2014 18:01:49 +0200
parents d86cc6a17b7a
children 5e38e2924c07
line wrap: on
line diff
--- a/backend/src/main/java/org/dive4elements/river/importer/ImportSedimentLoadLS.java	Fri Jul 18 17:43:27 2014 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/ImportSedimentLoadLS.java	Fri Jul 18 18:01:49 2014 +0200
@@ -33,6 +33,8 @@
 
     private ImportTimeInterval timeInterval;
 
+    private ImportTimeInterval sqTimeInterval;
+
     private String description;
 
     private Integer kind;
@@ -50,6 +52,10 @@
         this.timeInterval = timeInterval;
     }
 
+    public void setSQTimeInterval(ImportTimeInterval sqTimeInterval) {
+        this.sqTimeInterval = sqTimeInterval;
+    }
+
     public void setUnit(ImportUnit unit) {
         this.unit = unit;
     }
@@ -92,6 +98,9 @@
         Unit u = unit != null ? unit.getPeer() : null;
 
         TimeInterval ti = timeInterval != null ? timeInterval.getPeer() : null;
+        TimeInterval sqti = sqTimeInterval != null
+                ? sqTimeInterval.getPeer()
+                : null;
 
         if (ti == null || u == null) {
             log.warn("Skip invalid SedimentLoadLS: time interval or unit null!");
@@ -101,23 +110,34 @@
         if (peer == null) {
             Session session = ImporterSession.getInstance()
                 .getDatabaseSession();
+
+            String sqtquery = sqTimeInterval == null ?
+                "sq_time_interval_id is null" :
+                "sqTimeInterval = :sqTimeInterval";
             Query query = session.createQuery("from SedimentLoadLS where "
                 + "   river=:river and "
-                + "   grainFraction=:grainFraction and " + "   unit=:unit and "
+                + "   grainFraction=:grainFraction and "
+                + "   unit=:unit and "
                 + "   timeInterval=:timeInterval and "
-                + "   description=:description");
+                + "   description=:description and "
+                + "   kind = :kind and " +
+                      sqtquery);
 
             query.setParameter("river", river);
             query.setParameter("grainFraction", gf);
             query.setParameter("unit", u);
             query.setParameter("timeInterval", ti);
+            if (sqti != null) {
+                query.setParameter("sqTimeInterval", sqti);
+            }
             query.setParameter("description", description);
+            query.setParameter("kind", kind);
 
             List<SedimentLoadLS> loads = query.list();
             if (loads.isEmpty()) {
                 log.debug("create new SedimentLoadLS");
 
-                peer = new SedimentLoadLS(river, u, ti, gf, description);
+                peer = new SedimentLoadLS(river, u, ti, sqti, gf, description);
                 peer.setKind(this.kind);
                 session.save(peer);
             }

http://dive4elements.wald.intevation.org