changeset 8124:2c21fd1ade39

(issue 1448) Use new data model for sedimentloadinfo This probably returns a bit too much of data. So we might need to reduce this later on.
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 25 Aug 2014 12:18:35 +0200
parents 4a2ef6895557
children f01c65261963
files artifacts/src/main/java/org/dive4elements/river/artifacts/services/SedimentLoadInfoService.java
diffstat 1 files changed, 22 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/services/SedimentLoadInfoService.java	Mon Aug 25 12:05:37 2014 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/services/SedimentLoadInfoService.java	Mon Aug 25 12:18:35 2014 +0200
@@ -9,6 +9,7 @@
 package org.dive4elements.river.artifacts.services;
 
 import java.util.Calendar;
+import java.util.Collection;
 
 import org.apache.log4j.Logger;
 import org.w3c.dom.Document;
@@ -18,9 +19,9 @@
 import org.dive4elements.artifacts.CallMeta;
 import org.dive4elements.artifacts.GlobalContext;
 import org.dive4elements.artifacts.common.utils.XMLUtils;
-import org.dive4elements.river.artifacts.model.minfo.SedimentLoadLSData;
-import org.dive4elements.river.artifacts.model.minfo.SedimentLoadFactory;
-
+import org.dive4elements.river.artifacts.model.minfo.SedimentLoadDataFactory;
+import org.dive4elements.river.artifacts.model.minfo.SedimentLoadData;
+import org.dive4elements.river.artifacts.model.minfo.SedimentLoadData.Load;
 
 /** Service delivering info about sediment loads. */
 public class SedimentLoadInfoService
@@ -69,23 +70,28 @@
             return XMLUtils.newDocument();
         }
 
-        SedimentLoadLSData[] loads =
-            SedimentLoadFactory.getLoads(river, type, fromD, toD);
+        /* This call initializes the sedimentloaddata for the river. Might be
+         * expensive but has to be done anyway for the calculation later on. */
+        SedimentLoadData allLoadData = SedimentLoadDataFactory.INSTANCE.getSedimentLoadData(
+                river);
+
+        Collection <Load> loads = allLoadData.findLoads(fromD, toD);
+
         return buildDocument(loads);
     }
 
-    protected Document buildDocument(SedimentLoadLSData[] loads) {
+    protected Document buildDocument(Collection<Load> loads) {
         Document result = XMLUtils.newDocument();
         Element all = result.createElement("sedimentloads");
-        for (SedimentLoadLSData sl : loads) {
-            Element load = result.createElement("sedimentload");
-            load.setAttribute("description", sl.getDescription());
-            if (sl.isEpoch()) {
+        for (Load load : loads) {
+            Element ele = result.createElement("sedimentload");
+            ele.setAttribute("description", load.getDescription());
+            if (load.isEpoch()) {
                 Calendar calendarS = Calendar.getInstance();
-                calendarS.setTime(sl.getStart());
+                calendarS.setTime(load.getStartTime());
                 Calendar calendarE = Calendar.getInstance();
-                calendarE.setTime(sl.getEnd());
-                load.setAttribute(
+                calendarE.setTime(load.getStopTime());
+                ele.setAttribute(
                     "date",
                     calendarS.get(Calendar.YEAR) +
                         " - " +
@@ -93,12 +99,12 @@
             }
             else {
                 Calendar calendar = Calendar.getInstance();
-                calendar.setTime(sl.getStart());
-                load.setAttribute(
+                calendar.setTime(load.getStartTime());
+                ele.setAttribute(
                     "date",
                     String.valueOf(calendar.get(Calendar.YEAR)));
             }
-            all.appendChild(load);
+            all.appendChild(ele);
         }
         result.appendChild(all);
         return result;

http://dive4elements.wald.intevation.org