chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmpas...@apache.org
Subject svn commit: r1485107 [3/5] - in /chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client: ./ src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/ src/main/java/org/apache/chemistry/opencmis/client/bindi...
Date Wed, 22 May 2013 07:49:35 GMT
Modified: chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/ObjectServiceImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/ObjectServiceImpl.java?rev=1485107&r1=1485106&r2=1485107&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/ObjectServiceImpl.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/ObjectServiceImpl.java
Wed May 22 07:49:35 2013
@@ -59,9 +59,10 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.impl.MimeHelper;
 import org.apache.chemistry.opencmis.commons.impl.ReturnVersion;
 import org.apache.chemistry.opencmis.commons.impl.UrlBuilder;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.BulkUpdateImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.BulkUpdateObjectIdAndChangeTokenImpl;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl;
 import org.apache.chemistry.opencmis.commons.impl.dataobjects.FailedToDeleteDataImpl;
-import org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectDataImpl;
 import org.apache.chemistry.opencmis.commons.spi.Holder;
 import org.apache.chemistry.opencmis.commons.spi.ObjectService;
 
@@ -106,21 +107,9 @@ public class ObjectServiceImpl extends A
         UrlBuilder url = new UrlBuilder(link);
         url.addParameter(Constants.PARAM_VERSIONIG_STATE, versioningState);
 
