Uploaded image for project: 'Chemistry (Retired)'
  1. Chemistry (Retired)
  2. CMIS-979

Allow to use multi valued values in properties when using the Browser Binding

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • cmislib 0.6.0
    • python-cmislib
    • None
    • Patch

    Description

      The browser binding on the trunk doesn't support multi valued values for properties.

      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):
       
           """
      

      https://github.com/lmignon/python-cmislib/commit/04c944398531691b86c39cf3160cd61c1553a137

      Attachments

        Activity

          People

            jpotts Jeffrey Taylor Potts
            lmi Laurent Mignon
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: