chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1215136 - in /chemistry/opencmis/trunk: chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/ chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/...
Date Fri, 16 Dec 2011 14:12:21 GMT
Author: fmui
Date: Fri Dec 16 14:12:20 2011
New Revision: 1215136

URL: http://svn.apache.org/viewvc?rev=1215136&view=rev
Log:
CMIS-488: creation of unfiled objects via AtomPub

Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/ObjectServiceImpl.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/MultiFilingService.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/ObjectServiceImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/ObjectServiceImpl.java?rev=1215136&r1=1215135&r2=1215136&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/ObjectServiceImpl.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/ObjectServiceImpl.java
Fri Dec 16 14:12:20 2011
@@ -54,6 +54,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
 import org.apache.chemistry.opencmis.commons.impl.Constants;
 import org.apache.chemistry.opencmis.commons.impl.MimeHelper;
 import org.apache.chemistry.opencmis.commons.impl.ReturnVersion;
@@ -84,10 +85,24 @@ public class ObjectServiceImpl extends A
         checkCreateProperties(properties);
 
         // find the link
-        String link = loadLink(repositoryId, folderId, Constants.REL_DOWN, Constants.MEDIATYPE_CHILDREN);
+        String link = null;
 
-        if (link == null) {
-            throwLinkException(repositoryId, folderId, Constants.REL_DOWN, Constants.MEDIATYPE_CHILDREN);
+        if (folderId == null) {
+            // Creation of unfiled objects via AtomPub is not defined in the
+            // CMIS 1.0 specification. This implementation follow the CMIS 1.1
+            // draft and POSTs the document to the Unfiled collection.
+
+            link = loadCollection(repositoryId, Constants.COLLECTION_UNFILED);
+
+            if (link == null) {
+                throw new CmisObjectNotFoundException("Unknown repository or unfiling not
supported!");
+            }
+        } else {
+            link = loadLink(repositoryId, folderId, Constants.REL_DOWN, Constants.MEDIATYPE_CHILDREN);
+
+            if (link == null) {
+                throwLinkException(repositoryId, folderId, Constants.REL_DOWN, Constants.MEDIATYPE_CHILDREN);
+            }
         }
 
         UrlBuilder url = new UrlBuilder(link);
@@ -171,10 +186,24 @@ public class ObjectServiceImpl extends A
         checkCreateProperties(properties);
 
         // find the link
-        String link = loadLink(repositoryId, folderId, Constants.REL_DOWN, Constants.MEDIATYPE_CHILDREN);
+        String link = null;
 
-        if (link == null) {
-            throwLinkException(repositoryId, folderId, Constants.REL_DOWN, Constants.MEDIATYPE_CHILDREN);
+        if (folderId == null) {
+            // Creation of unfiled objects via AtomPub is not defined in the
+            // CMIS 1.0 specification. This implementation follow the CMIS 1.1
+            // draft and POSTs the policy to the Unfiled collection.
+
+            link = loadCollection(repositoryId, Constants.COLLECTION_UNFILED);
+
+            if (link == null) {
+                throw new CmisObjectNotFoundException("Unknown repository or unfiling not
supported!");
+            }
+        } else {
+            link = loadLink(repositoryId, folderId, Constants.REL_DOWN, Constants.MEDIATYPE_CHILDREN);
+
+            if (link == null) {
+                throwLinkException(repositoryId, folderId, Constants.REL_DOWN, Constants.MEDIATYPE_CHILDREN);
+            }
         }
 
         UrlBuilder url = new UrlBuilder(link);

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/MultiFilingService.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/MultiFilingService.java?rev=1215136&r1=1215135&r2=1215136&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/MultiFilingService.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/atompub/MultiFilingService.java
Fri Dec 16 14:12:20 2011
@@ -22,12 +22,14 @@ import static org.apache.chemistry.openc
 import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.compileBaseUrl;
 import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.compileUrl;
 import static org.apache.chemistry.opencmis.server.impl.atompub.AtomPubUtils.writeObjectEntry;
+import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getEnumParameter;
 import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getStringParameter;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.chemistry.opencmis.commons.data.ObjectData;
+import org.apache.chemistry.opencmis.commons.enums.VersioningState;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
 import org.apache.chemistry.opencmis.commons.impl.Constants;
 import org.apache.chemistry.opencmis.commons.impl.UrlBuilder;
@@ -51,9 +53,18 @@ public class MultiFilingService {
         // get parameters
         String removeFrom = getStringParameter(request, Constants.PARAM_REMOVE_FROM);
 
-        AtomEntryParser parser = new AtomEntryParser(request.getInputStream());
+        AtomEntryParser parser = new AtomEntryParser();
+        parser.setIgnoreAtomContentSrc(true); // needed for some clients
+        parser.parse(request.getInputStream());
+
         String objectId = parser.getId();
 
+        if (objectId == null && removeFrom == null) {
+            // create unfiled object
+            createUnfiledObject(context, service, repositoryId, request, response, parser);
+            return;
+        }
+
         // execute
         service.removeObjectFromFolder(repositoryId, objectId, removeFrom, null);
 
@@ -84,4 +95,44 @@ public class MultiFilingService {
         writeObjectEntry(service, entry, object, null, repositoryId, null, null, baseUrl,
true);
         entry.endDocument();
     }
+
+    /**
+     * Create unfiled object.
+     * 
+     * (Creation of unfiled objects via AtomPub is not defined in the CMIS 1.0
+     * specification. This implementation follow the CMIS 1.1 draft.)
+     */
+    private static void createUnfiledObject(CallContext context, CmisService service, String
repositoryId,
+            HttpServletRequest request, HttpServletResponse response, AtomEntryParser parser)
throws Exception {
+        // get additional parameters
+        VersioningState versioningState = getEnumParameter(request, Constants.PARAM_VERSIONIG_STATE,
+                VersioningState.class);
+
+        // create
+        String newObjectId = service.create(repositoryId, parser.getProperties(), null, parser.getContentStream(),
+                versioningState, parser.getPolicyIds(), null);
+
+        ObjectInfo objectInfo = service.getObjectInfo(repositoryId, newObjectId);
+        if (objectInfo == null) {
+            throw new CmisRuntimeException("Object Info is missing!");
+        }
+
+        ObjectData object = objectInfo.getObject();
+        if (object == null) {
+            throw new CmisRuntimeException("Object is null!");
+        }
+
+        // set headers
+        UrlBuilder baseUrl = compileBaseUrl(request, repositoryId);
+
+        response.setStatus(HttpServletResponse.SC_CREATED);
+        response.setContentType(Constants.MEDIATYPE_ENTRY);
+        response.setHeader("Location", compileUrl(baseUrl, RESOURCE_ENTRY, newObjectId));
+
+        // write XML
+        AtomEntry entry = new AtomEntry();
+        entry.startDocument(response.getOutputStream());
+        writeObjectEntry(service, entry, object, null, repositoryId, null, null, baseUrl,
true);
+        entry.endDocument();
+    }
 }



Mime
View raw message