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/02/22 19:03:31 UTC

svn commit: r914996 - in /incubator/chemistry/trunk/chemistry: chemistry-api/src/main/java/org/apache/chemistry/ chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/ chemistry-commons/src/main/java/org/apache/chemistry/impl/simpl...

Author: fguillaume
Date: Mon Feb 22 18:03:30 2010
New Revision: 914996

URL: http://svn.apache.org/viewvc?rev=914996&view=rev
Log:
CMIS-54: added SPI.createDocumentFromSource and Document.copy

Modified:
    incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/Document.java
    incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/SPI.java
    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/APPDocument.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/SimpleDocument.java
    incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrConnection.java
    incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrDocument.java
    incubator/chemistry/trunk/chemistry/chemistry-tests/src/main/java/org/apache/chemistry/test/BasicTestCase.java

Modified: incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/Document.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/Document.java?rev=914996&r1=914995&r2=914996&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/Document.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/Document.java Mon Feb 22 18:03:30 2010
@@ -25,6 +25,27 @@
 public interface Document extends CMISObject {
 
     /*
+     * ----- Object Services -----
+     */
+
+    /**
+     * Copies this document to another folder.
+     * <p>
+     * The target folder may be {@code null} to create an unfiled copy.
+     *
+     * @param folder the target folder, or {@code null}
+     * @return the document copy
+     *
+     * @throws ConstraintViolationException if the document's type isn't allowed
+     *             as a child object type in the folder
+     * @throws NameConstraintViolationException if the object name is not legal
+     *             in its new folder
+     * @throws VersioningException if the move cannot be done to a non-latest
+     *             version
+     */
+    Document copy(Folder folder) throws NameConstraintViolationException;
+
+    /*
      * ----- Versioning Services -----
      */
 

Modified: incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/SPI.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/SPI.java?rev=914996&r1=914995&r2=914996&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/SPI.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-api/src/main/java/org/apache/chemistry/SPI.java Mon Feb 22 18:03:30 2010
@@ -238,12 +238,42 @@
      *             document
      * @throws NameConstraintViolationException if the name is not legal
      */
+    // TODO policies, addACEs, removeACEs
     ObjectId createDocument(Map<String, Serializable> properties,
             ObjectId folder, ContentStream contentStream,
             VersioningState versioningState)
             throws NameConstraintViolationException;
 
-    // TODO 1.0 createDocumentFromSource
+    /**
+     * Copies a document.
+     * <p>
+     * Creates a document as a copy of the given source document.
+     * <p>
+     * A set of properties that have to be changed in the copy can be specified.
+     * This allows a "copy-and-update" operation.
+     * <p>
+     * The versioningState input is used to create a document in a
+     * {@link VersioningState#CHECKED_OUT CHECKED_OUT} state, or as a checked-in
+     * {@link VersioningState#MINOR MINOR} version, or as a checked-in
+     * {@link VersioningState#MAJOR MAJOR} version. If created in a
+     * {@link VersioningState#CHECKED_OUT CHECKED_OUT} state, the object is a
+     * private working copy and there is no corresponding checked out document.
+     *
+     * @param source the source document
+     * @param folder the parent folder for the newly created document, or
+     *            {@code null} for to create an unfiled document
+     * @param properties the properties to change
+     * @param versioningState the versioning state
+     * @return the ID of the created document
+     *
+     * @throws ConstraintViolationException if the properties are not legal
+     * @throws NameConstraintViolationException if the name is not legal
+     */
+    // TODO policies, addACEs, removeACEs
+    ObjectId createDocumentFromSource(ObjectId source, ObjectId folder,
+            Map<String, Serializable> properties,
+            VersioningState versioningState)
+            throws NameConstraintViolationException;
 
     /**
      * Creates a folder.
@@ -255,6 +285,7 @@
      * @throws ConstraintViolationException if the properties are not legal
      * @throws NameConstraintViolationException if the name is not legal
      */
+    // TODO policies, addACEs, removeACEs
     ObjectId createFolder(Map<String, Serializable> properties, ObjectId folder)
             throws NameConstraintViolationException;
 
@@ -266,6 +297,7 @@
      *
      * @throws ConstraintViolationException if the properties are not legal
      */
+    // TODO policies, addACEs, removeACEs
     ObjectId createRelationship(Map<String, Serializable> properties);
 
     /**
@@ -280,6 +312,7 @@
      *
      * @throws ConstraintViolationException if the properties are not legal
      */
+    // TODO policies, addACEs, removeACEs
     ObjectId createPolicy(Map<String, Serializable> properties, ObjectId folder);
 
     /**

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=914996&r1=914995&r2=914996&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 Mon Feb 22 18:03:30 2010
@@ -42,6 +42,7 @@
 import org.apache.chemistry.Folder;
 import org.apache.chemistry.Inclusion;
 import org.apache.chemistry.ListPage;
+import org.apache.chemistry.NameConstraintViolationException;
 import org.apache.chemistry.ObjectEntry;
 import org.apache.chemistry.ObjectId;
 import org.apache.chemistry.ObjectNotFoundException;
@@ -382,6 +383,15 @@
         return connector.postEntry(href, null, entry);
     }
 
+    public ObjectId createDocumentFromSource(ObjectId source, ObjectId folder,
+            Map<String, Serializable> properties,
+            VersioningState versioningState)
+            throws NameConstraintViolationException {
+        // TODO implement copy "by hand" or using extensions when available
+        throw new CMISRuntimeException(
+                "AtomPub bindings do not support createDocumentFromSource");
+    }
+
     public ObjectId createDocument(Map<String, Serializable> properties,
             ObjectId folder, ContentStream contentStream,
             VersioningState versioningState) {

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPDocument.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPDocument.java?rev=914996&r1=914995&r2=914996&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPDocument.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-client/src/main/java/org/apache/chemistry/atompub/client/APPDocument.java Mon Feb 22 18:03:30 2010
@@ -21,8 +21,11 @@
 import java.io.IOException;
 import java.util.Collection;
 
+import org.apache.chemistry.CMISRuntimeException;
 import org.apache.chemistry.ContentStream;
 import org.apache.chemistry.Document;
+import org.apache.chemistry.Folder;
+import org.apache.chemistry.NameConstraintViolationException;
 import org.apache.chemistry.Type;
 
 /**
@@ -73,4 +76,9 @@
         throw new UnsupportedOperationException();
     }
 
+    public Document copy(Folder folder) throws NameConstraintViolationException {
+        // TODO implement copy "by hand" or using extensions when available
+        throw new CMISRuntimeException("AtomPub bindings do not support copy");
+    }
+
 }

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=914996&r1=914995&r2=914996&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 Mon Feb 22 18:03:30 2010
@@ -53,6 +53,7 @@
 import org.apache.chemistry.Folder;
 import org.apache.chemistry.Inclusion;
 import org.apache.chemistry.ListPage;
+import org.apache.chemistry.NameConstraintViolationException;
 import org.apache.chemistry.ObjectEntry;
 import org.apache.chemistry.ObjectId;
 import org.apache.chemistry.ObjectNotFoundException;
@@ -369,10 +370,45 @@
         }
     }
 
+    public ObjectId createDocumentFromSource(ObjectId source, ObjectId folder,
+            Map<String, Serializable> properties,
+            VersioningState versioningState)
+            throws NameConstraintViolationException {
+        // TODO versioningState
+        String id = source.getId();
+        SimpleData sourceData = repository.datas.get(id);
+        if (sourceData == null) {
+            throw new ObjectNotFoundException(id);
+        }
+        String typeId = (String) sourceData.get(Property.TYPE_ID);
+        Type type = repository.getType(typeId);
+        if (type == null || type.getBaseType() != BaseType.DOCUMENT) {
+            throw new IllegalArgumentException(typeId);
+        }
+        SimpleData data = new SimpleData(null, null);
+        data.putAll(sourceData);
+        if (properties != null) {
+            data.putAll(properties);
+        }
+        data.remove(Property.CREATION_DATE);
+        data.remove(Property.CREATED_BY);
+        if (folder == null) {
+            data.remove(Property.PARENT_ID);
+        } else {
+            String folderId = folder.getId();
+            if (!repository.datas.containsKey(folderId)) {
+                throw new ObjectNotFoundException(folderId);
+            }
+            data.put(Property.PARENT_ID, folderId);
+        }
+        saveData(data, (String) data.get(Property.TYPE_ID));
+        return new SimpleObjectEntry(data, this);
+    }
+
     public ObjectId createDocument(Map<String, Serializable> properties,
             ObjectId folder, ContentStream contentStream,
             VersioningState versioningState) {
-        // TODO contentStream, versioningState
+        // TODO versioningState
         String typeId = (String) properties.get(Property.TYPE_ID);
         if (typeId == null) {
             // use a default type, useful for pure AtomPub POST

Modified: incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleDocument.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleDocument.java?rev=914996&r1=914995&r2=914996&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleDocument.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-commons/src/main/java/org/apache/chemistry/impl/simple/SimpleDocument.java Mon Feb 22 18:03:30 2010
@@ -23,6 +23,9 @@
 import org.apache.chemistry.ContentStream;
 import org.apache.chemistry.ContentStreamPresence;
 import org.apache.chemistry.Document;
+import org.apache.chemistry.Folder;
+import org.apache.chemistry.NameConstraintViolationException;
+import org.apache.chemistry.ObjectId;
 import org.apache.chemistry.Property;
 
 public class SimpleDocument extends SimpleObject implements Document {
@@ -93,7 +96,7 @@
         } else {
             entry.setValue(Property.CONTENT_STREAM_LENGTH,
                     Integer.valueOf((int) contentStream.getLength())); // TODO
-                                                                       // Long
+            // Long
             entry.setValue(Property.CONTENT_STREAM_MIME_TYPE,
                     contentStream.getMimeType());
             entry.setValue(Property.CONTENT_STREAM_FILE_NAME,
@@ -103,4 +106,10 @@
         }
     }
 
+    public Document copy(Folder folder) throws NameConstraintViolationException {
+        ObjectId id = connection.getSPI().createDocumentFromSource(this,
+                folder, null, null);
+        return new SimpleDocument((SimpleObjectEntry) id, connection);
+    }
+
 }

Modified: incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrConnection.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrConnection.java?rev=914996&r1=914995&r2=914996&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrConnection.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrConnection.java Mon Feb 22 18:03:30 2010
@@ -182,9 +182,9 @@
         throw new UnsupportedOperationException();
     }
 
-    public ObjectId checkIn(ObjectId documentId, Map<String, Serializable> properties,
-            ContentStream contentStream, boolean major,
-            String comment) {
+    public ObjectId checkIn(ObjectId documentId,
+            Map<String, Serializable> properties, ContentStream contentStream,
+            boolean major, String comment) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }
@@ -194,6 +194,14 @@
         throw new UnsupportedOperationException();
     }
 
+    public ObjectId createDocumentFromSource(ObjectId source, ObjectId folder,
+            Map<String, Serializable> properties,
+            VersioningState versioningState)
+            throws NameConstraintViolationException {
+        // TODO Auto-generated method stub
+        throw new UnsupportedOperationException();
+    }
+
     // TODO add IOException to throws clause
     public ObjectId createDocument(Map<String, Serializable> properties,
             ObjectId folderId, ContentStream contentStream,
@@ -479,8 +487,8 @@
         throw new UnsupportedOperationException();
     }
 
-    public ObjectId setContentStream(ObjectId documentId, ContentStream contentStream,
-            boolean overwrite) {
+    public ObjectId setContentStream(ObjectId documentId,
+            ContentStream contentStream, boolean overwrite) {
         // TODO Auto-generated method stub
         throw new UnsupportedOperationException();
     }

Modified: incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrDocument.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrDocument.java?rev=914996&r1=914995&r2=914996&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrDocument.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-jcr/src/main/java/org/apache/chemistry/jcr/JcrDocument.java Mon Feb 22 18:03:30 2010
@@ -29,6 +29,7 @@
 import org.apache.chemistry.ContentStream;
 import org.apache.chemistry.Document;
 import org.apache.chemistry.Folder;
+import org.apache.chemistry.NameConstraintViolationException;
 import org.apache.chemistry.Property;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -152,4 +153,9 @@
         return null;
     }
 
+    public Document copy(Folder folder) throws NameConstraintViolationException {
+        // 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=914996&r1=914995&r2=914996&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 Mon Feb 22 18:03:30 2010
@@ -33,6 +33,7 @@
 
 import org.apache.chemistry.BaseType;
 import org.apache.chemistry.CMISObject;
+import org.apache.chemistry.CMISRuntimeException;
 import org.apache.chemistry.CapabilityACL;
 import org.apache.chemistry.CapabilityChange;
 import org.apache.chemistry.CapabilityJoin;
@@ -252,6 +253,46 @@
         assertEquals("some title", doc.getValue("title"));
     }
 
+    public void testCopySPI() throws Exception {
+        ObjectEntry doc1 = spi.getObjectByPath("/folder 1/doc 1", null);
+        Map<String, Serializable> properties = new HashMap<String, Serializable>();
+        properties.put("title", "new title");
+        try {
+            ObjectId id = spi.createDocumentFromSource(doc1,
+                    repository.getInfo().getRootFolderId(), properties, null);
+            assertNotNull(id);
+            assertNotSame(id, doc1.getId());
+        } catch (CMISRuntimeException e) {
+            assertTrue(e.getMessage().contains(
+                    "AtomPub bindings do not support"));
+            return;
+        }
+        // fetch
+        ObjectEntry doc = spi.getObjectByPath("/doc 1", null);
+        assertNotNull(doc);
+        assertEquals("new title", doc.getValue("title"));
+    }
+
+    public void testCopy() throws Exception {
+        ObjectEntry foldid = spi.getObjectByPath("/folder 1", null);
+        Folder fold = (Folder) conn.getObject(foldid);
+
+        ObjectEntry docid = spi.getObjectByPath("/folder 1/folder 2/doc 2",
+                null);
+        Document doc = (Document) conn.getObject(docid);
+        try {
+            Document newdoc = doc.copy(fold);
+            assertNotSame(doc.getId(), newdoc.getId());
+        } catch (CMISRuntimeException e) {
+            assertTrue(e.getMessage().contains(
+                    "AtomPub bindings do not support"));
+            return;
+        }
+        ObjectEntry d = spi.getObjectByPath("/folder 1/doc 2", null);
+        assertNotNull(d);
+        assertEquals("doc 2 title", d.getValue("title"));
+    }
+
     public void testQuery() {
         String rootId = spi.getRepository().getInfo().getRootFolderId().getId();
         String folder1Id = spi.getObjectByPath("/folder 1", null).getId();