changeset 7465:4b29bb2c785f

Datacage: Remove tree branches vom datacage tree on client side which do not contain loadable data.
author Sascha L. Teichmann <teichmann@intevation.de>
date Wed, 30 Oct 2013 11:58:57 +0100
parents f16dce7a2407
children 5cddf115b27b
files gwt-client/src/main/java/org/dive4elements/river/client/server/MetaDataServiceImpl.java gwt-client/src/main/java/org/dive4elements/river/client/shared/model/AttrList.java gwt-client/src/main/java/org/dive4elements/river/client/shared/model/DataCageNode.java gwt-client/src/main/java/org/dive4elements/river/client/shared/model/DataCageTree.java
diffstat 4 files changed, 54 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/server/MetaDataServiceImpl.java	Wed Oct 30 11:57:04 2013 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/server/MetaDataServiceImpl.java	Wed Oct 30 11:58:57 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	Wed Oct 30 11:57:04 2013 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/shared/model/AttrList.java	Wed Oct 30 11:58:57 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	Wed Oct 30 11:57:04 2013 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/shared/model/DataCageNode.java	Wed Oct 30 11:58:57 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	Wed Oct 30 11:57:04 2013 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/shared/model/DataCageTree.java	Wed Oct 30 11:58:57 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