changeset 8229:0bf888783683

(issue1448) Extend SL info service to handle sq_time_intervals
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 08 Sep 2014 16:21:26 +0200
parents 2f63c6c84540
children f54c4b858213
files artifacts/src/main/java/org/dive4elements/river/artifacts/services/SedimentLoadInfoService.java
diffstat 1 files changed, 58 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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);

http://dive4elements.wald.intevation.org