chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jpo...@apache.org
Subject svn commit: r1208886 - in /chemistry/cmislib/trunk/src: cmislib/model.py tests/cmislibtest.py
Date Wed, 30 Nov 2011 23:44:58 GMT
Author: jpotts
Date: Wed Nov 30 23:44:54 2011
New Revision: 1208886

URL: http://svn.apache.org/viewvc?rev=1208886&view=rev
Log:
Added Folder.getPaths and Document.getPaths, refactored testGetObjectByPath to build path
without assuming name is the path segment. Closes CMIS-232

Modified:
    chemistry/cmislib/trunk/src/cmislib/model.py
    chemistry/cmislib/trunk/src/tests/cmislibtest.py

Modified: chemistry/cmislib/trunk/src/cmislib/model.py
URL: http://svn.apache.org/viewvc/chemistry/cmislib/trunk/src/cmislib/model.py?rev=1208886&r1=1208885&r2=1208886&view=diff
==============================================================================
--- chemistry/cmislib/trunk/src/cmislib/model.py (original)
+++ chemistry/cmislib/trunk/src/cmislib/model.py Wed Nov 30 23:44:54 2011
@@ -1750,11 +1750,11 @@ class CmisObject(object):
             self._objectId = CmisId(props['cmis:objectId'])
         return self._objectId
 
-    def getObjectParents(self):
+    def getObjectParents(self, **kwargs):
         """
         See CMIS specification document 2.2.3.5 getObjectParents
 
-        The following optional arguments are not supported:
+        The following optional arguments are supported:
          - filter
          - includeRelationships
          - renditionFilter
@@ -1768,7 +1768,7 @@ class CmisObject(object):
             raise NotSupportedException('Root folder does not support getObjectParents')
 
         # invoke the URL
-        result = self._cmisClient.get(parentUrl.encode('utf-8'))
+        result = self._cmisClient.get(parentUrl.encode('utf-8'), **kwargs)
 
         if type(result) == HTTPError:
             raise CmisException(result.code)
@@ -1776,6 +1776,13 @@ class CmisObject(object):
         # return the result set
         return ResultSet(self._cmisClient, self._repository, result)
 
+    def getPaths(self):
+        """
+        Returns the object's paths as a list of strings.
+        """
+        # see sub-classes for implementation
+        pass
+
     def getAllowableActions(self):
 
         """
@@ -1875,6 +1882,15 @@ class CmisObject(object):
                 else:
                     propertyValue = None
                 self._properties[propertyName] = propertyValue
+
+            for node in [e for e in self.xmlDoc.childNodes if e.nodeType == e.ELEMENT_NODE
and e.namespaceURI == CMISRA_NS]:
+                propertyName = node.nodeName
+                if node.childNodes:
+                    propertyValue = node.firstChild.nodeValue
+                else:
+                    propertyValue = None
+                self._properties[propertyName] = propertyValue
+
         return self._properties
 
     def getName(self):
@@ -2589,6 +2605,38 @@ class Document(CmisObject):
 
     checkedOut = property(isCheckedOut)
 
+    def getPaths(self):
+        """
+        Returns the Document's paths by asking for the parents with the
+        includeRelativePathSegment flag set to true, then concats the value
+        of cmis:path with the relativePathSegment.
+        """
+        # get the appropriate 'up' link
+        parentUrl = self._getLink(UP_REL)
+
+        if parentUrl == None:
+            raise NotSupportedException('Root folder does not support getObjectParents')
+
+        # invoke the URL
+        result = self._cmisClient.get(parentUrl.encode('utf-8'),
+                                      filter='cmis:path',
+                                      includeRelativePathSegment=True)
+
+        if type(result) == HTTPError:
+            raise CmisException(result.code)
+
+        paths = []
+        rs = ResultSet(self._cmisClient, self._repository, result)
+        for res in rs:
+            path = res.properties['cmis:path']
+            relativePathSegment = res.properties['cmisra:relativePathSegment']
+            
+            # concat with a slash
+            # add it to the list
+            paths.append(path + '/' + relativePathSegment)
+
+        return paths
+
 
 class Folder(CmisObject):
 
@@ -2984,6 +3032,14 @@ class Folder(CmisObject):
         if type(result) == HTTPError:
             raise CmisException(result.code)
 
