chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jpo...@apache.org
Subject svn commit: r1776466 - in /chemistry/cmislib/trunk/src: cmislib/atompub/binding.py cmislib/browser/binding.py cmislib/domain.py cmislib/util.py tests/cmislibtest.py
Date Thu, 29 Dec 2016 19:05:37 GMT
Author: jpotts
Date: Thu Dec 29 19:05:36 2016
New Revision: 1776466

URL: http://svn.apache.org/viewvc?rev=1776466&view=rev
Log:
Enhance checkin method to support setting properties simultaneously to close #CMIS-972

Modified:
    chemistry/cmislib/trunk/src/cmislib/atompub/binding.py
    chemistry/cmislib/trunk/src/cmislib/browser/binding.py
    chemistry/cmislib/trunk/src/cmislib/domain.py
    chemistry/cmislib/trunk/src/cmislib/util.py
    chemistry/cmislib/trunk/src/tests/cmislibtest.py

Modified: chemistry/cmislib/trunk/src/cmislib/atompub/binding.py
URL: http://svn.apache.org/viewvc/chemistry/cmislib/trunk/src/cmislib/atompub/binding.py?rev=1776466&r1=1776465&r2=1776466&view=diff
==============================================================================
--- chemistry/cmislib/trunk/src/cmislib/atompub/binding.py (original)
+++ chemistry/cmislib/trunk/src/cmislib/atompub/binding.py Thu Dec 29 19:05:36 2016
@@ -2363,7 +2363,8 @@ class AtomPubDocument(AtomPubCmisObject)
         self.reload()
         return self.getProperties()['cmis:versionSeriesCheckedOutBy']
 
-    def checkin(self, checkinComment=None, **kwargs):
+    def checkin(self, checkinComment=None, contentFile=None, contentType=None,
+                properties=None, **kwargs):
 
         """
         Checks in this :class:`Document` which must be a private
@@ -2379,10 +2380,7 @@ class AtomPubDocument(AtomPubCmisObject)
         >>> doc.isCheckedOut()
         False
 
-        The following optional arguments are supported:
-         - major
-         - properties
-         - contentStream
+        The following optional arguments are NOT supported:
          - policies
          - addACEs
          - removeACEs
@@ -2396,8 +2394,19 @@ class AtomPubDocument(AtomPubCmisObject)
         kwargs['checkin'] = 'true'
         kwargs['checkinComment'] = checkinComment
 
-        # Build an empty ATOM entry
-        entryXmlDoc = getEmptyXmlDoc()
+        if not properties and not contentFile:
+            # Build an empty ATOM entry
+            entryXmlDoc = getEmptyXmlDoc()
+        else:
+            # the getEntryXmlDoc function may need the object type
+            objectTypeId = None
+            if self.properties.has_key('cmis:objectTypeId') and not properties.has_key('cmis:objectTypeId'):
+                objectTypeId = self.properties['cmis:objectTypeId']
+                self.logger.debug('This object type is:%s', objectTypeId)
+
+            # build the entry based on the properties provided
+            entryXmlDoc = getEntryXmlDoc(
+                self._repository, objectTypeId, properties, contentFile, contentType)
 
         # Get the self link
         # Do a PUT of the empty ATOM to the self link

Modified: chemistry/cmislib/trunk/src/cmislib/browser/binding.py
URL: http://svn.apache.org/viewvc/chemistry/cmislib/trunk/src/cmislib/browser/binding.py?rev=1776466&r1=1776465&r2=1776466&view=diff
==============================================================================
--- chemistry/cmislib/trunk/src/cmislib/browser/binding.py (original)
+++ chemistry/cmislib/trunk/src/cmislib/browser/binding.py Thu Dec 29 19:05:36 2016
@@ -26,7 +26,8 @@ from cmislib.domain import CmisId, CmisO
 from cmislib.exceptions import CmisException, InvalidArgumentException,\
                                NotSupportedException, ObjectNotFoundException
 from cmislib.net import RESTService as Rest
-from cmislib.util import parsePropValueByType, parseDateTimeValue, safe_quote
+from cmislib.util import parsePropValueByType, parseDateTimeValue, safe_quote,\
+                        safe_urlencode
 import json
 import logging
 import StringIO
@@ -1756,7 +1757,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,
+                properties=None, **kwargs):
 
         """
         Checks in this :class:`Document` which must be a private
@@ -1773,9 +1775,6 @@ class BrowserDocument(BrowserCmisObject)
         False
 
         The following optional arguments are NOT supported:
-         - major
-         - properties
-         - contentStream
          - policies
          - addACEs
          - removeACEs
