You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by jp...@apache.org on 2010/03/05 16:47:44 UTC

svn commit: r919457 - in /incubator/chemistry/trunk/cmislib: ./ src/cmislib/model.py src/tests/cmislibtest.py src/tests/settings.py

Author: jpotts
Date: Fri Mar  5 15:47:43 2010
New Revision: 919457

URL: http://svn.apache.org/viewvc?rev=919457&view=rev
Log:
Reload and getObjectByPath now support a properties filter. Added a unit test for the property filter. Fixed reload--it wasn't retaining the optional arguments that had originally been set. Fixed a problem that was caused when vendors add their own extensions to the properties list. I'm now more defensive about only looking for property elements in the CMIS namespace.

Modified:
    incubator/chemistry/trunk/cmislib/   (props changed)
    incubator/chemistry/trunk/cmislib/src/cmislib/model.py
    incubator/chemistry/trunk/cmislib/src/tests/cmislibtest.py
    incubator/chemistry/trunk/cmislib/src/tests/settings.py

Propchange: incubator/chemistry/trunk/cmislib/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Mar  5 15:47:43 2010
@@ -0,0 +1,2 @@
+build
+dist

Modified: incubator/chemistry/trunk/cmislib/src/cmislib/model.py
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/cmislib/src/cmislib/model.py?rev=919457&r1=919456&r2=919457&view=diff
==============================================================================
--- incubator/chemistry/trunk/cmislib/src/cmislib/model.py (original)
+++ incubator/chemistry/trunk/cmislib/src/cmislib/model.py Fri Mar  5 15:47:43 2010
@@ -891,9 +891,9 @@
          - includeAllowableActions
         """
 
-        return getSpecializedObject(CmisObject(self._cmisClient, self, objectId, **kwargs))
+        return getSpecializedObject(CmisObject(self._cmisClient, self, objectId, **kwargs), **kwargs)
 
-    def getObjectByPath(self, path):
+    def getObjectByPath(self, path, **kwargs):
 
         """
         Returns an object given the path to the object.
@@ -921,17 +921,30 @@
               '{includeRelationships}': 'false',
               '{includeACL}': 'false',
               '{renditionFilter}': ''}
+
+        options = {}
+        addOptions = {} # args specified, but not in the template
+        for k, v in kwargs.items():
+            pKey = "{" + k + "}"
+            if template.find(pKey) >= 0:
+                options[pKey] = toCMISValue(v)
+            else:
+                addOptions[k] = toCMISValue(v)
+
+        # merge the templated args with the default params
+        params.update(options)
+
         byObjectPathUrl = multiple_replace(params, template)
 
         # do a GET against the URL
-        result = self._cmisClient.get(byObjectPathUrl)
+        result = self._cmisClient.get(byObjectPathUrl, **addOptions)
         if type(result) == HTTPError:
             raise CmisException(result.code)
 
         # instantiate CmisObject objects with the results and return the list
         entryElements = result.getElementsByTagNameNS(ATOM_NS, 'entry')
         assert(len(entryElements) == 1), "Expected entry element in result from calling %s" % byObjectPathUrl
-        return getSpecializedObject(CmisObject(self._cmisClient, self, xmlDoc=entryElements[0]))
+        return getSpecializedObject(CmisObject(self._cmisClient, self, xmlDoc=entryElements[0], **kwargs), **kwargs)
 
     def query(self, statement, **kwargs):
 
@@ -1565,6 +1578,11 @@
         """
         Fetches the latest representation of this object from the CMIS service.
         Some methods, like :class:`^Document.checkout` do this for you.
+
+        If you call reload with a properties filter, the filter will be in
+        effect on subsequent calls until the filter argument is changed. To
+        reset to the full list of properties, call reload with filter set to
+        '*'. 
         """
 
         if kwargs:
