chemistry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Laurent Mignon (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (CMIS-972) Implement contentSream and properties update in BrowserDocument.checkin method
Date Fri, 25 Mar 2016 15:41:25 GMT

     [ https://issues.apache.org/jira/browse/CMIS-972?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Laurent Mignon updated CMIS-972:
--------------------------------
    Description: 
I've improved the checkin method to allow to update the content stream and the properties

{code}
diff --git a/src/cmislib/browser/binding.py b/src/cmislib/browser/binding.py
index c9cc8a3..b340eda 100644
--- a/src/cmislib/browser/binding.py
+++ b/src/cmislib/browser/binding.py
@@ -1743,7 +1743,8 @@ class BrowserDocument(BrowserCmisObject):
         self.reload()
         return self.getProperties()['cmis:versionSeriesCheckedOutBy']
 
-    def checkin(self, checkinComment=None, **kwargs):
+    def checkin(self, checkinComment=None, contentFile=None, contentType=None,ntStream
          - policies
          - addACEs
          - removeACEs
         """
-        # TODO implement optional arguments
-        # major = true is supposed to be the default but inmemory 0.9 is throwing an error
500 without it
         if not kwargs.has_key('major'):
             kwargs['major'] = 'true'
+        else:
+            kwargs['major'] = 'false'
+        props = {
+            'checkinComment': checkinComment,
+        }
+        props.update(kwargs)
+        propCount = 0
+        properties = properties or {}
+        for key, value in properties.iteritems():
+            props["propertyId[%s]" % propCount] = key
+            props["propertyValue[%s]" % propCount] = value
+            propCount += 1
 
-        kwargs['checkinComment'] = checkinComment
-
-        ciUrl = self._repository.getRootFolderUrl()
+        ciUrl = self._repository.getRootFolderUrl() + "?objectId=" + self.id + "&cmisaction=checkin"
 
-        # TODO don't hardcode major flag
-        props = {"objectId": self.id,
-                 "cmisaction": "checkIn"}
+        contentType, body = encode_multipart_formdata(props, contentFile, contentType)
 
         # invoke the URL
         result = self._cmisClient.binding.post(ciUrl.encode('utf-8'),
-                                               urlencode(props),
-                                               'application/x-www-form-urlencoded',
+                                               body,
+                                               contentType,
                                                self._cmisClient.username,
-                                               self._cmisClient.password,
-                                               **kwargs)
+                                               self._cmisClient.password)
 
         return getSpecializedObject(BrowserCmisObject(self._cmisClient, self._repository,
data=result))
{code}
https://github.com/lmignon/python-cmislib/commit/c1ff31b82c6768148e18e766a9cbc5d62bfb5b23?diff=unified


  was:
With the dev version of cmislib when using the browser binding. If you provide a properties
dict to the createFolder method, the following error will raise
{code}
  File "../local/lib/python2.7/site-packages/cmislib/browser/binding.py", line 1387, in createFolder
    return parentFolder.createFolder(name, properties, **kwargs)
  File ".../local/lib/python2.7/site-packages/cmislib/browser/binding.py", line 2051, in createFolder
    props["propertyId[%s]" % propCount] = prop.key
AttributeError: 'str' object has no attribute 'key'
{code}

Moreover, the code seems to be not actively developed and the git mirror is outdated. How
can I contribute efficiently. I'll provide a patch as soon as I've finished to mirror your
svn repo to github?

{code}
>From 203330f499a508427a6b3ae7b7b0f402797ecc01 Mon Sep 17 00:00:00 2001
From: Laurent Mignon <laurent.mignon@acsone.eu>
Date: Fri, 18 Mar 2016 18:17:00 +0100
Subject: [PATCH] In createFolder 'properties' param is a dict Fixes CMIS-971
 See https://issues.apache.org/jira/browse/CMIS-971

---
 src/cmislib/browser/binding.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/cmislib/browser/binding.py b/src/cmislib/browser/binding.py
index 79ae297..c9cc8a3 100644
--- a/src/cmislib/browser/binding.py
+++ b/src/cmislib/browser/binding.py
@@ -2043,13 +2043,14 @@ def createFolder(self, name, properties={}, **kwargs):
         props["propertyId[1]"] = "cmis:objectTypeId"
         if properties.has_key('cmis:objectTypeId'):
             props["propertyValue[1]"] = properties['cmis:objectTypeId']
+            del properties['cmis:objectTypeId']
         else:
             props["propertyValue[1]"] = "cmis:folder"
 
         propCount = 2
-        for prop in properties:
-            props["propertyId[%s]" % propCount] = prop.key
-            props["propertyValue[%s]" % propCount] = prop
+        for key, val in properties.items():
+            props["propertyId[%s]" % propCount] = key
+            props["propertyValue[%s]" % propCount] = val
             propCount += 1
 
         # invoke the URL
{code}
see https://github.com/lmignon/python-cmislib/commit/203330f499a508427a6b3ae7b7b0f402797ecc01?diff=unified



> Implement contentSream and properties update in BrowserDocument.checkin method
> ------------------------------------------------------------------------------
>
>                 Key: CMIS-972
>                 URL: https://issues.apache.org/jira/browse/CMIS-972
>             Project: Chemistry
>          Issue Type: Improvement
>          Components: python-cmislib
>         Environment: Linux, python 2.7.x, Alfresco 5.0.x
>            Reporter: Laurent Mignon
>            Assignee: Jeff Potts
>
> I've improved the checkin method to allow to update the content stream and the properties
> {code}
> diff --git a/src/cmislib/browser/binding.py b/src/cmislib/browser/binding.py
> index c9cc8a3..b340eda 100644
> --- a/src/cmislib/browser/binding.py
> +++ b/src/cmislib/browser/binding.py
> @@ -1743,7 +1743,8 @@ class BrowserDocument(BrowserCmisObject):
>          self.reload()
>          return self.getProperties()['cmis:versionSeriesCheckedOutBy']
>  
> -    def checkin(self, checkinComment=None, **kwargs):
> +    def checkin(self, checkinComment=None, contentFile=None, contentType=None,ntStream
>           - policies
>           - addACEs
>           - removeACEs
>          """
> -        # TODO implement optional arguments
> -        # major = true is supposed to be the default but inmemory 0.9 is throwing an
error 500 without it
>          if not kwargs.has_key('major'):
>              kwargs['major'] = 'true'
> +        else:
> +            kwargs['major'] = 'false'
> +        props = {
> +            'checkinComment': checkinComment,
> +        }
> +        props.update(kwargs)
> +        propCount = 0
> +        properties = properties or {}
> +        for key, value in properties.iteritems():
> +            props["propertyId[%s]" % propCount] = key
> +            props["propertyValue[%s]" % propCount] = value
> +            propCount += 1
>  
> -        kwargs['checkinComment'] = checkinComment
> -
> -        ciUrl = self._repository.getRootFolderUrl()
> +        ciUrl = self._repository.getRootFolderUrl() + "?objectId=" + self.id + "&cmisaction=checkin"
>  
> -        # TODO don't hardcode major flag
> -        props = {"objectId": self.id,
> -                 "cmisaction": "checkIn"}
> +        contentType, body = encode_multipart_formdata(props, contentFile, contentType)
>  
>          # invoke the URL
>          result = self._cmisClient.binding.post(ciUrl.encode('utf-8'),
> -                                               urlencode(props),
> -                                               'application/x-www-form-urlencoded',
> +                                               body,
> +                                               contentType,
>                                                 self._cmisClient.username,
> -                                               self._cmisClient.password,
> -                                               **kwargs)
> +                                               self._cmisClient.password)
>  
>          return getSpecializedObject(BrowserCmisObject(self._cmisClient, self._repository,
data=result))
> {code}
> https://github.com/lmignon/python-cmislib/commit/c1ff31b82c6768148e18e766a9cbc5d62bfb5b23?diff=unified



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message