@@ -1784,22 +1783,30 @@ class BrowserDocument(BrowserCmisObject)
         # 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'
 
-        kwargs['checkinComment'] = checkinComment
+        props = {
+            'checkinComment': checkinComment or "",
+        }
+        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
 
-        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'),
-                                               safe_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))
 

Modified: chemistry/cmislib/trunk/src/cmislib/domain.py
URL: http://svn.apache.org/viewvc/chemistry/cmislib/trunk/src/cmislib/domain.py?rev=1776466&r1=1776465&r2=1776466&view=diff
==============================================================================
--- chemistry/cmislib/trunk/src/cmislib/domain.py (original)
+++ chemistry/cmislib/trunk/src/cmislib/domain.py Thu Dec 29 19:05:36 2016
@@ -1241,7 +1241,8 @@ class Document(CmisObject):
 
         pass
 
-    def checkin(self, checkinComment=None, **kwargs):
+    def checkin(self, checkinComment=None, contentFile=None, contentType=None,
+                properties=None, **kwargs):
 
         """
         Checks in this :class:`Document` which must be a private
@@ -1257,10 +1258,7 @@ class Document(CmisObject):
         >>> doc.isCheckedOut()
         False
 
-        The following optional arguments are supported:
-         - major
-         - properties
-         - contentStream
+        The following optional arguments are NOT supported:
          - policies
          - addACEs
          - removeACEs

Modified: chemistry/cmislib/trunk/src/cmislib/util.py
URL: http://svn.apache.org/viewvc/chemistry/cmislib/trunk/src/cmislib/util.py?rev=1776466&r1=1776465&r2=1776466&view=diff
==============================================================================
--- chemistry/cmislib/trunk/src/cmislib/util.py (original)
+++ chemistry/cmislib/trunk/src/cmislib/util.py Thu Dec 29 19:05:36 2016
@@ -25,7 +25,7 @@ import iso8601
 import logging
 import datetime
 from cmislib.domain import CmisId
-from urllib import quote
+from urllib import urlencode, quote
 
 moduleLogger = logging.getLogger('cmislib.util')
 

Modified: chemistry/cmislib/trunk/src/tests/cmislibtest.py
URL: http://svn.apache.org/viewvc/chemistry/cmislib/trunk/src/tests/cmislibtest.py?rev=1776466&r1=1776465&r2=1776466&view=diff
==============================================================================
--- chemistry/cmislib/trunk/src/tests/cmislibtest.py (original)
+++ chemistry/cmislib/trunk/src/tests/cmislibtest.py Thu Dec 29 19:05:36 2016
@@ -899,6 +899,48 @@ class DocumentTest(CmisTestBase):
             if testDoc.isCheckedOut():
                 pwcDoc.delete()
 
+    def testCheckinContentAndProperties(self):
+        """Checkin a document with a new content a modifed properties"""
+        testFilename = settings.TEST_BINARY_1.split('/')[-1]
+        contentFile = open(testFilename, 'rb')
+        props = {'cmis:objectTypeId': settings.VERSIONABLE_TYPE_ID}
+        testDoc = self._testFolder.createDocument(testFilename, contentFile=contentFile,
properties=props)
+        contentFile.close()
+        self.assertEquals(testFilename, testDoc.getName())
+        if not 'canCheckOut' in testDoc.allowableActions.keys():
+            print 'The test doc cannot be checked out...skipping'
+            return
+        pwcDoc = testDoc.checkout()
+
+        try:
+            self.assertTrue(testDoc.isCheckedOut())
+            testFile2 = settings.TEST_BINARY_2
+            testFile2Size = os.path.getsize(testFile2)
+            exportFile2 = testFile2.replace('.', 'export.')
+            contentFile2 = open(testFile2, 'rb')
+            props = {'cmis:name': 'testDocument2'}
+            testDoc = pwcDoc.checkin(
+                contentFile=contentFile2,
+                properties=props)
+            contentFile2.close()
+            self.assertFalse(testDoc.isCheckedOut())
+            self.assertEqual('testDocument2', testDoc.getName())
+
+            # expport the result
+            result = testDoc.getContentStream()
+            outfile = open(exportFile2, 'wb')
+            outfile.write(result.read())
+            result.close()
+            outfile.close()
+
+            # the file we exported should be the same size as the file we
+            # originally created
+            self.assertEquals(testFile2Size, os.path.getsize(exportFile2))
+
+        finally:
+            if testDoc.isCheckedOut():
+                pwcDoc.delete()
+
     def testCheckinAfterGetPWC(self):
         """Create a document in a test folder, check it out, call getPWC, then checkin"""
         if not self._repo.getCapabilities()['PWCUpdatable'] == True:



Mime
View raw message