@@ -1742,7 +1760,7 @@
                 self.reload()
             propertiesElement = self.xmlDoc.getElementsByTagNameNS(CMIS_NS, 'properties')[0]
             #cpattern = re.compile(r'^property([\w]*)')
-            for node in [e for e in propertiesElement.childNodes if e.nodeType == e.ELEMENT_NODE]:
+            for node in [e for e in propertiesElement.childNodes if e.nodeType == e.ELEMENT_NODE and e.namespaceURI == CMIS_NS]:
                 #propertyId, propertyString, propertyDateTime
                 #propertyType = cpattern.search(node.localName).groups()[0]
                 propertyName = node.attributes['propertyDefinitionId'].value

Modified: incubator/chemistry/trunk/cmislib/src/tests/cmislibtest.py
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/cmislib/src/tests/cmislibtest.py?rev=919457&r1=919456&r2=919457&view=diff
==============================================================================
--- incubator/chemistry/trunk/cmislib/src/tests/cmislibtest.py (original)
+++ incubator/chemistry/trunk/cmislib/src/tests/cmislibtest.py Fri Mar  5 15:47:43 2010
@@ -466,6 +466,64 @@
         self.assert_('cmis:name' in props)
         self.assert_(props['cmis:name'] != None)
 
+    def testPropertyFilter(self):
+        '''Test the properties filter'''
+        # names of folders and test docs
+        testFolderName = self._testFolder.getName()
+        parentFolderName = 'testGetObjectByPath folder'
+        subFolderName = 'subfolder'
+
+        # create the folder structure
+        parentFolder = self._testFolder.createFolder(parentFolderName)
+        subFolder = parentFolder.createFolder(subFolderName)
+
+        # test when used with getObjectByPath
+        searchFolder = self._repo.getObjectByPath(settings.TEST_ROOT_PATH + \
+                        "/".join([testFolderName, parentFolderName, subFolderName]), \
+                        filter='cmis:objectId,cmis:objectTypeId,cmis:baseTypeId')
+        self.assertEquals(subFolder.getObjectId(), searchFolder.getObjectId())        
+        self.assertTrue(searchFolder.getProperties().has_key('cmis:objectId'))
+        self.assertTrue(searchFolder.getProperties().has_key('cmis:objectTypeId'))
+        self.assertTrue(searchFolder.getProperties().has_key('cmis:baseTypeId'))
+        self.assertFalse(searchFolder.getProperties().has_key('cmis:name'))
+
+        # test when used with getObjectByPath + reload
+        searchFolder = self._repo.getObjectByPath(settings.TEST_ROOT_PATH + \
+                        "/".join([testFolderName, parentFolderName, subFolderName]), \
+                        filter='cmis:objectId,cmis:objectTypeId,cmis:baseTypeId')
+        searchFolder.reload()
+        self.assertEquals(subFolder.getObjectId(), searchFolder.getObjectId())
+        self.assertTrue(searchFolder.getProperties().has_key('cmis:objectId'))
+        self.assertTrue(searchFolder.getProperties().has_key('cmis:objectTypeId'))
+        self.assertTrue(searchFolder.getProperties().has_key('cmis:baseTypeId'))
+        self.assertFalse(searchFolder.getProperties().has_key('cmis:name'))
+
+        # test when used with getObject
+        searchFolder = self._repo.getObject(subFolder.getObjectId(), \
+                        filter='cmis:objectId,cmis:objectTypeId,cmis:baseTypeId')
+        self.assertEquals(subFolder.getObjectId(), searchFolder.getObjectId())
+        self.assertTrue(searchFolder.getProperties().has_key('cmis:objectId'))
+        self.assertTrue(searchFolder.getProperties().has_key('cmis:objectTypeId'))
+        self.assertTrue(searchFolder.getProperties().has_key('cmis:baseTypeId'))
+        self.assertFalse(searchFolder.getProperties().has_key('cmis:name'))
+
+        # test when used with getObject + reload
+        searchFolder = self._repo.getObject(subFolder.getObjectId(), \
+                        filter='cmis:objectId,cmis:objectTypeId,cmis:baseTypeId')
+        searchFolder.reload()
+        self.assertEquals(subFolder.getObjectId(), searchFolder.getObjectId())
+        self.assertTrue(searchFolder.getProperties().has_key('cmis:objectId'))
+        self.assertTrue(searchFolder.getProperties().has_key('cmis:objectTypeId'))
+        self.assertTrue(searchFolder.getProperties().has_key('cmis:baseTypeId'))
+        self.assertFalse(searchFolder.getProperties().has_key('cmis:name'))
+
+        # test that you can do a reload with a reset filter
+        searchFolder.reload(filter='*')
+        self.assertTrue(searchFolder.getProperties().has_key('cmis:objectId'))
+        self.assertTrue(searchFolder.getProperties().has_key('cmis:objectTypeId'))
+        self.assertTrue(searchFolder.getProperties().has_key('cmis:baseTypeId'))
+        self.assertTrue(searchFolder.getProperties().has_key('cmis:name'))
+
     def testUpdateProperties(self):
         '''Create a test folder, then update its properties'''
         folderName = 'testUpdateProperties folder'

