chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fguilla...@apache.org
Subject svn commit: r893770 - in /incubator/chemistry/trunk/chemistry: chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/ chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/ chemistry-atompub-server/sr...
Date Thu, 24 Dec 2009 15:10:46 GMT
Author: fguillaume
Date: Thu Dec 24 15:10:46 2009
New Revision: 893770

URL: http://svn.apache.org/viewvc?rev=893770&view=rev
Log:
CMIS-82: implemented AtomPub object DELETE

Modified:
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPConnection.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/HttpClientResponse.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/Response.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/jaxrs/AbderaResource.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.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=893770&r1=893769&r2=893770&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 Dec 24 15:10:46 2009
@@ -45,6 +45,7 @@
 import org.apache.chemistry.ListPage;
 import org.apache.chemistry.ObjectEntry;
 import org.apache.chemistry.ObjectId;
+import org.apache.chemistry.ObjectNotFoundException;
 import org.apache.chemistry.Paging;
 import org.apache.chemistry.Policy;
 import org.apache.chemistry.Property;
@@ -66,6 +67,7 @@
 import org.apache.chemistry.impl.simple.SimpleContentStream;
 import org.apache.chemistry.impl.simple.SimpleListPage;
 import org.apache.chemistry.impl.simple.SimpleObjectId;
+import org.apache.commons.httpclient.HttpStatus;
 
 /**
  *
@@ -305,6 +307,9 @@
         // TODO proper URI template syntax
         href = href.replace("{id}", objectId.getId());
         Response resp = connector.get(new Request(href));
+        if (resp.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
+            throw new ObjectNotFoundException(objectId.getId());
+        }
         if (!resp.isOk()) {
             throw new ContentManagerException(
                     "Remote server returned error code: "
@@ -618,8 +623,25 @@
     }
 
     public void deleteObject(ObjectId object, boolean allVersions) {
-        // TODO Auto-generated method stub
-        throw new UnsupportedOperationException();
+        APPObjectEntry current = getObjectEntry(object);
+        String href = current.getLink(AtomPub.LINK_SELF);
+        Request req = new Request(href);
+        // TODO XXX allVersions not in spec
+        req.setParameter("allVersions", String.valueOf(allVersions));
+        Response resp = connector.delete(req);
+        int status = resp.getStatusCode();
+        if (status == HttpStatus.SC_NOT_FOUND) {
+            throw new ObjectNotFoundException(object.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());
+        }
     }
 
     public Collection<ObjectId> deleteTree(ObjectId folder, Unfiling unfiling,

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/HttpClientResponse.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/HttpClientResponse.java?rev=893770&r1=893769&r2=893770&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/HttpClientResponse.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/HttpClientResponse.java
Thu Dec 24 15:10:46 2009
@@ -64,6 +64,10 @@
         return method.getStatusCode() < 400;
     }
 
+    public String getStatusReasonPhrase() {
+        return method.getStatusLine().getReasonPhrase();
+    }
+
     public InputStream getStream() throws ContentManagerException {
         try {
             return method.getResponseBodyAsStream();

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/Response.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/Response.java?rev=893770&r1=893769&r2=893770&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/Response.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/connector/Response.java
Thu Dec 24 15:10:46 2009
@@ -62,4 +62,6 @@
 
     boolean isOk();
 
+    String getStatusReasonPhrase();
+
 }

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=893770&r1=893769&r2=893770&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
Thu Dec 24 15:10:46 2009
@@ -14,6 +14,7 @@
  * Authors:
  *     Florent Guillaume, Nuxeo
  *     Amelie Avramo, EntropySoft
+ *     Florian Roth, In-integrierte Informationssysteme
  */
 package org.apache.chemistry.atompub.server;
 
@@ -57,6 +58,7 @@
 import org.apache.chemistry.Inclusion;
 import org.apache.chemistry.ObjectEntry;
 import org.apache.chemistry.ObjectId;
+import org.apache.chemistry.ObjectNotFoundException;
 import org.apache.chemistry.Property;
 import org.apache.chemistry.RelationshipDirection;
 import org.apache.chemistry.Repository;
@@ -513,7 +515,25 @@
     @Override
     public void deleteEntry(String resourceName, RequestContext request)
             throws ResponseContextException {
-        throw new UnsupportedOperationException();
+        ObjectId object;
+        SPI spi = repository.getSPI();
+        try {
+            String oid = resourceName;
+            object = spi.newObjectId(oid);
+            // 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) {
+            throw new ResponseContextException(409, e);
+        } catch (CMISRuntimeException e) {
+            throw new ResponseContextException(500, e);
+        } catch (Exception e) {
+            throw new ResponseContextException(500, e);
+        } finally {
+            spi.close();
+        }
     }
 
     @Override

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java?rev=893770&r1=893769&r2=893770&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java
Thu Dec 24 15:10:46 2009
@@ -22,6 +22,7 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequestWrapper;
 import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
 import javax.ws.rs.POST;
 import javax.ws.rs.PUT;
@@ -229,6 +230,15 @@
         return getResponse(adapter.putEntry(requestContext));
     }
 
