[PATCH] (issue 1448) Use new data model for sedimentloadinfo

Wald Commits scm-commit at wald.intevation.org
Mon Aug 25 12:18:39 CEST 2014


# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1408961915 -7200
# Node ID 2c21fd1ade39f75992f11b45d7474638039ff526
# Parent  4a2ef6895557ec0eaf52c112cc574afc6c8fdbe8
(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.

diff -r 4a2ef6895557 -r 2c21fd1ade39 artifacts/src/main/java/org/dive4elements/river/artifacts/services/SedimentLoadInfoService.java
--- 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;


More information about the Dive4Elements-commits mailing list