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-979) Allow to use multi valued values in properties when using the Browser Binding
Date Wed, 11 May 2016 16:20:13 GMT

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

Laurent Mignon updated CMIS-979:
--------------------------------
    Description: 
The browser binding on the trunk doesn't support multi valued values for properties.
{code}
diff --git a/src/cmislib/browser/binding.py b/src/cmislib/browser/binding.py
index b340eda..8565be0 100644
--- a/src/cmislib/browser/binding.py
+++ b/src/cmislib/browser/binding.py
@@ -352,13 +352,7 @@ class BrowserCmisObject(object):
         updateUrl = self._repository.getRootFolderUrl() + "?objectId=" + self.id
 
         props = {"cmisaction": "update"}
-
-        propCount = 0
-        for prop in properties:
-            props["propertyId[%s]" % propCount] = prop
-            props["propertyValue[%s]" % propCount] = properties[prop]
-            propCount += 1
-
+        setProps(properties, props, initialIndex=0)
         # invoke the URL
         result = self._cmisClient.binding.post(updateUrl.encode('utf-8'),
                                                urlencode(props),
@@ -1325,14 +1319,11 @@ class BrowserRepository(object):
         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:document"
 
-        propCount = 2
-        for prop in properties:
-            props["propertyId[%s]" % propCount] = prop
-            props["propertyValue[%s]" % propCount] = properties[prop]
-            propCount += 1
+        setProps(properties, props, initialIndex=2)
 
         contentType, body = encode_multipart_formdata(props, contentFile, contentType)
 
@@ -1775,10 +1766,7 @@ class BrowserDocument(BrowserCmisObject):
         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
+        setProps(properties, props, initialIndex=0)
 
         ciUrl = self._repository.getRootFolderUrl() + "?objectId=" + self.id + "&cmisaction=checkin"
 
@@ -2050,11 +2038,7 @@ class BrowserFolder(BrowserCmisObject):
         else:
             props["propertyValue[1]"] = "cmis:folder"
 
-        propCount = 2
-        for key, val in properties.items():
-            props["propertyId[%s]" % propCount] = key
-            props["propertyValue[%s]" % propCount] = val
-            propCount += 1
+        setProps(properties, props, initialIndex=2)
 
         # invoke the URL
         result = self._cmisClient.binding.post(createFolderUrl.encode('utf-8'),
@@ -3028,6 +3012,24 @@ class BrowserCmisId(str):
     pass
 
 
+def setProps(properties, props, initialIndex=0):
+    """
+    Transform key, value from properties into props list items in the format
+    expected by the HTTP POST request
+    """
+    i = initialIndex
+    for key, val in properties.items():
+        props["propertyId[%s]" % i] = key
+        if hasattr(val, '__iter__'):
+            j = 0
+            for v in val:
+                props["propertyValue[%s][%s]" % (i, j)] = v
+                j += 1
+        else:
+            props["propertyValue[%s]" % i] = val
+        i += 1
+
+
 def getSpecializedObject(obj, **kwargs):
 
     """
{code}
https://github.com/lmignon/python-cmislib/commit/04c944398531691b86c39cf3160cd61c1553a137

  was:
The browser binding on the trunk doesn't support multi valued values for properties.
{code}
https://github.com/lmignon/python-cmislib/commit/04c944398531691b86c39cf3160cd61c1553a137
{code}
https://github.com/lmignon/python-cmislib/commit/04c944398531691b86c39cf3160cd61c1553a137


> Allow to use multi valued values in properties when using the Browser Binding
> -----------------------------------------------------------------------------
>
>                 Key: CMIS-979
>                 URL: https://issues.apache.org/jira/browse/CMIS-979
>             Project: Chemistry
>          Issue Type: Bug
>          Components: python-cmislib
>            Reporter: Laurent Mignon
>
> The browser binding on the trunk doesn't support multi valued values for properties.
> {code}
> diff --git a/src/cmislib/browser/binding.py b/src/cmislib/browser/binding.py
> index b340eda..8565be0 100644
> --- a/src/cmislib/browser/binding.py
> +++ b/src/cmislib/browser/binding.py
> @@ -352,13 +352,7 @@ class BrowserCmisObject(object):
>          updateUrl = self._repository.getRootFolderUrl() + "?objectId=" + self.id
>  
>          props = {"cmisaction": "update"}
> -
> -        propCount = 0
> -        for prop in properties:
> -            props["propertyId[%s]" % propCount] = prop
> -            props["propertyValue[%s]" % propCount] = properties[prop]
> -            propCount += 1
> -
> +        setProps(properties, props, initialIndex=0)
>          # invoke the URL
>          result = self._cmisClient.binding.post(updateUrl.encode('utf-8'),
>                                                 urlencode(props),
> @@ -1325,14 +1319,11 @@ class BrowserRepository(object):
>          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:document"
>  
> -        propCount = 2
> -        for prop in properties:
> -            props["propertyId[%s]" % propCount] = prop
> -            props["propertyValue[%s]" % propCount] = properties[prop]
> -            propCount += 1
> +        setProps(properties, props, initialIndex=2)
>  
>          contentType, body = encode_multipart_formdata(props, contentFile, contentType)
>  
> @@ -1775,10 +1766,7 @@ class BrowserDocument(BrowserCmisObject):
>          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
> +        setProps(properties, props, initialIndex=0)
>  
>          ciUrl = self._repository.getRootFolderUrl() + "?objectId=" + self.id + "&cmisaction=checkin"
>  
> @@ -2050,11 +2038,7 @@ class BrowserFolder(BrowserCmisObject):
>          else:
>              props["propertyValue[1]"] = "cmis:folder"
>  
> -        propCount = 2
> -        for key, val in properties.items():
> -            props["propertyId[%s]" % propCount] = key
> -            props["propertyValue[%s]" % propCount] = val
> -            propCount += 1
> +        setProps(properties, props, initialIndex=2)
>  
>          # invoke the URL
>          result = self._cmisClient.binding.post(createFolderUrl.encode('utf-8'),
> @@ -3028,6 +3012,24 @@ class BrowserCmisId(str):
>      pass
>  
>  
> +def setProps(properties, props, initialIndex=0):
> +    """
> +    Transform key, value from properties into props list items in the format
> +    expected by the HTTP POST request
> +    """
> +    i = initialIndex
> +    for key, val in properties.items():
> +        props["propertyId[%s]" % i] = key
> +        if hasattr(val, '__iter__'):
> +            j = 0
> +            for v in val:
> +                props["propertyValue[%s][%s]" % (i, j)] = v
> +                j += 1
> +        else:
> +            props["propertyValue[%s]" % i] = val
> +        i += 1
> +
> +
>  def getSpecializedObject(obj, **kwargs):
>  
>      """
> {code}
> https://github.com/lmignon/python-cmislib/commit/04c944398531691b86c39cf3160cd61c1553a137



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

Mime
View raw message