Hi, I'm Harlin and welcome to my blog. I write about Python, Alfresco and other cheesy comestibles.

Python + Alfresco: How to Find Documents by Document Type Using CMIS

I like playing with the new Alfresco model manager. Well, at least it was new in Alfresco 5.0 and here we are now on 5.2.

I have an old system where I upload a lot of PDF files. I found an old model (techbooks) on a 5.1.2 system and wanted to make it inactive so I could create a newer and better version of "techbooks". Of course, I wasn't able to make it inactive because evidently there were a number of documents that were using this type. Alfresco won't let you do that until you delete the documents. It's also not very simple out of the box to find the offending documents. So, I wrote this very simple script to find those documents:

#!/usr/bin/env python

from cmislib import CmisClient

url = 'http://alfrescohost:8080/alfresco/cmisatom'
userid = 'admin'
passwd = 'admin'
model_name = 'tb:techbook'

client = CmisClient(url, userid, passwd)
repo = client.defaultRepository

results = repo.query("SELECT * FROM %s" % (model_name,))

for row in results:
    print row.properties['cmis:name']

FWIW, I still don't like that you can't do standard sql query string substitution with this module.

You can at least get a list of tb:techbook documents, go hunt them down and delete them. Since the three books I found were still ones I wanted in my repo, I just downloaded them before deleting them. Also, be aware that you need to go into your user's trashcan to delete them permanently so that the model is no longer attached to them. You should then be able to make the model inactive.

Any Comments, Always Welcome!