Examples

There’s nothing in cmislib that is specific to any particular vendor. Once you give it your CMIS provider’s service URL and some credentials, it figures out where to go from there.

Let’s look at some examples using a local install of Alfresco Community Edition.

Get a Repository object

  1. From the command-line, start the Python shell by typing python then hit enter.

  2. Import the CmisClient:

    >>> from cmislib import CmisClient
    
  3. Point the CmisClient at the repository’s service URL

    >>> client = CmisClient('http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/atom', 'admin', 'admin')
    
  4. Get the default repository for the service

    >>> repo = client.defaultRepository
    >>> repo.id
    u'-default-'
    
  5. Get the repository’s properties. This for-loop spits out everything cmislib knows about the repo.

    >>> repo.name
    u''
    >>> info = repo.info
    >>> for k,v in info.items():
        ...     print "%s:%s" % (k,v)
        ...
        cmisVersionSupported:1.1
        principalAnonymous:guest
        principalAnyone:GROUP_EVERYONE
        repositoryDescription:None
        changesOnType:cmis:folder
        changesIncomplete:true
        productVersion:5.2.0 (r133656-b12)
        rootFolderId:000f9013-af35-430e-912f-67328f106279
        repositoryId:-default-
        repositoryName:None
        vendorName:Alfresco
        productName:Alfresco Community
    

Folders & Documents

Once you’ve got the Repository object you can start working with folders.

  1. Create a new folder in the root. You should name yours something unique.

    >>> root = repo.rootFolder
    >>> someFolder = root.createFolder('someFolder')
    >>> someFolder.id
    u'92133bfd-8b69-4e97-9af2-761a09f29e01'
    
  2. Then, you can create some content:

    >>> someFile = open('test.txt', 'r')
    >>> someDoc = someFolder.createDocument('Test Document', contentFile=someFile)
    
  3. And, if you want, you can dump the properties of the newly-created document (this is a partial list):

    >>> props = someDoc.properties
    >>> for k,v in props.items():
    ...     print '%s:%s' % (k,v)
    ...
    cmis:contentStreamMimeType:text/plain
    cmis:creationDate:2016-12-29 14:53:47.430000-06:00
    cmis:baseTypeId:cmis:document
    cmis:isLatestMajorVersion:false
    cmis:isImmutable:false
    cmis:isMajorVersion:false
    cmis:objectId:c4bc9d00-5bf0-404d-8f0a-a6260f6d21ae;1.0
    

Searching For & Retrieving Objects

There are several different ways to grab an object:
  • You can run a CMIS query
  • You can ask the repository to give you one for a specific path or object ID
  • You can traverse the repository using a folder’s children and/or descendants
  1. Let’s find the doc we just created with a full-text search.

    >>> results = repo.query("select * from cmis:document where contains('test')")
    >>> for result in results:
    ...     print result.name
    ...
    Test Document2
    example test script.js
    
  2. Alternatively, you can also get objects by their path, like this:

    >>> someDoc = repo.getObjectByPath('/someFolder/Test Document')
    >>> someDoc.id
    'c4bc9d00-5bf0-404d-8f0a-a6260f6d21ae;1.0'
    
  3. Or their object ID, like this:

    >>> someDoc = repo.getObject('c4bc9d00-5bf0-404d-8f0a-a6260f6d21ae;1.0')
    >>> someDoc.name
    u'Test Document'
    
  4. Folder objects have getChildren() and getDescendants() methods that will return a list of CmisObject objects:

    >>> children = someFolder.getChildren()
    >>> for child in children:
    ...     print child.name
    ...
    Test Document
    Test Document2