-        // set up object and writer
-        ObjectDataImpl object = new ObjectDataImpl();
-        object.setProperties(properties);
-        // TODO
-        // object.setPolicyIds(convertPolicyIds(policies));
-
-        String mediaType = null;
-        InputStream stream = null;
-
-        if (contentStream != null) {
-            mediaType = contentStream.getMimeType();
-            stream = contentStream.getStream();
-        }
-
-        final AtomEntryWriter entryWriter = new AtomEntryWriter(object, mediaType, stream);
+        // set up writer
+        final AtomEntryWriter entryWriter = new AtomEntryWriter(createObject(properties,
policies),
+                getCmisVersion(repositoryId), contentStream);
 
         // post the new folder object
         Response resp = post(url, Constants.MEDIATYPE_ENTRY, new Output() {
@@ -157,13 +146,9 @@ public class ObjectServiceImpl extends A
 
         UrlBuilder url = new UrlBuilder(link);
 
-        // set up object and writer
-        ObjectDataImpl object = new ObjectDataImpl();
-        object.setProperties(properties);
-        // TODO
-        // object.setPolicyIds(convertPolicyIds(policies));
-
-        final AtomEntryWriter entryWriter = new AtomEntryWriter(object);
+        // set up writer
+        final AtomEntryWriter entryWriter = new AtomEntryWriter(createObject(properties,
policies),
+                getCmisVersion(repositoryId));
 
         // post the new folder object
         Response resp = post(url, Constants.MEDIATYPE_ENTRY, new Output() {
@@ -208,13 +193,9 @@ public class ObjectServiceImpl extends A
 
         UrlBuilder url = new UrlBuilder(link);
 
-        // set up object and writer
-        ObjectDataImpl object = new ObjectDataImpl();
-        object.setProperties(properties);
-        // TODO
-        // object.setPolicyIds(convertPolicyIds(policies));
-
-        final AtomEntryWriter entryWriter = new AtomEntryWriter(object);
+        // set up writer
+        final AtomEntryWriter entryWriter = new AtomEntryWriter(createObject(properties,
policies),
+                getCmisVersion(repositoryId));
 
         // post the new folder object
         Response resp = post(url, Constants.MEDIATYPE_ENTRY, new Output() {
@@ -255,13 +236,9 @@ public class ObjectServiceImpl extends A
 
         UrlBuilder url = new UrlBuilder(link);
 
-        // set up object and writer
-        ObjectDataImpl object = new ObjectDataImpl();
-        object.setProperties(properties);
-        // TODO
-        // object.setPolicyIds(convertPolicyIds(policies));
-
-        final AtomEntryWriter entryWriter = new AtomEntryWriter(object);
+        // set up writer
+        final AtomEntryWriter entryWriter = new AtomEntryWriter(createObject(properties,
policies),
+                getCmisVersion(repositoryId));
 
         // post the new folder object
         Response resp = post(url, Constants.MEDIATYPE_ENTRY, new Output() {
@@ -278,7 +255,7 @@ public class ObjectServiceImpl extends A
 
         return entry.getId();
     }
-    
+
     public String createRelationship(String repositoryId, Properties properties, List<String>
policies, Acl addAces,
             Acl removeAces, ExtensionsData extension) {
         checkCreateProperties(properties);
@@ -303,12 +280,9 @@ public class ObjectServiceImpl extends A
 
         UrlBuilder url = new UrlBuilder(link);
 
-        // set up object and writer
-        ObjectDataImpl object = new ObjectDataImpl();
-        object.setProperties(properties);
-        // TODO
-        // object.setPolicyIds(convertPolicyIds(policies));
-        final AtomEntryWriter entryWriter = new AtomEntryWriter(object);
+        // set up writer
+        final AtomEntryWriter entryWriter = new AtomEntryWriter(createObject(properties,
policies),
+                getCmisVersion(repositoryId));
 
         // post the new folder object
         Response resp = post(url, Constants.MEDIATYPE_ENTRY, new Output() {
@@ -326,7 +300,6 @@ public class ObjectServiceImpl extends A
         return entry.getId();
     }
 
-    @SuppressWarnings("rawtypes")
     public void updateProperties(String repositoryId, Holder<String> objectId, Holder<String>
changeToken,
             Properties properties, ExtensionsData extension) {
         // we need an object id
@@ -346,13 +319,9 @@ public class ObjectServiceImpl extends A
             url.addParameter(Constants.PARAM_CHANGE_TOKEN, changeToken.getValue());
         }
 
-        // set up object and writer
-        ObjectDataImpl object = new ObjectDataImpl();
-        object.setProperties(properties);
-        // TODO
-        // object.setPolicyIds(convertPolicyIds(policies));
-
-        final AtomEntryWriter entryWriter = new AtomEntryWriter(object);
+        // set up writer
+        final AtomEntryWriter entryWriter = new AtomEntryWriter(createObject(properties,
null),
+                getCmisVersion(repositoryId));
 
         // update
         Response resp = put(url, Constants.MEDIATYPE_ENTRY, new Output() {
@@ -388,20 +357,13 @@ public class ObjectServiceImpl extends A
                 } else if (element.getObject() instanceof ObjectData) {
                     // extract new change token
                     if (changeToken != null) {
-                        object = (ObjectDataImpl) element.getObject();
+                        ObjectData object = (ObjectData) element.getObject();
 
                         if (object.getProperties() != null) {
-                            for (PropertyData property : object.getProperties().getPropertyList())
{
-                                if (PropertyIds.CHANGE_TOKEN.equals(property.getId())
-                                        && (property instanceof PropertyString))
{
-
-                                    PropertyString changeTokenProperty = (PropertyString)
property;
-                                    if (changeTokenProperty.getFirstValue() != null &&
changeTokenProperty.getFirstValue().length() > 0) {
-                                        changeToken.setValue(changeTokenProperty.getFirstValue());
-                                    }
-
-                                    break;
-                                }
+                            Object changeTokenStr = object.getProperties().getProperties()
+                                    .get(PropertyIds.CHANGE_TOKEN);
+                            if (changeTokenStr instanceof PropertyString) {
+                                changeToken.setValue(((PropertyString) changeTokenStr).getFirstValue());
                             }
                         }
                     }
@@ -415,7 +377,60 @@ public class ObjectServiceImpl extends A
     public List<BulkUpdateObjectIdAndChangeToken> bulkUpdateProperties(String repositoryId,
             List<BulkUpdateObjectIdAndChangeToken> objectIdAndChangeToken, Properties
properties,
             List<String> addSecondaryTypeIds, List<String> removeSecondaryTypeIds,
ExtensionsData extension) {
-        throw new CmisNotSupportedException("Not supported!");
+        // find link
+        String link = loadCollection(repositoryId, Constants.COLLECTION_BULK_UPDATE);
+
+        if (link == null) {
+            throw new CmisObjectNotFoundException("Unknown repository or bulk update properties
is not supported!");
+        }
+
+        // set up writer
+        final BulkUpdateImpl bulkUpdate = new BulkUpdateImpl();
+        bulkUpdate.setObjectIdAndChangeToken(objectIdAndChangeToken);
+        bulkUpdate.setProperties(properties);
+        bulkUpdate.setAddSecondaryTypeIds(addSecondaryTypeIds);
+        bulkUpdate.setRemoveSecondaryTypeIds(removeSecondaryTypeIds);
+
+        final AtomEntryWriter entryWriter = new AtomEntryWriter(bulkUpdate);
+
+        // post the new folder object
+        Response resp = post(new UrlBuilder(link), Constants.MEDIATYPE_ENTRY, new Output()
{
+            public void write(OutputStream out) throws Exception {
+                entryWriter.write(out);
+            }
+        });
+
+        AtomFeed feed = parse(resp.getStream(), AtomFeed.class);
+        List<BulkUpdateObjectIdAndChangeToken> result = new ArrayList<BulkUpdateObjectIdAndChangeToken>(feed
+                .getEntries().size());
+
+        // get the results
+        if (!feed.getEntries().isEmpty()) {
+
+            for (AtomEntry entry : feed.getEntries()) {
+                // walk through the entry
+                // we are not interested in the links this time because they
+                // could belong to a new document version
+                for (AtomElement element : entry.getElements()) {
+                    if (element.getObject() instanceof ObjectData) {
+                        ObjectData object = (ObjectData) element.getObject();
+                        String id = object.getId();
+                        if (id != null) {
+                            String changeToken = null;
+                            PropertyData<?> changeTokenProp = object.getProperties().getProperties()
+                                    .get(PropertyIds.CHANGE_TOKEN);
+                            if (changeTokenProp instanceof PropertyString) {
+                                changeToken = ((PropertyString) changeTokenProp).getFirstValue();
+                            }
+
+                            result.add(new BulkUpdateObjectIdAndChangeTokenImpl(id, changeToken));
+                        }
+                    }
+                }
+            }
+        }
+
+        return result;
     }
 
     public void deleteObject(String repositoryId, String objectId, Boolean allVersions, ExtensionsData
extension) {
@@ -436,14 +451,28 @@ public class ObjectServiceImpl extends A
     public FailedToDeleteData deleteTree(String repositoryId, String folderId, Boolean allVersions,
             UnfileObject unfileObjects, Boolean continueOnFailure, ExtensionsData extension)
{
 
-        // find the link
-        String link = loadLink(repositoryId, folderId, Constants.REL_DOWN, Constants.MEDIATYPE_DESCENDANTS);
+        // find the down links
+        String link = loadLink(repositoryId, folderId, Constants.REL_DOWN, null);
+
+        if (link != null) {
+            // found only a children link, but no descendants link
+            // -> try folder tree link
+            link = null;
+        } else {
+            // found no or two down links
+            // -> get only the descendants link
+            link = loadLink(repositoryId, folderId, Constants.REL_DOWN, Constants.MEDIATYPE_DESCENDANTS);
+        }
 
         if (link == null) {
             link = loadLink(repositoryId, folderId, Constants.REL_FOLDERTREE, Constants.MEDIATYPE_DESCENDANTS);
         }
 
         if (link == null) {
+            link = loadLink(repositoryId, folderId, Constants.REL_FOLDERTREE, Constants.MEDIATYPE_FEED);
+        }
+
+        if (link == null) {
             throwLinkException(repositoryId, folderId, Constants.REL_DOWN, Constants.MEDIATYPE_DESCENDANTS);
         }
 
@@ -560,11 +589,6 @@ public class ObjectServiceImpl extends A
         return result;
     }
 
-    public void appendContentStream(String repositoryId, Holder<String> objectId, Holder<String>
changeToken,
-            ContentStream contentStream, boolean isLastChunk, ExtensionsData extension) {
-        throw new CmisNotSupportedException("Not supported!");
-    }    
-    
     public ObjectData getObject(String repositoryId, String objectId, String filter, Boolean
includeAllowableActions,
             IncludeRelationships includeRelationships, String renditionFilter, Boolean includePolicyIds,
             Boolean includeACL, ExtensionsData extension) {
@@ -624,7 +648,8 @@ public class ObjectServiceImpl extends A
         url.addParameter(Constants.PARAM_SOURCE_FOLDER_ID, sourceFolderId);
 
         // set up object and writer
-        final AtomEntryWriter entryWriter = new AtomEntryWriter(createIdObject(objectId.getValue()));
+        final AtomEntryWriter entryWriter = new AtomEntryWriter(createIdObject(objectId.getValue()),
+                getCmisVersion(repositoryId));
 
         // post move request
         Response resp = post(url, Constants.MEDIATYPE_ENTRY, new Output() {
@@ -641,64 +666,7 @@ public class ObjectServiceImpl extends A
 
     public void setContentStream(String repositoryId, Holder<String> objectId, Boolean
overwriteFlag,
             Holder<String> changeToken, ContentStream contentStream, ExtensionsData
extension) {
-        // we need an object id
-        if ((objectId == null) || (objectId.getValue() == null)) {
-            throw new CmisInvalidArgumentException("Object ID must be set!");
-        }
-
-        // we need content
-        if ((contentStream == null) || (contentStream.getStream() == null) || (contentStream.getMimeType()
== null)) {
-            throw new CmisInvalidArgumentException("Content must be set!");
-        }
-
-        // find the link
-        String link = loadLink(repositoryId, objectId.getValue(), Constants.REL_EDITMEDIA,
null);
-
-        if (link == null) {
-            throwLinkException(repositoryId, objectId.getValue(), Constants.REL_EDITMEDIA,
null);
-        }
-
-        UrlBuilder url = new UrlBuilder(link);
-        if (changeToken != null) {
-            url.addParameter(Constants.PARAM_CHANGE_TOKEN, changeToken.getValue());
-        }
-        url.addParameter(Constants.PARAM_OVERWRITE_FLAG, overwriteFlag);
-
-        final InputStream stream = contentStream.getStream();
-
-        // Content-Disposition header for the filename
-        Map<String, String> headers = null;
-        if (contentStream.getFileName() != null) {
-            headers = Collections
-                    .singletonMap(
-                            MimeHelper.CONTENT_DISPOSITION,
-                            MimeHelper.encodeContentDisposition(MimeHelper.DISPOSITION_ATTACHMENT,
-                                    contentStream.getFileName()));
-        }
-
-        // send content
-        Response resp = put(url, contentStream.getMimeType(), headers, new Output() {
-            public void write(OutputStream out) throws Exception {
-                int b;
-                byte[] buffer = new byte[4096];
-
-                while ((b = stream.read(buffer)) > -1) {
-                    out.write(buffer, 0, b);
-                }
-
-                stream.close();
-            }
-        });
-
-        // check response code further
-        if ((resp.getResponseCode() != 200) && (resp.getResponseCode() != 201) &&
(resp.getResponseCode() != 204)) {
-            throw convertStatusCode(resp.getResponseCode(), resp.getResponseMessage(), resp.getErrorContent(),
null);
-        }
-
-        objectId.setValue(null);
-        if (changeToken != null) {
-            changeToken.setValue(null);
-        }
+        setOrAppendContent(repositoryId, objectId, overwriteFlag, changeToken, contentStream,
true, false, extension);
     }
 
     public void deleteContentStream(String repositoryId, Holder<String> objectId, Holder<String>
changeToken,
@@ -728,6 +696,11 @@ public class ObjectServiceImpl extends A
         }
     }
 
+    public void appendContentStream(String repositoryId, Holder<String> objectId, Holder<String>
changeToken,
+            ContentStream contentStream, boolean isLastChunk, ExtensionsData extension) {
+        setOrAppendContent(repositoryId, objectId, null, changeToken, contentStream, isLastChunk,
true, extension);
+    }
+
     // ---- internal ----
 
     private static void checkCreateProperties(Properties properties) {
@@ -762,4 +735,74 @@ public class ObjectServiceImpl extends A
             }
         }
     }
+
+    /**
+     * Sets or appends content.
+     */
+    private void setOrAppendContent(String repositoryId, Holder<String> objectId, Boolean
overwriteFlag,
+            Holder<String> changeToken, ContentStream contentStream, boolean isLastChunk,
boolean append,
+            ExtensionsData extension) {
+        // we need an object id
+        if ((objectId == null) || (objectId.getValue() == null)) {
+            throw new CmisInvalidArgumentException("Object ID must be set!");
+        }
+
+        // we need content
+        if ((contentStream == null) || (contentStream.getStream() == null) || (contentStream.getMimeType()
== null)) {
+            throw new CmisInvalidArgumentException("Content must be set!");
+        }
+
+        // find the link
+        String link = loadLink(repositoryId, objectId.getValue(), Constants.REL_EDITMEDIA,
null);
+
+        if (link == null) {
+            throwLinkException(repositoryId, objectId.getValue(), Constants.REL_EDITMEDIA,
null);
+        }
+
+        UrlBuilder url = new UrlBuilder(link);
+        if (changeToken != null) {
+            url.addParameter(Constants.PARAM_CHANGE_TOKEN, changeToken.getValue());
+        }
+
+        if (append) {
+            url.addParameter(Constants.PARAM_APPEND, Boolean.TRUE);
+            url.addParameter(Constants.PARAM_IS_LAST_CHUNK, isLastChunk);
+        } else {
+            url.addParameter(Constants.PARAM_OVERWRITE_FLAG, overwriteFlag);
+        }
+
+        final InputStream stream = contentStream.getStream();
+
+        // Content-Disposition header for the filename
+        Map<String, String> headers = null;
+        if (contentStream.getFileName() != null) {
+            headers = Collections
+                    .singletonMap(
+                            MimeHelper.CONTENT_DISPOSITION,
+                            MimeHelper.encodeContentDisposition(MimeHelper.DISPOSITION_ATTACHMENT,
+                                    contentStream.getFileName()));
+        }
+
+        // send content
+        Response resp = put(url, contentStream.getMimeType(), headers, new Output() {
+            public void write(OutputStream out) throws Exception {
+                int b;
+                byte[] buffer = new byte[4096];
+
+                while ((b = stream.read(buffer)) > -1) {
+                    out.write(buffer, 0, b);
+                }
+            }
+        });
+
+        // check response code further
+        if ((resp.getResponseCode() != 200) && (resp.getResponseCode() != 201) &&
(resp.getResponseCode() != 204)) {
+            throw convertStatusCode(resp.getResponseCode(), resp.getResponseMessage(), resp.getErrorContent(),
null);
+        }
+
+        objectId.setValue(null);
+        if (changeToken != null) {
+            changeToken.setValue(null);
+        }
+    }
 }

Modified: chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/PolicyServiceImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/PolicyServiceImpl.java?rev=1485107&r1=1485106&r2=1485107&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/PolicyServiceImpl.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/PolicyServiceImpl.java
Wed May 22 07:49:35 2013
@@ -32,8 +32,6 @@ import org.apache.chemistry.opencmis.cli
 import org.apache.chemistry.opencmis.commons.PropertyIds;
 import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
 import org.apache.chemistry.opencmis.commons.data.ObjectData;
-import org.apache.chemistry.opencmis.commons.data.PropertyData;
-import org.apache.chemistry.opencmis.commons.data.PropertyId;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
 import org.apache.chemistry.opencmis.commons.impl.Constants;
 import org.apache.chemistry.opencmis.commons.impl.UrlBuilder;
@@ -62,7 +60,7 @@ public class PolicyServiceImpl extends A
         UrlBuilder url = new UrlBuilder(link);
 
         // set up object and writer
-        final AtomEntryWriter entryWriter = new AtomEntryWriter(createIdObject(objectId));
+        final AtomEntryWriter entryWriter = new AtomEntryWriter(createIdObject(objectId),
getCmisVersion(repositoryId));
 
         // post applyPolicy request
         post(url, Constants.MEDIATYPE_ENTRY, new Output() {
@@ -145,7 +143,7 @@ public class PolicyServiceImpl extends A
                             policyLink = atomLink.getHref();
                         }
                     } else if (element.getObject() instanceof ObjectData) {
-                        String id = findIdProperty((ObjectData) element.getObject());
+                        String id = ((ObjectData) element.getObject()).getId();
                         if (policyId.equals(id)) {
                             found = true;
                         }
@@ -163,24 +161,4 @@ public class PolicyServiceImpl extends A
             delete(new UrlBuilder(policyLink));
         }
     }
-
-    /**
-     * Finds the id property within a CMIS object.
-     */
-    private static String findIdProperty(ObjectData object) {
-        if ((object == null) || (object.getProperties() == null)) {
-            return null;
-        }
-
-        for (PropertyData<?> property : object.getProperties().getPropertyList()) {
-            if (PropertyIds.OBJECT_ID.equals(property.getId()) && (property instanceof
PropertyId)) {
-                List<String> values = ((PropertyId) property).getValues();
-                if (values.size() == 1) {
-                    return values.get(0);
-                }
-            }
-        }
-
-        return null;
-    }
 }

Modified: chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/RepositoryServiceImpl.java?rev=1485107&r1=1485106&r2=1485107&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/RepositoryServiceImpl.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/RepositoryServiceImpl.java
Wed May 22 07:49:35 2013
@@ -18,22 +18,29 @@
  */
 package org.apache.chemistry.opencmis.client.bindings.spi.atompub;
 
+import java.io.OutputStream;
 import java.math.BigInteger;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
+import org.apache.chemistry.opencmis.client.bindings.impl.CmisBindingsHelper;
 import org.apache.chemistry.opencmis.client.bindings.spi.BindingSession;
 import org.apache.chemistry.opencmis.client.bindings.spi.atompub.objects.AtomElement;
 import org.apache.chemistry.opencmis.client.bindings.spi.atompub.objects.AtomEntry;
 import org.apache.chemistry.opencmis.client.bindings.spi.atompub.objects.AtomFeed;
 import org.apache.chemistry.opencmis.client.bindings.spi.atompub.objects.AtomLink;
+import org.apache.chemistry.opencmis.client.bindings.spi.http.HttpInvoker;
+import org.apache.chemistry.opencmis.client.bindings.spi.http.Output;
 import org.apache.chemistry.opencmis.client.bindings.spi.http.Response;
 import org.apache.chemistry.opencmis.commons.data.ExtensionsData;
 import org.apache.chemistry.opencmis.commons.data.RepositoryInfo;
 import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
 import org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionContainer;
 import org.apache.chemistry.opencmis.commons.definitions.TypeDefinitionList;
-import org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
 import org.apache.chemistry.opencmis.commons.impl.Constants;
 import org.apache.chemistry.opencmis.commons.impl.UrlBuilder;
@@ -60,6 +67,14 @@ public class RepositoryServiceImpl exten
     public RepositoryInfo getRepositoryInfo(String repositoryId, ExtensionsData extension)
{
         List<RepositoryInfo> repositoryInfos = getRepositoriesInternal(repositoryId);
 
+        if (repositoryInfos.size() == 0) {
+            throw new CmisObjectNotFoundException("Repository '" + repositoryId + "'not found!");
+        }
+
+        if (repositoryInfos.size() == 1) {
+            return repositoryInfos.get(0);
+        }
+
         // find the repository
         for (RepositoryInfo info : repositoryInfos) {
             if (info.getId() == null) {
@@ -71,7 +86,7 @@ public class RepositoryServiceImpl exten
             }
         }
 
-        throw new CmisObjectNotFoundException("Repository not found!");
+        throw new CmisObjectNotFoundException("Repository '" + repositoryId + "'not found!");
     }
 
     public TypeDefinition getTypeDefinition(String repositoryId, String typeId, ExtensionsData
extension) {
@@ -95,7 +110,6 @@ public class RepositoryServiceImpl exten
         }
 
         UrlBuilder url = new UrlBuilder(link);
-        url.addParameter(Constants.PARAM_TYPE_ID, typeId);
         url.addParameter(Constants.PARAM_PROPERTY_DEFINITIONS, includePropertyDefinitions);
         url.addParameter(Constants.PARAM_MAX_ITEMS, maxItems);
         url.addParameter(Constants.PARAM_SKIP_COUNT, skipCount);
@@ -162,7 +176,6 @@ public class RepositoryServiceImpl exten
         }
 
         UrlBuilder url = new UrlBuilder(link);
-        url.addParameter(Constants.PARAM_TYPE_ID, typeId);
         url.addParameter(Constants.PARAM_DEPTH, depth);
         url.addParameter(Constants.PARAM_PROPERTY_DEFINITIONS, includePropertyDefinitions);
 
@@ -211,16 +224,130 @@ public class RepositoryServiceImpl exten
             }
         }
     }
-    
+
     public TypeDefinition createType(String repositoryId, TypeDefinition type, ExtensionsData
extension) {
-        throw new CmisNotSupportedException("Not supported!");
+        if (type == null) {
+            throw new CmisInvalidArgumentException("Type definition must be set!");
+        }
+
+        String parentId = type.getParentTypeId();
+        if (parentId == null) {
+            throw new CmisInvalidArgumentException("Type definition has no parent type id!");
+        }
+
+        // find the link
+        String link = loadTypeLink(repositoryId, parentId, Constants.REL_DOWN, Constants.MEDIATYPE_CHILDREN);
+
+        if (link == null) {
+            throw new CmisObjectNotFoundException("Unknown repository or parent type!");
+        }
+
+        // set up writer
+        final AtomEntryWriter entryWriter = new AtomEntryWriter(type, getCmisVersion(repositoryId));
+
+        // post the new type definition
+        Response resp = post(new UrlBuilder(link), Constants.MEDIATYPE_ENTRY, new Output()
{
+            public void write(OutputStream out) throws Exception {
+                entryWriter.write(out);
+            }
+        });
+
+        // parse the response
+        AtomEntry entry = parse(resp.getStream(), AtomEntry.class);
+
+        // we expect a CMIS entry
+        if (entry.getId() == null) {
+            throw new CmisConnectionException("Received Atom entry is not a CMIS entry!");
+        }
+
+        lockTypeLinks();
+        TypeDefinition result = null;
+        try {
+            // clean up cache
+            removeTypeLinks(repositoryId, entry.getId());
+
+            // walk through the entry
+            for (AtomElement element : entry.getElements()) {
+                if (element.getObject() instanceof AtomLink) {
+                    addTypeLink(repositoryId, entry.getId(), (AtomLink) element.getObject());
+                } else if (element.getObject() instanceof TypeDefinition) {
+                    result = (TypeDefinition) element.getObject();
+                }
+            }
+        } finally {
+            unlockTypeLinks();
+        }
+
+        return result;
     }
 
     public TypeDefinition updateType(String repositoryId, TypeDefinition type, ExtensionsData
extension) {
-        throw new CmisNotSupportedException("Not supported!");
+        if (type == null) {
+            throw new CmisInvalidArgumentException("Type definition must be set!");
+        }
+
+        String typeId = type.getId();
+        if (typeId == null) {
+            throw new CmisInvalidArgumentException("Type definition has no type id!");
+        }
+
+        // find the link
+        Map<String, Object> parameters = new HashMap<String, Object>();
+        parameters.put(Constants.PARAM_ID, typeId);
+
+        String link = loadTemplateLink(repositoryId, Constants.TEMPLATE_TYPE_BY_ID, parameters);
+        if (link == null) {
+            throw new CmisObjectNotFoundException("Unknown repository or type!");
+        }
+
+        // set up writer
+        final AtomEntryWriter entryWriter = new AtomEntryWriter(type, getCmisVersion(repositoryId));
+
+        // post the new type definition
+        Response resp = put(new UrlBuilder(link), Constants.MEDIATYPE_ENTRY, new Output()
{
+            public void write(OutputStream out) throws Exception {
+                entryWriter.write(out);
+            }
+        });
+
+        // parse the response
+        AtomEntry entry = parse(resp.getStream(), AtomEntry.class);
+
+        // we expect a CMIS entry
+        if (entry.getId() == null) {
+            throw new CmisConnectionException("Received Atom entry is not a CMIS entry!");
+        }
+
+        lockTypeLinks();
+        TypeDefinition result = null;
+        try {
+            // clean up cache
+            removeTypeLinks(repositoryId, entry.getId());
+
+            // walk through the entry
+            for (AtomElement element : entry.getElements()) {
+                if (element.getObject() instanceof AtomLink) {
+                    addTypeLink(repositoryId, entry.getId(), (AtomLink) element.getObject());
+                } else if (element.getObject() instanceof TypeDefinition) {
+                    result = (TypeDefinition) element.getObject();
+                }
+            }
+        } finally {
+            unlockTypeLinks();
+        }
+
+        return result;
     }
 
     public void deleteType(String repositoryId, String typeId, ExtensionsData extension)
{
-        throw new CmisNotSupportedException("Not supported!");
+        Map<String, Object> parameters = new HashMap<String, Object>();
+        parameters.put(Constants.PARAM_ID, typeId);
+
+        String link = loadTemplateLink(repositoryId, Constants.TEMPLATE_TYPE_BY_ID, parameters);
+        if (link == null) {
+            throw new CmisObjectNotFoundException("Unknown repository!");
+        }
+
+        delete(new UrlBuilder(link));
     }
 }

Modified: chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/VersioningServiceImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/VersioningServiceImpl.java?rev=1485107&r1=1485106&r2=1485107&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/VersioningServiceImpl.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/VersioningServiceImpl.java
Wed May 22 07:49:35 2013
@@ -18,7 +18,6 @@
  */
 package org.apache.chemistry.opencmis.client.bindings.spi.atompub;
 
-import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.List;
@@ -42,8 +41,7 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.impl.Constants;
 import org.apache.chemistry.opencmis.commons.impl.ReturnVersion;
 import org.apache.chemistry.opencmis.commons.impl.UrlBuilder;
-import org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectDataImpl;
-import org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.AccessControlListImpl;
 import org.apache.chemistry.opencmis.commons.spi.Holder;
 import org.apache.chemistry.opencmis.commons.spi.VersioningService;
 
@@ -75,7 +73,8 @@ public class VersioningServiceImpl exten
         UrlBuilder url = new UrlBuilder(link);
 
         // set up object and writer
-        final AtomEntryWriter entryWriter = new AtomEntryWriter(createIdObject(objectId.getValue()));
+        final AtomEntryWriter entryWriter = new AtomEntryWriter(createIdObject(objectId.getValue()),
+                getCmisVersion(repositoryId));
 
         // post move request
         Response resp = post(url, Constants.MEDIATYPE_ENTRY, new Output() {
@@ -127,7 +126,6 @@ public class VersioningServiceImpl exten
         delete(new UrlBuilder(link));
     }
 
-    @SuppressWarnings("unused")
     public void checkIn(String repositoryId, Holder<String> objectId, Boolean major,
Properties properties,
             ContentStream contentStream, String checkinComment, List<String> policies,
Acl addAces, Acl removeAces,
             ExtensionsData extension) {
@@ -155,24 +153,9 @@ public class VersioningServiceImpl exten
         url.addParameter(Constants.PARAM_MAJOR, major);
         url.addParameter(Constants.PARAM_CHECK_IN, "true");
 
-        // set up object and writer
-        ObjectDataImpl object = new ObjectDataImpl();
-        object.setProperties(properties);
-        // object.setPolicyIds(convertPolicyIds(policies));
-
-        if (object.getProperties() == null) {
-            object.setProperties(new PropertiesImpl());
-        }
-
-        String mediaType = null;
-        InputStream stream = null;
-
-        if (contentStream != null) {
-            mediaType = contentStream.getMimeType();
-            stream = contentStream.getStream();
-        }
-
-        final AtomEntryWriter entryWriter = new AtomEntryWriter(object, mediaType, stream);
+        // set up writer
+        final AtomEntryWriter entryWriter = new AtomEntryWriter(createObject(properties,
policies),
+                getCmisVersion(repositoryId), contentStream);
 
         // update
         Response resp = put(url, Constants.MEDIATYPE_ENTRY, new Output() {
@@ -192,7 +175,7 @@ public class VersioningServiceImpl exten
         // set object id
         objectId.setValue(entry.getId());
 
-        Acl originalAces = null;
+        AccessControlListImpl originalAces = null;
 
         lockLinks();
         try {
@@ -205,10 +188,11 @@ public class VersioningServiceImpl exten
                     addLink(repositoryId, entry.getId(), (AtomLink) element.getObject());
                 } else if (element.getObject() instanceof ObjectData) {
                     // extract current ACL
-                    // TODO Update This part for Android.
-                    object = (ObjectDataImpl) element.getObject();
-                    // originalAces = convert(object.getAcl(),
-                    // object.isExactACL());
+                    ObjectData object = (ObjectData) element.getObject();
+                    if (object.getAcl() != null) {
+                        originalAces = new AccessControlListImpl(object.getAcl().getAces());
+                        originalAces.setExact(object.isExactAcl());
+                    }
                 }
             }
         } finally {

Modified: chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/objects/AtomElement.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/objects/AtomElement.java?rev=1485107&r1=1485106&r2=1485107&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/objects/AtomElement.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/objects/AtomElement.java
Wed May 22 07:49:35 2013
@@ -23,7 +23,8 @@ import java.io.Serializable;
 import javax.xml.namespace.QName;
 
 /**
- * Atom element.
+ * @author <a href="mailto:fmueller@opentext.com">Florian M&uuml;ller</a>
+ * 
  */
 public class AtomElement implements Serializable {
 

Added: chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/DefaultHttpInvoker.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/DefaultHttpInvoker.java?rev=1485107&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/DefaultHttpInvoker.java
(added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/DefaultHttpInvoker.java
Wed May 22 07:49:35 2013
@@ -0,0 +1,218 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.client.bindings.spi.http;
+
+import java.io.BufferedOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.math.BigInteger;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+import java.util.zip.GZIPOutputStream;
+
+import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLSocketFactory;
+
+import org.apache.chemistry.opencmis.client.bindings.impl.ClientVersion;
+import org.apache.chemistry.opencmis.client.bindings.impl.CmisBindingsHelper;
+import org.apache.chemistry.opencmis.client.bindings.spi.BindingSession;
+import org.apache.chemistry.opencmis.commons.SessionParameter;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException;
+import org.apache.chemistry.opencmis.commons.impl.UrlBuilder;
+import org.apache.chemistry.opencmis.commons.spi.AuthenticationProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class DefaultHttpInvoker implements HttpInvoker {
+
+    private static final Logger LOG = LoggerFactory.getLogger(DefaultHttpInvoker.class);
+
+    private static final int BUFFER_SIZE = 2 * 1024 * 1024;
+
+    public DefaultHttpInvoker() {
+    }
+
+    public Response invokeGET(UrlBuilder url, BindingSession session) {
+        return invoke(url, "GET", null, null, null, session, null, null);
+    }
+
+    public Response invokeGET(UrlBuilder url, BindingSession session, BigInteger offset,
BigInteger length) {
+        return invoke(url, "GET", null, null, null, session, offset, length);
+    }
+
+    public Response invokePOST(UrlBuilder url, String contentType, Output writer, BindingSession
session) {
+        return invoke(url, "POST", contentType, null, writer, session, null, null);
+    }
+
+    public Response invokePUT(UrlBuilder url, String contentType, Map<String, String>
headers, Output writer,
+            BindingSession session) {
+        return invoke(url, "PUT", contentType, headers, writer, session, null, null);
+    }
+
+    public Response invokeDELETE(UrlBuilder url, BindingSession session) {
+        return invoke(url, "DELETE", null, null, null, session, null, null);
+    }
+
+    private Response invoke(UrlBuilder url, String method, String contentType, Map<String,
String> headers,
+            Output writer, BindingSession session, BigInteger offset, BigInteger length)
{
+        try {
+            // log before connect
+            if (LOG.isDebugEnabled()) {
+                LOG.debug(method + " " + url);
+            }
+
+            // connect
+            HttpURLConnection conn = (HttpURLConnection) (new URL(url.toString())).openConnection();
+            conn.setRequestMethod(method);
+            conn.setDoInput(true);
+            conn.setDoOutput(writer != null);
+            conn.setAllowUserInteraction(false);
+            conn.setUseCaches(false);
+            conn.setRequestProperty("User-Agent", ClientVersion.OPENCMIS_CLIENT);
+
+            // timeouts
+            int connectTimeout = session.get(SessionParameter.CONNECT_TIMEOUT, -1);
+            if (connectTimeout >= 0) {
+                conn.setConnectTimeout(connectTimeout);
+            }
+
+            int readTimeout = session.get(SessionParameter.READ_TIMEOUT, -1);
+            if (readTimeout >= 0) {
+                conn.setReadTimeout(readTimeout);
+            }
+
+            // set content type
+            if (contentType != null) {
+                conn.setRequestProperty("Content-Type", contentType);
+            }
+            // set other headers
+            if (headers != null) {
+                for (Map.Entry<String, String> header : headers.entrySet()) {
+                    conn.addRequestProperty(header.getKey(), header.getValue());
+                }
+            }
+
+            // authenticate
+            AuthenticationProvider authProvider = CmisBindingsHelper.getAuthenticationProvider(session);
+            if (authProvider != null) {
+                Map<String, List<String>> httpHeaders = authProvider.getHTTPHeaders(url.toString());
+                if (httpHeaders != null) {
+                    for (Map.Entry<String, List<String>> header : httpHeaders.entrySet())
{
+                        if (header.getValue() != null) {
+                            for (String value : header.getValue()) {
+                                conn.addRequestProperty(header.getKey(), value);
+                            }
+                        }
+                    }
+                }
+
+                if (conn instanceof HttpsURLConnection) {
+                    SSLSocketFactory sf = authProvider.getSSLSocketFactory();
+                    if (sf != null) {
+                        ((HttpsURLConnection) conn).setSSLSocketFactory(sf);
+                    }
+
+                    HostnameVerifier hv = authProvider.getHostnameVerifier();
+                    if (hv != null) {
+                        ((HttpsURLConnection) conn).setHostnameVerifier(hv);
+                    }
+                }
+            }
+
+            // range
+            if ((offset != null) || (length != null)) {
+                StringBuilder sb = new StringBuilder("bytes=");
+
+                if ((offset == null) || (offset.signum() == -1)) {
+                    offset = BigInteger.ZERO;
+                }
+
+                sb.append(offset.toString());
+                sb.append("-");
+
+                if ((length != null) && (length.signum() == 1)) {
+                    sb.append(offset.add(length.subtract(BigInteger.ONE)).toString());
+                }
+
+                conn.setRequestProperty("Range", sb.toString());
+            }
+
+            // compression
+            Object compression = session.get(SessionParameter.COMPRESSION);
+            if ((compression != null) && Boolean.parseBoolean(compression.toString()))
{
+                conn.setRequestProperty("Accept-Encoding", "gzip,deflate");
+            }
+
+            // locale
+            if (session.get(CmisBindingsHelper.ACCEPT_LANGUAGE) instanceof String) {
+                conn.setRequestProperty("Accept-Language", session.get(CmisBindingsHelper.ACCEPT_LANGUAGE).toString());
+            }
+
+            // send data
+            if (writer != null) {
+                
+                //Not supported with All server.
+                //conn.setChunkedStreamingMode((64 * 1024) - 1);
+
+                OutputStream connOut = null;
+
+                Object clientCompression = session.get(SessionParameter.CLIENT_COMPRESSION);
+                if ((clientCompression != null) && Boolean.parseBoolean(clientCompression.toString()))
{
+                    conn.setRequestProperty("Content-Encoding", "gzip");
+                    connOut = new GZIPOutputStream(conn.getOutputStream(), 4096);
+                } else {
+                    connOut = conn.getOutputStream();
+                }
+
+                OutputStream out = new BufferedOutputStream(connOut, BUFFER_SIZE);
+                writer.write(out);
+                out.flush();
+            }
+
+            // connect
+            conn.connect();
+
+            // get stream, if present
+            int respCode = conn.getResponseCode();
+            InputStream inputStream = null;
+            if ((respCode == 200) || (respCode == 201) || (respCode == 203) || (respCode
== 206)) {
+                inputStream = conn.getInputStream();
+            }
+
+            // log after connect
+            if (LOG.isTraceEnabled()) {
+                LOG.trace(method + " " + url + " > Headers: " + conn.getHeaderFields());
+            }
+
+            // forward response HTTP headers
+            if (authProvider != null) {
+                authProvider.putResponseHeaders(url.toString(), respCode, conn.getHeaderFields());
+            }
+
+            // get the response
+            return new Response(respCode, conn.getResponseMessage(), conn.getHeaderFields(),
inputStream,
+                    conn.getErrorStream());
+        } catch (Exception e) {
+            throw new CmisConnectionException("Cannot access " + url + ": " + e.getMessage(),
e);
+        }
+    }
+}



Mime
View raw message