Posted by Joeri Samson on Apr 13, 2010
This post will introduce you to ActiveCMIS with the public repository running the Alfresco CMIS implementation.
To start with it will only demonstrate some of the reading functionality.
Installation
ActiveCMIS is written in Ruby, so of course you first have to download and install Ruby if you haven't done that yet. ActiveCMIS should work with Ruby versions 1.8.6 and 1.9.1. It probably will also work with Ruby 1.8.7, but I didn't test that.
The only additional dependency of ActiveCMIS is Nokogiri, if you haven't installed this yet you should follow the Nokogiri's installation instructions for your OS. For Mac OS X the first step of the instructions is not strictly necessary, you will need to have macports installed for it to work. For both steps you will need to have XCode installed.
To install ActiveCMIS simply install the gem like this from the command line.
gem install active_cmis
Configuration
Paste the following text in a plain text file called cmis.yml in your current directory:
alfresco_public:
server_url: "http://cmis.alfresco.com/service/cmis"
repository_id: 84ccfe80-b325-4d79-ab4d-080a4bdd045b
server_login: admin
server_password: admin
Use
Start an IRB session from the command line
irb
Once irb is started you have to require a few libraries:
require 'pp'
require 'rubygems'
require 'active_cmis'
Now you're ready to start using ActiveCMIS. To load the configuration from cmis.yml
alfresco = ActiveCMIS.load_config('alfresco_public')
To view the capabilities of the repository you can query the Repository object:
pp alfresco.capabilities
This returns a hash summing up all the capabilities of the repository, similar to the overview of capabilities found at the Alfresco CMIS page
To view which documents are present in the repository we could do a query like this (this may take some time):
results = alfresco.query("SELECT * FROM cmis:document WHERE cmis:name LIKE '%test%'")
pp results.map {|o| o.cmis.name}
We map the results to the name of the objects because the object id that will be printed otherwise is not informative at all.
Or if we are interested more in the toplevel structure of the repository we could instead start like this:
folder = alfresco.root_folder
pp folder.items.map {|o| [o.id, o.cmis.name]}
This will list all documents and folders that are present at the top of the folder hierarchy.
pp folder.items.select {|o| o.is_a?(ActiveCMIS::Folder)}.map {|o| o.name}
The result of Folder#items is cached, so calling it twice on the same folder, as in the previous two examples, does not result in repeated calls to the server (unless you reload the folder object in the meantime).
To get all the attributes of an object you use Object#attributes
object = folder.items.first
pp object.attributes
It is possible that this will return the attributes of a folder, and will only provide attributes specified in the CMIS specification. To get some more interesting attributes you could also check the attributes of a CMIS document like this:
document = folder.items.detect {|o| o.is_a?(ActiveCMIS::Document) && o.cmis.contentStreamLength }
pp document.attributes
To download the content attached to this document you can run this command, this will copy the content of the document to a file named test_file in your current directory
document.content_stream.get_file('test_file')
blog comments powered by Disqus
Entries per category
- 9 pages are tagged with documentum
- 12 pages are tagged with events
- 14 pages are tagged with rails
- 32 pages are tagged with ruby
- 13 pages are tagged with sharepoint
