You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fg...@apache.org on 2010/01/05 16:43:30 UTC

svn commit: r896101 - in /incubator/chemistry/trunk/chemistry: chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/ chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/ chemistry-atompub/src/main/java/org/a...

Author: fguillaume
Date: Tue Jan  5 15:43:29 2010
New Revision: 896101

URL: http://svn.apache.org/viewvc?rev=896101&view=rev
Log:
Implemented foldertree collection and deleteTree

Added:
    incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/resources/jaxrs/
    incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/resources/jaxrs/web.xml   (with props)
Modified:
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISChildrenCollection.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISCollection.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISProvider.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISWorkspaceManager.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/AtomPubCMIS.java
    incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleConnection.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=896101&r1=896100&r2=896101&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 Tue Jan  5 15:43:29 2010
@@ -36,6 +36,7 @@
 import org.apache.chemistry.ACLPropagation;
 import org.apache.chemistry.BaseType;
 import org.apache.chemistry.CMISObject;
+import org.apache.chemistry.CMISRuntimeException;
 import org.apache.chemistry.Connection;
 import org.apache.chemistry.ConstraintViolationException;
 import org.apache.chemistry.ContentStream;
@@ -650,8 +651,37 @@
 
     public Collection<ObjectId> deleteTree(ObjectId folder, Unfiling unfiling,
             boolean continueOnFailure) {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException();
+        APPObjectEntry current = getObjectEntry(folder);
+        String href = current.getLink(AtomPub.LINK_DOWN,
+                AtomPubCMIS.MEDIA_TYPE_CMIS_TREE);
+        if (href == null) {
+            throw new CMISRuntimeException("Document is missing link "
+                    + AtomPub.LINK_DOWN + " "
+                    + AtomPubCMIS.MEDIA_TYPE_CMIS_TREE);
+        }
+        Request req = new Request(href);
+        if (unfiling != null) {
+            req.setParameter(AtomPubCMIS.PARAM_UNFILE_OBJECTS,
+                    unfiling.toString());
+        }
+        req.setParameter(AtomPubCMIS.PARAM_CONTINUE_ON_FAILURE,
+                Boolean.toString(continueOnFailure));
+        Response resp = connector.delete(req);
+        int status = resp.getStatusCode();
+        if (status == HttpStatus.SC_NOT_FOUND) {
+            throw new ObjectNotFoundException(folder.getId());
+        }
+        if (status == HttpStatus.SC_CONFLICT) {
+            throw new ConstraintViolationException(resp.getStatusReasonPhrase());
+        }
+        if (!resp.isOk()) {
+            // TODO exceptions
+            throw new ContentManagerException(
+                    "Remote server returned error code: "
+                            + resp.getStatusCode());
+        }
+        // AtomPub bindings cannot return the objects that could not be deleted
+        return Collections.emptyList();
     }
 
     public void addObjectToFolder(ObjectId object, ObjectId folder) {

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISChildrenCollection.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISChildrenCollection.java?rev=896101&r1=896100&r2=896101&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISChildrenCollection.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISChildrenCollection.java Tue Jan  5 15:43:29 2010
@@ -100,6 +100,12 @@
             feed.addLink(getChildrenLink(pid, request), AtomPub.LINK_UP,
                     AtomPub.MEDIA_TYPE_ATOM_FEED, null, null, -1);
         }
+        // TODO don't add descendants links if no children
+        feed.addLink(getDescendantsLink(pid, request), AtomPub.LINK_DOWN,
+                AtomPubCMIS.MEDIA_TYPE_CMIS_TREE, null, null, -1);
+        feed.addLink(getFolderTreeLink(pid, request),
+                AtomPubCMIS.LINK_FOLDER_TREE, AtomPub.MEDIA_TYPE_ATOM_FEED,
+                null, null, -1);
 
         // AtomPub paging
         // next
@@ -178,7 +184,7 @@
                 AtomPubCMIS.PARAM_INCLUDE_ALLOWABLE_ACTIONS, false);
         Inclusion inclusion = new Inclusion(properties, renditions,
                 relationships, allowableActions, false, false);
