changeset 7466:5cddf115b27b

Merged
author Sascha L. Teichmann <teichmann@intevation.de>
date Wed, 30 Oct 2013 11:59:09 +0100
parents 4b29bb2c785f (diff) 5b5a2cc8210f (current diff)
children 6878708ac1ab
files
diffstat 7 files changed, 83 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/CollectionMonitor.java	Tue Oct 29 19:59:59 2013 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/CollectionMonitor.java	Wed Oct 30 11:59:09 2013 +0100
@@ -12,18 +12,16 @@
 import java.util.List;
 import java.util.Map;
 
-import javax.xml.xpath.XPathConstants;
-
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 
 import org.dive4elements.artifacts.Artifact;
 import org.dive4elements.artifacts.ArtifactNamespaceContext;
 import org.dive4elements.artifacts.CallContext;
 import org.dive4elements.artifacts.Hook;
 
-import org.dive4elements.artifacts.common.utils.XMLUtils;
 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator;
 
 import org.dive4elements.artifactdatabase.state.Output;
@@ -33,9 +31,6 @@
 /** Monitors collection changes. */
 public class CollectionMonitor implements Hook {
 
-    public static final String XPATH_RESULT = "/art:result";
-
-
     @Override
     public void setup(Node cfg) {
     }
@@ -51,11 +46,14 @@
             return;
         }
 
-        Element result = (Element) XMLUtils.xpath(
-            doc,
-            XPATH_RESULT,
-            XPathConstants.NODE,
-            ArtifactNamespaceContext.INSTANCE);
+        NodeList results = doc.getElementsByTagNameNS(
+            ArtifactNamespaceContext.NAMESPACE_URI, "result");
+
+        if (results.getLength() < 1) {
+            return;
+        }
+
+        Element result = (Element)results.item(0);
 
         ElementCreator creator = new ElementCreator(
             doc,
@@ -63,7 +61,6 @@
             ArtifactNamespaceContext.NAMESPACE_PREFIX);
 
         Element recommended = creator.create("recommended-artifacts");
-        result.appendChild(recommended);
 
         String[] outs              = extractOutputNames(flys, context);
         Map<String, Object> params = getNoneUserSpecificParameters(flys, context);
@@ -73,6 +70,8 @@
         // TODO For newer official-lines recommendations we actually
         // need user-id (null here).
         rec.recommend(flys, null, outs, params, recommended);
