chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fguilla...@apache.org
Subject svn commit: r899223 - in /incubator/chemistry/trunk/chemistry: chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/ chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/ chemistry-tests/src/main/java/org/apache/chemis...
Date Thu, 14 Jan 2010 14:42:00 GMT
Author: fguillaume
Date: Thu Jan 14 14:41:59 2010
New Revision: 899223

URL: http://svn.apache.org/viewvc?rev=899223&view=rev
Log:
Implement AtomPub client getFolderTree using appropriate link

Modified:
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleListPage.java
    incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java?rev=899223&r1=899222&r2=899223&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java
Thu Jan 14 14:41:59 2010
@@ -186,36 +186,50 @@
      * ----- Navigation Services -----
      */
 
-    /**
-     * Accumulates the descendant folders into a list recursively.
-     */
-    protected void accumulateFolders(ObjectId folder, int depth,
-            Inclusion inclusion, List<ObjectEntry> list) {
-        List<ObjectEntry> children = getChildren(folder, inclusion, null,
-                new Paging(Integer.MAX_VALUE, 0));
-        for (ObjectEntry child : children) {
-            if (child.getBaseType() != BaseType.FOLDER) {
-                continue;
-            }
-            list.add(child);
-            if (depth > 1) {
-                accumulateFolders(child, depth - 1, inclusion, list);
-            }
-        }
-    }
+    // TODO check capabilityGetDescendants / capabilityGetFolderTree
+    // and folder fall back on recursion based on getChildren
 