Modified: incubator/chemistry/trunk/cmislib/src/tests/settings.py
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/cmislib/src/tests/settings.py?rev=919457&r1=919456&r2=919457&view=diff
==============================================================================
--- incubator/chemistry/trunk/cmislib/src/tests/settings.py (original)
+++ incubator/chemistry/trunk/cmislib/src/tests/settings.py Fri Mar  5 15:47:43 2010
@@ -2,14 +2,25 @@
 # Override these settings with values to match your environment.
 #
 # CMIS repository's service URL
-REPOSITORY_URL = 'http://cmis.alfresco.com/s/cmis'
+#REPOSITORY_URL = 'http://cmis.alfresco.com/s/cmis'
+#REPOSITORY_URL = 'http://localhost:8080/cmis/repository' # Apache Chemistry
+REPOSITORY_URL = 'http://cmis.dnsdojo.com:8080/p8cmis/resources/DaphneA/Service'
 #REPOSITORY_URL = 'http://localhost:8080/alfresco/s/cmis'
+#REPOSITORY_URL = 'http://cmis.demo.nuxeo.org/nuxeo/site/cmis/repository'
+#REPOSITORY_URL = 'http://localhost:8080/opencmis/atom' # OpenCMIS from the OpenText guys
+#REPOSITORY_URL = 'http://ec2-174-129-218-67.compute-1.amazonaws.com/cmis/atom' #OpenText on Amazon
 # CMIS repository credentials
 USERNAME = 'admin'
 PASSWORD = 'admin'
+#USERNAME = 'Administrator' # Nuxeo
+#PASSWORD = 'Administrator' # Nuxeo
+#USERNAME = 'cmisuser'
+#PASSWORD = 'otcmis'
 # Absolute path to a directory where test folders can be created, including
 # the trailing slash.
-TEST_ROOT_PATH = '/jeff test/' # REMEMBER TRAILING SLASH
+#TEST_ROOT_PATH = '/default-domain/jeff test/' # REMEMBER TRAILING SLASH
+TEST_ROOT_PATH = '/cmislib test/' # REMEMBER TRAILING SLASH
+#TEST_ROOT_PATH = '/'
 # Binary test files. Assumed to exist in the same dir as this python script
 TEST_BINARY_1 = '250px-Cmis_logo.png'
 TEST_BINARY_2 = 'sample-a.pdf'
@@ -17,4 +28,4 @@
 # times a query is retried before giving up.
 MAX_FULL_TEXT_TRIES = 10
 # The number of seconds the test should sleep between tries.
-FULL_TEXT_WAIT = 10
+FULL_TEXT_WAIT = 10
\ No newline at end of file