-        if ("descendants".equals(getType())) {
+        if (COLTYPE_DESCENDANTS.equals(getType())) {
             int depth = getParameter(request, AtomPubCMIS.PARAM_DEPTH, 1);
             List<ObjectEntry> descendants = spi.getDescendants(objectId, depth,
                     orderBy, inclusion);
@@ -187,6 +193,15 @@
             page.setHasMoreItems(false);
             page.setNumItems(page.size());
             return page;
+        } else if (COLTYPE_FOLDER_TREE.equals(getType())) {
+            int depth = getParameter(request, AtomPubCMIS.PARAM_DEPTH, 1);
+            List<ObjectEntry> folderTree = spi.getFolderTree(objectId, depth,
+                    inclusion);
+            SimpleListPage<ObjectEntry> page = new SimpleListPage<ObjectEntry>(
+                    folderTree);
+            page.setHasMoreItems(false);
+            page.setNumItems(page.size());
+            return page;
         } else {
             int maxItems = getParameter(request, AtomPubCMIS.PARAM_MAX_ITEMS, 0);
             int skipCount = getParameter(request, AtomPubCMIS.PARAM_SKIP_COUNT,

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISCollection.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISCollection.java?rev=896101&r1=896100&r2=896101&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISCollection.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISCollection.java Tue Jan  5 15:43:29 2010
@@ -147,6 +147,13 @@
         return request.absoluteUrlFor(TargetType.TYPE_COLLECTION, params);
     }
 
+    public String getFolderTreeLink(String fid, RequestContext request) {
+        Map<String, String> params = new HashMap<String, String>();
+        params.put("collection", "foldertree");
+        params.put("id", fid);
+        return request.absoluteUrlFor(TargetType.TYPE_COLLECTION, params);
+    }
+
     public String getParentsLink(String fid, RequestContext request) {
         Map<String, String> params = new HashMap<String, String>();
         params.put("collection", "parents");

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java?rev=896101&r1=896100&r2=896101&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISObjectsCollection.java Tue Jan  5 15:43:29 2010
@@ -53,6 +53,7 @@
 import org.apache.abdera.protocol.server.RequestContext;
 import org.apache.abdera.protocol.server.ResponseContext;
 import org.apache.abdera.protocol.server.Target;
+import org.apache.abdera.protocol.server.TargetType;
 import org.apache.abdera.protocol.server.context.AbstractResponseContext;
 import org.apache.abdera.protocol.server.context.BaseResponseContext;
 import org.apache.abdera.protocol.server.context.EmptyResponseContext;
@@ -73,6 +74,7 @@
 import org.apache.chemistry.Repository;
 import org.apache.chemistry.SPI;
 import org.apache.chemistry.Type;
+import org.apache.chemistry.Unfiling;
 import org.apache.chemistry.VersioningState;
 import org.apache.chemistry.atompub.AtomPub;
 import org.apache.chemistry.atompub.AtomPubCMIS;
@@ -94,6 +96,18 @@
 
     private static final Log log = LogFactory.getLog(CMISObjectsCollection.class);
 
+    public static final String COLTYPE_PATH = "path";
+
+    public static final String COLTYPE_DESCENDANTS = "descendants";
+
+    public static final String COLTYPE_FOLDER_TREE = "foldertree";
+
+    public static final TargetType TARGET_TYPE_CMIS_DESCENDANTS = TargetType.get(
+            "CMISDESCENDANTS", true);
+
+    public static final TargetType TARGET_TYPE_CMIS_FOLDER_TREE = TargetType.get(
+            "CMISFOLDERTREE", true);
+
     public CMISObjectsCollection(String type, String name, String id,
             Repository repository) {
         super(type, name, id, repository);
@@ -103,6 +117,25 @@
      * ----- AbstractCollectionAdapter -----
      */
 
+    // called by AbstractProvider.process if unknown TargetType
+    @Override
+    public ResponseContext extensionRequest(RequestContext request) {
+        TargetType type = request.getTarget().getType();
+        if (type != TARGET_TYPE_CMIS_DESCENDANTS
+                && type != TARGET_TYPE_CMIS_FOLDER_TREE) {
+            return ProviderHelper.notsupported(request);
+        }
+        if (request.getMethod().equalsIgnoreCase("GET")) {
+            return getFeed(request);
+        } else if (request.getMethod().equalsIgnoreCase("DELETE")) {
+            return deleteEntry(request);
+        } else {
+            // stupid signature prevents use of varargs...
+            return ProviderHelper.notallowed(request, new String[] { "GET",
+                    "DELETE" });
+        }
+    }
+
     @Override
     protected Feed createFeedBase(RequestContext request)
             throws ResponseContextException {
@@ -247,6 +280,9 @@
             // TODO don't add descendants links if no children
             entry.addLink(getDescendantsLink(oid, request), AtomPub.LINK_DOWN,
                     AtomPubCMIS.MEDIA_TYPE_CMIS_TREE, null, null, -1);
+            entry.addLink(getFolderTreeLink(oid, request),
+                    AtomPubCMIS.LINK_FOLDER_TREE, AtomPub.MEDIA_TYPE_ATOM_FEED,
+                    null, null, -1);
         } else if (baseType == BaseType.DOCUMENT) {
             // edit-media link always needed for setContentStream
             entry.addLink(getMediaLink(oid, request), AtomPub.LINK_EDIT_MEDIA);
@@ -572,9 +608,21 @@
         try {
             String oid = resourceName;
             object = spi.newObjectId(oid);
-            // TODO XXX allVersions not in spec
-            boolean allVersions = getParameter(request, "allVersions", false);
-            spi.deleteObject(object, allVersions);
+            if (COLTYPE_DESCENDANTS.equals(getType())
+                    || COLTYPE_FOLDER_TREE.equals(getType())) {
+                String unfile = request.getTarget().getParameter(
+                        AtomPubCMIS.PARAM_UNFILE_OBJECTS);
+                Unfiling unfileObjects = unfile == null ? null
+                        : Unfiling.get(unfile);
+                boolean continueOnFailure = getParameter(request,
+                        AtomPubCMIS.PARAM_CONTINUE_ON_FAILURE, false);
+                spi.deleteTree(object, unfileObjects, continueOnFailure);
+            } else {
+                // TODO XXX allVersions not in spec
+                boolean allVersions = getParameter(request, "allVersions",
+                        false);
+                spi.deleteObject(object, allVersions);
+            }
         } catch (ObjectNotFoundException e) {
             throw new ResponseContextException(404, e);
         } catch (ConstraintViolationException e) {
@@ -742,7 +790,7 @@
         RelationshipDirection relationships = RelationshipDirection.fromInclusion(incl);
         Inclusion inclusion = new Inclusion(properties, null, relationships,
                 allowableActions, false, false);
-        if ("path".equals(getType())) {
+        if (COLTYPE_PATH.equals(getType())) {
             String path = resourceName;
             if (!path.startsWith("/")) {
                 path = "/" + path;
@@ -757,7 +805,7 @@
     @Override
     public String getResourceName(RequestContext request) {
         String name;
-        if ("path".equals(getType())) {
+        if (COLTYPE_PATH.equals(getType())) {
             name = "path";
         } else {
             name = "objectid";

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISProvider.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISProvider.java?rev=896101&r1=896100&r2=896101&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISProvider.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISProvider.java Tue Jan  5 15:43:29 2010
@@ -98,7 +98,9 @@
         targetResolver.setPattern("/children/([^/?]+)(\\?.*)?",
                 TargetType.TYPE_COLLECTION, "objectid");
         targetResolver.setPattern("/descendants/([^/?]+)(\\?.*)?",
-                TargetType.TYPE_COLLECTION, "objectid");
+                CMISObjectsCollection.TARGET_TYPE_CMIS_DESCENDANTS, "objectid");
+        targetResolver.setPattern("/foldertree/([^/?]+)(\\?.*)?",
+                CMISObjectsCollection.TARGET_TYPE_CMIS_FOLDER_TREE, "objectid");
         targetResolver.setPattern("/allversions/([^/?]+)",
                 TargetType.TYPE_COLLECTION, "objectid");
         targetResolver.setPattern("/relationships/([^/?]+)",

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISWorkspaceManager.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISWorkspaceManager.java?rev=896101&r1=896100&r2=896101&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISWorkspaceManager.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/CMISWorkspaceManager.java Tue Jan  5 15:43:29 2010
@@ -58,7 +58,13 @@
         }
         if (paths.startsWith("/descendants/")) {
             String id = request.getTarget().getParameter("objectid");
-            return new CMISChildrenCollection("descendants", id, repository);
+            return new CMISChildrenCollection(
+                    CMISObjectsCollection.COLTYPE_DESCENDANTS, id, repository);
+        }
+        if (paths.startsWith("/foldertree/")) {
+            String id = request.getTarget().getParameter("objectid");
+            return new CMISChildrenCollection(
+                    CMISObjectsCollection.COLTYPE_FOLDER_TREE, id, repository);
         }
         if (paths.startsWith("/parents/")) {
             String id = request.getTarget().getParameter("objectid");
@@ -69,7 +75,8 @@
             return new CMISChildrenCollection(null, null, repository);
         }
         if (paths.startsWith("/path/")) {
-            return new CMISChildrenCollection("path", null, repository);
+            return new CMISChildrenCollection(
+                    CMISObjectsCollection.COLTYPE_PATH, null, repository);
         }
         if (paths.startsWith("/file/")) {
             return new CMISChildrenCollection(null, null, repository);

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/AtomPubCMIS.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/AtomPubCMIS.java?rev=896101&r1=896100&r2=896101&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/AtomPubCMIS.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub/src/main/java/org/apache/chemistry/atompub/AtomPubCMIS.java Tue Jan  5 15:43:29 2010
@@ -138,6 +138,10 @@
 
     public static final String PARAM_INCLUDE_PATH_SEGMENT = "includePathSegment";
 
+    public static final String PARAM_CONTINUE_ON_FAILURE = "continueOnFailure";
+
+    public static final String PARAM_UNFILE_OBJECTS = "unfileObjects";
+
     /*
      * ----- URI Template Types -----
      */

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=896101&r1=896100&r2=896101&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 Tue Jan  5 15:43:29 2010
@@ -705,7 +705,7 @@
         if (repository.getType(typeId).getBaseType() != BaseType.FOLDER) {
             throw new RuntimeException("Not a folder: " + folder); // TODO
         }
-        for (String childId : repository.children.get(id)) {
+        for (String childId : new ArrayList<String>(repository.children.get(id))) {
             SimpleData childData = repository.datas.get(childId);
             String childTypeId = (String) childData.get(Property.TYPE_ID);
             ObjectId objectId = new SimpleObjectId(childId);
@@ -822,9 +822,9 @@
         throw new UnsupportedOperationException();
     }
 
-    public ObjectId checkIn(ObjectId document, Map<String, Serializable> properties,
-            ContentStream contentStream, boolean major,
-            String comment) {
+    public ObjectId checkIn(ObjectId document,
+            Map<String, Serializable> properties, ContentStream contentStream,
+            boolean major, String comment) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }

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=896101&r1=896100&r2=896101&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 Tue Jan  5 15:43:29 2010
@@ -435,6 +435,15 @@
         }
     }
 
+    public void testDeleteTreeSPI() throws Exception {
+        ObjectEntry fold2 = spi.getObjectByPath("/folder 1/folder 2", null);
+        spi.deleteTree(fold2, null, true);
+        ObjectEntry oe = spi.getObjectByPath("/folder 1/doc 1", null);
+        assertNotNull(oe);
+        oe = spi.getObjectByPath("/folder 1/folder 2", null);
+        assertNull(oe);
+    }
+
     public void testNewDocument() throws Exception {
         Folder root = conn.getRootFolder();
         assertNull(getDocumentChild(root));

Added: incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/resources/jaxrs/web.xml
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/resources/jaxrs/web.xml?rev=896101&view=auto
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/resources/jaxrs/web.xml (added)
+++ incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/resources/jaxrs/web.xml Tue Jan  5 15:43:29 2010
@@ -0,0 +1,19 @@
+<?xml version="1.0"?>
+<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+  "http://java.sun.com/dtd/web-app_2_3.dtd">
+<web-app>
+  <servlet>
+    <servlet-name>cxfjaxrs</servlet-name>
+    <servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
+    <init-param>
+      <param-name>javax.ws.rs.Application</param-name>
+      <param-value>org.apache.chemistry.atompub.server.jaxrs.CMISApplication</param-value>
+    </init-param>
+    <load-on-startup>1</load-on-startup>
+  </servlet>
+
+  <servlet-mapping>
+    <servlet-name>cxfjaxrs</servlet-name>
+    <url-pattern>/*</url-pattern>
+  </servlet-mapping>
+</web-app>

Propchange: incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/resources/jaxrs/web.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/resources/jaxrs/web.xml
------------------------------------------------------------------------------
    svn:keywords = Id