Integrating a CMIS repository with Zoho using gadgets in GateIn

1. Introduction

Content Management Interoperability Services (CMIS) is a standard for improving interoperability between Enterprise Content Management systems. It’s a new standard to make Document Management more interoperable.

A year and half ago, I already wrote a web service in java to edit documents, stored in the JCR, with Zoho. As CMIS arrive, it seems a good idea to rewrite this one with this standard and using groovy. Last time, I used a greasemonkey script to integrate it in eXo ECM, but this time, I’m going to create a gadget for that. Thanks to GateIn Gadget Dashboard, I’ll be able to follow multiple repository in one page and edit their files.

Requirements for this project

  • Browse the CMIS repository
  • If file can be edited with Zoho, offer this possibility
  • Work in the main browsers
  • Work with all the public CMIS demo servers available

Dashboard with the Zoho - CMIS gadget

What you need to know before starting

  • Basic knowledge of the gadget API. If you don’t have a look at the Gadget Developer Guide
  • Basic knowledge of javascript and jQuery
  • Basic knowledge of what is Atom, REST and CMIS

2. Accessing to files of a CMIS servers

CMIS servers make available 2 types of API: SOAP and Atom. From javascript, it’s easier to use the Atom API. But all the browsers don’t handle namespaces the same way, so it makes it harder to parse response. We are going to use JQuery because it makes things easier than using the native javascript functions, but I guess it’s possible to do the same with YUI, Dojo or other…

Parsing Atom in Javascript

To get a namespaced node with jQuery, you can do:

So with this, I created a simple CMIS response parser in javascript: jquery.cmis.js (jsDoc). It can parse a Service, a Feed or an Entry.

To get the workspaces from a service:

To list a feed’s entries:

Loading the feed from the gadget

So now that we know how to parse the response of a CMIS server. We can start building our gadget. Most (all?) the CMIS repository are using BasicAuth as authentication/authorization mechanism, so if our CMIS server is on the same domain name we could directly send a request to it. But as we want to be able to integrate CMIS server from all over the internet, we need to use a proxy (remember the same origin policy of our browsers).I’d love to see CMIS repositories to use oAuth authorization mechanism, but as it’s not the case for now, we need to write a simple proxy in Groovy and JAX-RS to do the authentication for us:

So to get a URL authenticated you can just call a url like this:

From our gadget, to get the response of the CMIS server using our proxy, we are going to do:

We can now just use our response object to list the files on our repository.

3. Editing the files with Zoho

Now that we have successfully accessed to our files, we would like to edit them with Zoho editor (API documentation). We have to POST the file to their server, and they return the URL to edit it. When the user will save the document, the zoho server will do a POST on a callback URL (defined on our first POST) containing the document.

You will need to get your zoho API key.

So, here is how it’s going to work:

  • The gadget is going to call our service
  • The service will download the file from the CMIS server
  • The service will generate an ID for the document. We are going to use the URL on the CMIS server and the login/password to access it. To avoid sending the login and password to zoho, we could have store it in the JCR but it add an extra step that we are not going to show on this tutorial.
  • The service will POST everything to the Zoho API corresponding to the right editor (Doc, spredsheet, presentation)
  • The service will parse the response and return the url of the editor
  • The gadget will redirect the user to the editor
  • When the user save the document, Zoho will do a POST on our service to save it
  • The service is going to push the document back on the CMIS server

It looks like a lot of things to do, but with groovy and JAX-RS it’s quite simple.

The gadget is going to call our edit service with the URL of the file and the credential needed in parameter:

Now that we have sent the file to zoho, we need to save it back on the CMIS server. Zoho will call the following method:

We have now everything to be able to browse a CMIS repository and edit the files with Zoho. Have a look at the code of the final gadget and feel free to remix it. You can also view the demo on the xCMIS demo server. To deploy it in GateIn Beta5, read How to activate groovy REST services in GateIn Beta5.

4. Download and link to online demo

Related Posts

1 Comment

    Speak your mind

    Your email address will not be published.

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">