+
+        result.appendChild(recommended);
     }
 
 
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentDensity.java	Tue Oct 29 19:59:59 2013 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentDensity.java	Wed Oct 30 11:59:09 2013 +0100
@@ -77,20 +77,26 @@
     }
 
     public void addDensity(double km, double density, int year) {
+
         logger.debug("adding " + year);
-        if (this.densities.containsKey(year)) {
-            List<SedimentDensityValue> list = this.densities.get(year);
-            list.add(new SedimentDensityValue(km, density, year));
+
+        Integer key = Integer.valueOf(year);
+
+        List<SedimentDensityValue> list = densities.get(key);
+
+        if (list == null) {
+            list = new ArrayList<SedimentDensityValue>();
+            densities.put(key, list);
         }
-        else {
-            List<SedimentDensityValue> list =
-                new ArrayList<SedimentDensityValue>();
-            list.add(new SedimentDensityValue(km, density, year));
-            densities.put(year, list);
-        }
-        if (!this.years.contains(new Integer(year))) {
+
+        list.add(new SedimentDensityValue(km, density, year));
+
+        // XXX: Why do we store a redundant list of years, too?
+        // Years are the keys of densities so they can be easily
+        // accessed by their key set!
+        if (!years.contains(key)) {
             logger.debug("new year");
-            years.add(new Integer(year));
+            years.add(key);
         }
     }
 
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadCalculation.java	Tue Oct 29 19:59:59 2013 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/minfo/SedimentLoadCalculation.java	Wed Oct 30 11:59:09 2013 +0100
@@ -522,7 +522,7 @@
             SedimentDensityFactory.getSedimentDensity(river, kmLow, kmUp, year);
 
         for (double km: load.getKms()) {
-            double dens = density.getDensity(km, year);
+            double dens = 1d/density.getDensity(km, year);
             SedimentLoadFraction fraction = load.getFraction(km);
             double coarse = fraction.getCoarse();
             double fineMiddle = fraction.getFineMiddle();
--- a/gwt-client/src/main/java/org/dive4elements/river/client/server/MetaDataServiceImpl.java	Tue Oct 29 19:59:59 2013 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/server/MetaDataServiceImpl.java	Wed Oct 30 11:59:09 2013 +0100
@@ -28,6 +28,8 @@
 import org.dive4elements.artifacts.httpclient.http.HttpClient;
 import org.dive4elements.artifacts.httpclient.http.HttpClientImpl;
 
+import org.dive4elements.river.client.shared.model.AttrList;
+import org.dive4elements.river.client.shared.model.DataCageNode;
 import org.dive4elements.river.client.shared.model.DataCageTree;
 
 import org.dive4elements.river.client.server.meta.Converter;
@@ -38,7 +40,7 @@
  */
 public class MetaDataServiceImpl
 extends      RemoteServiceServlet
-implements   MetaDataService
+implements   MetaDataService, DataCageTree.Visitor
 {
     /** Our very own logger. */
     private static final Logger logger =
@@ -48,6 +50,12 @@
         "error_no_meta_data_found";
 
 
+    @Override
+    public boolean accept(DataCageNode node) {
+        AttrList al = node.getAttributes();
+        return al != null && al.hasAttribute("factory");
+    }
+
     /**
      * @param locale needed for i18n.
      * @param artifactId ID of masterartifact (can be null)
@@ -109,7 +117,9 @@
 
         try {
             Converter converter = new Converter();
-            return converter.convert(client.callService(url, "metadata", doc));
+            DataCageTree tree = converter.convert(client.callService(url, "metadata", doc));
+            tree.prune(this);
+            return tree;
         }
         catch (ConnectionException ce) {
             ce.printStackTrace();
--- a/gwt-client/src/main/java/org/dive4elements/river/client/shared/model/AttrList.java	Tue Oct 29 19:59:59 2013 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/shared/model/AttrList.java	Wed Oct 30 11:59:09 2013 +0100
@@ -41,5 +41,14 @@
         keyValues.add(key);
         keyValues.add(value);
     }
+
+    public boolean hasAttribute(String key) {
+        for (int i = 0, N = keyValues.size(); i < N; i += 2) {
+            if (keyValues.get(i).equals(key)) {
+                return true;
+            }
+        }
+        return false;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/gwt-client/src/main/java/org/dive4elements/river/client/shared/model/DataCageNode.java	Tue Oct 29 19:59:59 2013 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/shared/model/DataCageNode.java	Wed Oct 30 11:59:09 2013 +0100
@@ -63,5 +63,9 @@
     public AttrList getAttributes() {
         return attrs;
     }
+
+    public boolean hasChildren() {
+        return children != null && !children.isEmpty();
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/gwt-client/src/main/java/org/dive4elements/river/client/shared/model/DataCageTree.java	Tue Oct 29 19:59:59 2013 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/shared/model/DataCageTree.java	Wed Oct 30 11:59:09 2013 +0100
@@ -9,9 +9,15 @@
 package org.dive4elements.river.client.shared.model;
 
 import java.io.Serializable;
+import java.util.List;
 
 public class DataCageTree implements Serializable
 {
+
+    public interface Visitor {
+        boolean accept(DataCageNode node);
+    } // interface
+
     protected DataCageNode root;
 
     public DataCageTree() {
@@ -28,5 +34,28 @@
     public DataCageNode getRoot() {
         return root;
     }
+
+
+    protected boolean recursivePrune(DataCageNode node, Visitor visitor) {
+        if (!node.hasChildren()) {
+            return visitor.accept(node);
+        }
+
+        List<DataCageNode> children = node.getChildren();
+
+        for (int i = children.size()-1; i >= 0; --i) {
+            if (!recursivePrune(children.get(i), visitor)) {
+                children.remove(i);
+            }
+        }
+
+        return !children.isEmpty();
+    }
+
+    public boolean prune(Visitor visitor) {
+        return root == null || !root.hasChildren()
+            ? true
+            : recursivePrune(root, visitor);
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org