+    def getPaths(self):
+        """
+        Returns the paths as a list of strings. The spec says folders cannot
+        be multi-filed, so this should always be one value. We return a list
+        to be symmetric with the same method in :class:`Document`.
+        """
+        return [self.properties['cmis:path']]
+
 
 class Relationship(CmisObject):
 

Modified: chemistry/cmislib/trunk/src/tests/cmislibtest.py
URL: http://svn.apache.org/viewvc/chemistry/cmislib/trunk/src/tests/cmislibtest.py?rev=1208886&r1=1208885&r2=1208886&view=diff
==============================================================================
--- chemistry/cmislib/trunk/src/tests/cmislibtest.py (original)
+++ chemistry/cmislib/trunk/src/tests/cmislibtest.py Wed Nov 30 23:44:54 2011
@@ -341,16 +341,21 @@ class RepositoryTest(CmisTestBase):
         # create the folder structure
         parentFolder = self._testFolder.createFolder(parentFolderName)
         subFolder = parentFolder.createFolder(subFolderName)
-        # name and path segment are not the same thing
+        # use the subfolder path to get the folder by path
         subFolderPath = subFolder.getProperties().get("cmis:path")
         searchFolder = self._repo.getObjectByPath(subFolderPath)
         self.assertEquals(subFolder.getObjectId(), searchFolder.getObjectId())
 
         # create a test doc
         doc = subFolder.createDocument(docName)
-        searchDocPath = subFolderPath + '/' + docName  # TODO use proper path segment
-        searchDoc = self._repo.getObjectByPath(searchDocPath)
-        self.assertEquals(doc.getObjectId(), searchDoc.getObjectId())
+        # ask the doc for its paths
+        searchDocPaths = doc.getPaths()
+        # for each path in the list, try to get the object by path
+        # this is better than building a path with the doc's name b/c the name
+        # isn't guaranteed to be used as the path segment (see CMIS-232)
+        for path in searchDocPaths:
+            searchDoc = self._repo.getObjectByPath(path)
+            self.assertEquals(doc.getObjectId(), searchDoc.getObjectId())
 
         # get the subfolder by path, then ask for its children
         subFolder = self._repo.getObjectByPath(subFolderPath)
@@ -662,19 +667,30 @@ class FolderTest(CmisTestBase):
         self.assertEquals(doc.name, subFolder1.getChildren()[0].name)
 
     def testFolderLeadingDot(self):
-        '''Create a folder with a leading dot in it's name'''
+        '''Create a folder with a leading dot in its name'''
         leadingDotFolder = self._testFolder.createFolder('.leadingDot')
         resultSet = self._testFolder.getChildren()
         self.assert_(resultSet != None)
         self.assertTrue(leadingDotFolder.getName().startswith('.'))
 
     def testFolderTrailingDot(self):
-        '''Create a folder with a trailing dot in it's name'''
+        '''Create a folder with a trailing dot in its name'''
         trailingDotFolder = self._testFolder.createFolder('trailingDot.')
         resultSet = self._testFolder.getChildren()
         self.assert_(resultSet != None)
         self.assertTrue(trailingDotFolder.getName().endswith('.'))
-        
+
+    def testGetPaths(self):
+        '''Get a folder's paths'''
+        # ask the root for its path
+        root = self._repo.getRootFolder()
+        paths = root.getPaths()
+        self.assertTrue(len(paths) == 1)
+        self.assertTrue(paths[0] == '/')
+        # ask the test folder for its paths
+        paths = self._testFolder.getPaths()
+        self.assertTrue(len(paths) == 1)
+
     # Exceptions
 
     def testBadParentFolder(self):
@@ -1257,6 +1273,13 @@ class DocumentTest(CmisTestBase):
             parentNames.remove(parent.name)
         self.assertEquals(len(parentNames), 0)
 
+    def testGetPaths(self):
+        '''Get the paths of a document'''
+        testDoc = self._testFolder.createDocument('testdoc')
+        # ask the test doc for its paths
+        paths = testDoc.getPaths()
+        self.assertTrue(len(paths) >= 1)
+
 
 class TypeTest(unittest.TestCase):
 



Mime
View raw message