[PATCH 4 of 7] (issue1448) Extend SL info service to handle sq_time_intervals

Wald Commits scm-commit at wald.intevation.org
Mon Sep 8 16:25:19 CEST 2014


# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1410186086 -7200
# Node ID 0bf8887836838ee74204acc0bc173064059f48d1
# Parent  2f63c6c845406ca57953b73b0c7a1088c0784a58
(issue1448) Extend SL info service to handle sq_time_intervals

diff -r 2f63c6c84540 -r 0bf888783683 artifacts/src/main/java/org/dive4elements/river/artifacts/services/SedimentLoadInfoService.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/services/SedimentLoadInfoService.java	Mon Sep 08 16:19:15 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/services/SedimentLoadInfoService.java	Mon Sep 08 16:21:26 2014 +0200
@@ -10,6 +10,8 @@
 
 import java.util.Calendar;
 import java.util.Collection;
+import java.util.Iterator;
+import java.util.Date;
 
 import org.apache.log4j.Logger;
 import org.w3c.dom.Document;
@@ -32,6 +34,7 @@
 
     public static final String RIVER_XPATH = "/art:river/text()";
     public static final String TYPE_XPATH = "/art:river/art:type/text()";
+    public static final String SQ_TI_XPATH = "/art:river/art:sq_ti_id/text()";
     public static final String FROM_XPATH = "/art:river/art:location/art:from/text()";
     public static final String TO_XPATH = "/art:river/art:location/art:to/text()";
 
@@ -60,6 +63,10 @@
             data,
             TO_XPATH,
             ArtifactNamespaceContext.INSTANCE);
+        String sq_ti_id = XMLUtils.xpathString(
+            data,
+            SQ_TI_XPATH,
+            ArtifactNamespaceContext.INSTANCE);
         double fromD, toD;
         try {
             fromD = Double.parseDouble(from);
@@ -75,7 +82,30 @@
         SedimentLoadData allLoadData = SedimentLoadDataFactory.INSTANCE.getSedimentLoadData(
                 river);
 
-        Collection <Load> loads = allLoadData.findLoads(fromD, toD);
+        log.debug("Requested type: " + type + " with sq_ti_id: " + sq_ti_id);
+        Collection <Load> loads;
+        if (type.equals("off_epoch")) {
+            /* TODO */
+            loads = null;
+        } else if (type.equals("sq_time_intervals")) {
+            loads = allLoadData.findUniqueTimeIntervalLoads(fromD, toD);
+
+            for (Iterator<Load> it = loads.iterator(); it.hasNext();) {
+                /* Skip loads without time interval for this info type. */
+                if (it.next().getSQRelationTimeIntervalId() == 0) {
+                    it.remove();
+                }
+            }
+        } else {
+            if (!sq_ti_id.isEmpty()) {
+                int id = Integer.parseInt(sq_ti_id);
+                log.debug("Finding only items for id");
+                loads = allLoadData.findLoads(fromD, toD, id);
+            } else {
+                log.debug("Finding everything.");
+                loads = allLoadData.findLoads(fromD, toD);
+            }
+        }
 
         return buildDocument(loads);
     }
@@ -104,6 +134,33 @@
                     "date",
                     String.valueOf(calendar.get(Calendar.YEAR)));
             }
+            /* SQ Time interval */
+            if (load.getSQRelationTimeIntervalId() != 0) {
+                ele.setAttribute("sq_ti_id", String.valueOf(load.getSQRelationTimeIntervalId()));
+                Date start = load.getSQStartTime();
+                Date stop = load.getSQStopTime();
+                if (start != null && stop != null) {
+                    Calendar calendarS = Calendar.getInstance();
+                    calendarS.setTime(start);
+                    Calendar calendarE = Calendar.getInstance();
+                    calendarE.setTime(stop);
+                    ele.setAttribute(
+                        "sq_date",
+                        calendarS.get(Calendar.YEAR) +
+                            " - " +
+                            calendarE.get(Calendar.YEAR));
+                } else if (start != null) {
+                    Calendar calendar = Calendar.getInstance();
+                    calendar.setTime(start);
+                    ele.setAttribute(
+                        "sq_date",
+                        String.valueOf(calendar.get(Calendar.YEAR)));
+                } else {
+                    log.warn("Load: " + load.getSQRelationTimeIntervalId() +
+                            " has no beginning.");
+                }
+            }
+
             all.appendChild(ele);
         }
         result.appendChild(all);


More information about the Dive4Elements-commits mailing list