+    protected Response deleteAbderaEntry(int skipSegments) {
+        RequestContext requestContext = getRequestContext(skipSegments);
+        CollectionAdapter adapter = getAbderaCollectionAdapter(requestContext);
+        if (adapter == null) {
+            return Response.status(Response.Status.NOT_FOUND).build();
+        }
+        return getResponse(adapter.deleteEntry(requestContext));
+    }
+
     @GET
     @Produces(AtomPub.MEDIA_TYPE_ATOM_SERVICE)
     @Path("repository")
@@ -302,6 +312,13 @@
         return putAbderaEntry(2);
     }
 
+    @DELETE
+    @Path("object/{objectid}")
+    public Response deleteObject() {
+        // objectid decoded by Abdera getCollectionAdapter
+        return deleteAbderaEntry(2);
+    }
+
     @GET
     @Produces(AtomPub.MEDIA_TYPE_ATOM_ENTRY)
     @Path("path/{path:.*}")

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java?rev=893770&r1=893769&r2=893770&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java
Thu Dec 24 15:10:46 2009
@@ -270,6 +270,18 @@
         resp.release();
     }
 
+    public void testDelete() {
+        RequestOptions options = new RequestOptions();
+        options.setContentType(AtomPub.MEDIA_TYPE_ATOM_ENTRY);
+        ClientResponse resp = client.delete(base + "/object/" + doc3id, options);
+        assertEquals(HttpStatus.SC_NO_CONTENT, resp.getStatus());
+        resp.release();
+
+        resp = client.delete(base + "/object/nosuchid", options);
+        assertEquals(HttpStatus.SC_NOT_FOUND, resp.getStatus());
+        resp.release();
+    }
+
     public void testFile() throws Exception {
         HttpMethod method = new GetMethod(base + "/file/" + doc3id);
         int status = new HttpClient().executeMethod(method);

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=893770&r1=893769&r2=893770&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 Dec 24 15:10:46 2009
@@ -42,6 +42,7 @@
 import org.apache.chemistry.BaseType;
 import org.apache.chemistry.CMISObject;
 import org.apache.chemistry.Connection;
+import org.apache.chemistry.ConstraintViolationException;
 import org.apache.chemistry.ContentStream;
 import org.apache.chemistry.ContentStreamPresence;
 import org.apache.chemistry.Document;
@@ -50,6 +51,7 @@
 import org.apache.chemistry.ListPage;
 import org.apache.chemistry.ObjectEntry;
 import org.apache.chemistry.ObjectId;
+import org.apache.chemistry.ObjectNotFoundException;
 import org.apache.chemistry.Paging;
 import org.apache.chemistry.Policy;
 import org.apache.chemistry.Property;
@@ -658,18 +660,18 @@
         // TODO allVersions
         String id = object.getId();
         if (repository.rootId.equals(id)) {
-            throw new RuntimeException("Cannot delete root"); // TODO
+            throw new ConstraintViolationException("Cannot delete root");
         }
         SimpleData data = repository.datas.get(id);
         if (data == null) {
-            throw new RuntimeException("Not found: " + object); // TODO
+            throw new ObjectNotFoundException(object.getId());
         }
         // delete children info
         Set<String> children = repository.children.get(id);
         if (children != null) {
             if (children.size() > 0) {
-                throw new RuntimeException(
-                        "Cannot delete, folder has children: " + object); // TODO
+                throw new ConstraintViolationException(
+                        "Cannot delete, folder has children: " + object);
             }
             // remove only if empty
             repository.children.remove(id);

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=893770&r1=893769&r2=893770&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 Dec 24 15:10:46 2009
@@ -39,12 +39,14 @@
 import org.apache.chemistry.CapabilityQuery;
 import org.apache.chemistry.CapabilityRendition;
 import org.apache.chemistry.Connection;
+import org.apache.chemistry.ConstraintViolationException;
 import org.apache.chemistry.ContentStream;
 import org.apache.chemistry.Document;
 import org.apache.chemistry.Folder;
 import org.apache.chemistry.ListPage;
 import org.apache.chemistry.ObjectEntry;
 import org.apache.chemistry.ObjectId;
+import org.apache.chemistry.ObjectNotFoundException;
 import org.apache.chemistry.Paging;
 import org.apache.chemistry.Property;
 import org.apache.chemistry.Repository;
@@ -401,6 +403,26 @@
         assertFalse(spi.hasContentStream(id));
     }
 
+    public void testDeleteSPI() throws Exception {
+        ObjectEntry doc1 = spi.getObjectByPath("/folder 1/doc 1", null);
+        spi.deleteObject(doc1, false);
+        doc1 = spi.getObjectByPath("/folder 1/doc 1", null);
+        assertNull(doc1);
+        try {
+            spi.deleteObject(spi.newObjectId("nosuchid"), false);
+            fail();
+        } catch (ObjectNotFoundException e) {
+            // ok
+        }
+        ObjectEntry folder1 = spi.getObjectByPath("/folder 1", null);
+        try {
+            spi.deleteObject(folder1, false);
+            fail();
+        } catch (ConstraintViolationException e) {
+            // ok to fail, still has children
+        }
+    }
+
     public void testNewDocument() throws Exception {
         Folder root = conn.getRootFolder();
         assertNull(getDocumentChild(root));



Mime
View raw message