-    // TODO use foldertree feed
     public List<ObjectEntry> getFolderTree(ObjectId folder, int depth,
             Inclusion inclusion) {
-        List<ObjectEntry> list = new ArrayList<ObjectEntry>();
-        accumulateFolders(folder, depth, inclusion, list);
-        return list;
+        String href = getFolderEntry(folder).getLink(
+                AtomPubCMIS.LINK_FOLDER_TREE, AtomPub.MEDIA_TYPE_ATOM_FEED);
+        if (href == null) {
+            throw new CMISRuntimeException("Missing foldertree link");
+        }
+        Request req = new Request(href);
+        req.setParameter(AtomPubCMIS.PARAM_DEPTH, Integer.toString(depth));
+        if (inclusion != null) {
+            if (inclusion.properties != null) {
+                req.setParameter(AtomPubCMIS.PARAM_FILTER, inclusion.properties);
+            }
+            if (inclusion.renditions != null) {
+                req.setParameter(AtomPubCMIS.PARAM_RENDITION_FILTER,
+                        inclusion.renditions);
+            }
+            if (inclusion.relationships != null) {
+                req.setParameter(
+                        AtomPubCMIS.PARAM_INCLUDE_RELATIONSHIPS,
+                        RelationshipDirection.toInclusion(inclusion.relationships));
+            }
+            req.setParameter(AtomPubCMIS.PARAM_INCLUDE_ALLOWABLE_ACTIONS,
+                    Boolean.toString(inclusion.allowableActions));
+        }
+        Response resp = connector.get(req);
+        if (!resp.isOk()) {
+            throw new ContentManagerException(
+                    "Remote server returned error code: "
+                            + resp.getStatusCode());
+        }
+        return resp.getObjectFeed(new ReadContext(this));
     }
 
     public List<ObjectEntry> getDescendants(ObjectId folder, int depth,
             String orderBy, Inclusion inclusion) {
         String href = getFolderEntry(folder).getLink(AtomPub.LINK_DOWN,
                 AtomPubCMIS.MEDIA_TYPE_CMIS_TREE);
+        if (href == null) {
+            throw new CMISRuntimeException("Missing down tree link");
+        }
         Request req = new Request(href);
         req.setParameter(AtomPubCMIS.PARAM_DEPTH, Integer.toString(depth));
         if (orderBy != null) {

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java?rev=899223&r1=899222&r2=899223&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.java
Thu Jan 14 14:41:59 2010
@@ -161,19 +161,20 @@
      */
 
     /**
-     * Accumulates the descendant folders into a list recursively.
+     * Accumulates descendants into a list recursively.
      */
-    protected void accumulateFolders(ObjectId folder, int depth,
-            Inclusion inclusion, List<ObjectEntry> list) {
-        ListPage<ObjectEntry> children = getChildren(folder, inclusion, null,
+    // TODO optimized paging
+    protected void accumulate(ObjectId folder, int depth, Inclusion inclusion,
+            String orderBy, BaseType baseType, List<ObjectEntry> list) {
+        List<ObjectEntry> children = getChildren(folder, inclusion, orderBy,
                 null);
         for (ObjectEntry child : children) {
-            if (child.getBaseType() != BaseType.FOLDER) {
-                continue;
+            BaseType childBaseType = child.getBaseType();
+            if (baseType == null || baseType == childBaseType) {
+                list.add(child);
             }
-            list.add(child);
-            if (depth > 1) {
-                accumulateFolders(child, depth - 1, inclusion, list);
+            if (childBaseType == BaseType.FOLDER && depth != 1) {
+                accumulate(child, depth - 1, inclusion, orderBy, baseType, list);
             }
         }
     }
@@ -182,40 +183,21 @@
             Inclusion inclusion) {
         checkFolder(folder);
         List<ObjectEntry> list = new ArrayList<ObjectEntry>();
-        accumulateFolders(folder, depth, inclusion, list);
+        accumulate(folder, depth, inclusion, null, BaseType.FOLDER, list);
         return list;
     }
 
-    /**
-     * Accumulates the descendants into a list recursively.
-     *
-     * @param includeRenditions TODO
-     */
-    protected void accumulateDescendants(ObjectId folder, int depth,
-            Inclusion inclusion, String orderBy, List<ObjectEntry> list) {
-        // TODO deal with paging properly
-        List<ObjectEntry> children = getChildren(folder, inclusion, orderBy,
-                null);
-        for (ObjectEntry child : children) {
-            list.add(child);
-            if (depth > 1 && child.getBaseType() == BaseType.FOLDER) {
-                accumulateDescendants(child, depth - 1, inclusion, orderBy,
-                        list);
-            }
-        }
-    }
-
     public List<ObjectEntry> getDescendants(ObjectId folder, int depth,
             String orderBy, Inclusion inclusion) {
         checkFolder(folder);
         List<ObjectEntry> list = new ArrayList<ObjectEntry>();
-        accumulateDescendants(folder, depth, inclusion, orderBy, list);
+        accumulate(folder, depth, inclusion, orderBy, null, list);
         return list;
     }
 
     public ListPage<ObjectEntry> getChildren(ObjectId folder,
             Inclusion inclusion, String orderBy, Paging paging) {
-        // TODO orderBy
+        // TODO orderBy, inclusion
         checkFolder(folder);
         Set<String> ids = repository.children.get(folder.getId());
         List<ObjectEntry> all = new ArrayList<ObjectEntry>(ids.size());
@@ -223,7 +205,7 @@
             SimpleData data = repository.datas.get(id);
             all.add(new SimpleObjectEntry(data, this));
         }
-        return getListPage(all, paging);
+        return SimpleListPage.fromPaging(all, paging);
     }
 
     protected void checkFolder(ObjectId object) throws ObjectNotFoundException,
@@ -240,41 +222,6 @@
 
     }
 
-    /**
-     * Extracts part of a list according to given paging parameters.
-     *
-     * @param all the complete list
-     * @param paging the paging info, which may be {@code null}
-     * @return the page
-     */
-    public static ListPage<ObjectEntry> getListPage(List<ObjectEntry> all,
-            Paging paging) {
-        int total = all.size();
-        int fromIndex = paging == null ? 0 : paging.skipCount;
-        if (fromIndex < 0 || fromIndex > total) {
-            return SimpleListPage.emptyList();
-        }
-        int maxItems = paging == null ? -1 : paging.maxItems;
-        if (maxItems <= 0) {
-            maxItems = total;
-        }
-        int toIndex = fromIndex + maxItems;
-        if (toIndex > total) {
-            toIndex = total;
-        }
-        List<ObjectEntry> slice;
-        if (fromIndex == 0 && toIndex == total) {
-            slice = all;
-        } else {
-            slice = all.subList(fromIndex, toIndex);
-        }
-        SimpleListPage<ObjectEntry> page;
-        page = new SimpleListPage<ObjectEntry>(slice);
-        page.setHasMoreItems(toIndex < total);
-        page.setNumItems(total);
-        return page;
-    }
-
     public ObjectEntry getFolderParent(ObjectId folder, String filter) {
         // TODO filter
         String folderId = folder.getId();
@@ -776,7 +723,7 @@
                 all.add(new SimpleObjectEntry(data, this));
             }
         }
-        return getListPage(all, paging);
+        return SimpleListPage.fromPaging(all, paging);
     }
 
     protected boolean typeMatches(String tableName, String typeId) {

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleListPage.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleListPage.java?rev=899223&r1=899222&r2=899223&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleListPage.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleListPage.java
Thu Jan 14 14:41:59 2010
@@ -20,9 +20,12 @@
 import java.util.AbstractList;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.List;
 import java.util.RandomAccess;
 
 import org.apache.chemistry.ListPage;
+import org.apache.chemistry.ObjectEntry;
+import org.apache.chemistry.Paging;
 
 /**
  * A simple implementation of {@link ListPage} based on {@link ArrayList}.
@@ -98,6 +101,41 @@
         super(collection);
     }
 
+    /**
+     * Extracts part of a list according to given paging parameters.
+     *
+     * @param all the complete list
+     * @param paging the paging info, which may be {@code null}
+     * @return the page
+     */
+    public static ListPage<ObjectEntry> fromPaging(List<ObjectEntry> all,
+            Paging paging) {
+        int total = all.size();
+        int fromIndex = paging == null ? 0 : paging.skipCount;
+        if (fromIndex < 0 || fromIndex > total) {
+            return emptyList();
+        }
+        int maxItems = paging == null ? -1 : paging.maxItems;
+        if (maxItems <= 0) {
+            maxItems = total;
+        }
+        int toIndex = fromIndex + maxItems;
+        if (toIndex > total) {
+            toIndex = total;
+        }
+        List<ObjectEntry> slice;
+        if (fromIndex == 0 && toIndex == total) {
+            slice = all;
+        } else {
+            slice = all.subList(fromIndex, toIndex);
+        }
+        SimpleListPage<ObjectEntry> page = new SimpleListPage<ObjectEntry>(
+                slice);
+        page.setHasMoreItems(toIndex < total);
+        page.setNumItems(total);
+        return page;
+    }
+
     public boolean getHasMoreItems() {
         return hasMoreItems;
     }

Modified: incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java?rev=899223&r1=899222&r2=899223&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java
Thu Jan 14 14:41:59 2010
@@ -374,6 +374,34 @@
         }
     }
 
+
+    public void testTrees() throws Exception {
+        List<ObjectEntry> list;
+
+        Folder root = conn.getRootFolder();
+        list = spi.getDescendants(root, -1, null, null);
+        assertEquals(6, list.size());
+        list = spi.getDescendants(root, 1, null, null);
+        assertEquals(1, list.size());
+        list = spi.getDescendants(root, 2, null, null);
+        assertEquals(3, list.size());
+        list = spi.getDescendants(root, 3, null, null);
+        assertEquals(6, list.size());
+        list = spi.getDescendants(root, 4, null, null);
+        assertEquals(6, list.size());
+
+        ObjectEntry fold1 = spi.getObjectByPath("/folder 1", null);
+        list = spi.getDescendants(fold1, -1, null, null);
+        assertEquals(5, list.size());
+        list = spi.getDescendants(fold1, 1, null, null);
+        assertEquals(2, list.size());
+        list = spi.getDescendants(fold1, 2, null, null);
+        assertEquals(5, list.size());
+        list = spi.getDescendants(fold1, 3, null, null);
+        assertEquals(5, list.size());
+    }
+
+
     public void testGetFolderParent() {
         Folder root = conn.getRootFolder();
         assertNull(spi.getFolderParent(root, null));



Mime
View raw message