Alfresco CMIS Sample Chapter
Alfresco CMIS Sample Chapter
Martin Bergljung
I would like to thank Sumeet Sawant, Priyanka Shah, and Subho Gupta at Packt Publishing for suggesting the project and getting it on track. My thanks also goes to Sherin Padayatty and Michelle Quadros, my Project Coordinators, who were always pushing me to deliver the next chapter. Thanks to the entire Packt Publishing team for working so diligently to help bring out a high-quality product. Thanks to all the book reviewers who gave me invaluable feedback during the whole project. Specifically, I would like to thank Robin Bramely, my colleague at Ixxus, who gave me invaluable feedback, tips, and ideas throughout the book writing process, thanks! I must also thank the talented team of developers who created the Alfresco open source product. It opens up a new way for everyone that wants to build any kind of ECM business solution. And finally, I would like to thank Paul Samuel and Justin Haynes at Ixxus for supporting my book project.
Alfresco CMIS
Content Management Servers (CMS), both proprietary and open source, have been around for a very long time, but there has not been a standard way of talking to them until recently. The Content Management Interoperability Services (CMIS) standard provides both an application programming interface and a search language (based on SQL-92). Today, most of the CMS systems out there support the CMIS standard. Alfresco CMIS is a practical, hands-on guide that provides you with a number of clear step-by-step exercises, which will help you take advantage of the real power of CMIS and give you a good foundation in using it via HTTP/XML, Java, or scripting. This practical companion will get you up to speed on CMIS in no time.
Understanding CMIS
CMIS is an effort toward standardization and is managed by the Organization for the Advancement of Structured Information Standards (OASIS) body. The latest version is 1.1 (http://docs.oasis-open.org/cmis/CMIS/v1.1/CMIS-v1.1.html), which was approved in May 2013. Version 1.0 species most of the functionalities and is quite developed being approved in May 2010. Some content servers might not yet support Version 1.1, so we will point out when a feature is only available in Version 1.1. CMIS is all about being able to access and manage content in a so-called content repository in a standard way. You can think of a content repository as something that can be used to store les in a folder hierarchy. The CMIS interface consists of two parts: a number of repository services for things such as content navigation and content creation, and a repository query language for content search. The standard also denes what protocols can be used to communicate with a repository and what formats should be used in requests and responses via these protocols.
To really explain what CMIS is, and the background to why it came about, one has to look at how the implementation of content management systems has evolved. If we go back 15-20 years, most companies (that are large corporations) had one content management system installed for Document Management (DM) and workow. This meant that all the content was available in one system via a single Application Programming Interface (API), making it easy for other enterprise systems to integrate with it and access content. For example, the Swedish nuclear power plant that I worked for in the mid 90s had one big installation of Documentum that everyone used. In the last 5-10 years, there has been an explosion in the number of content management systems used by companies; most companies now have multiple content management systems in use, sometimes running into double digits.
So you are thinking that this cannot be true; companies having ve content management systems? This is true alright. According to the Association for Information and Image Management (AIIM), which is the main Enterprise Content Management (ECM) industry organization, 72 percent of large organizations have three or more ECM, Document Management, or Record Management systems, while 25 percent have ve or more (as mentioned in State of the ECM Industry, AIIM, 2011).
This is because these days we not only manage documents, but we also manage records (known as Record Management), images and media les (known as Digital Asset Management), advanced workows, web content (known as Web Content Management), and many other types of content. It is quite often that one content management system is better than the other in handling one type of content such as records or web content, so a company ends up buying multiple content management systems to manage different types of content. A new type of content management system has also emerged, which is open source and easily accessible for everyone to try out. Each one of these systems have different APIs and can be implemented in a different language and on a different type of platform. All this means that a lot of companies have ended up with many content silos/islands that are not communicating with each other, sometimes having duplicated content.
[8]
Chapter 1
What this means is that when it comes to implementing the following kind of services, we might have a problem choosing what API to work with: Enterprise service that should aggregate content from several of these systems Content transfer from one system to another UI client that should display content from more than one of these systems
It would then be necessary to learn about a whole lot of APIs and platforms. Most of the proprietary APIs were also not based on HTTP, so if you wanted a service or client to be outside the rewall, you would have to open up new ports in the rewall to take care of security and so on. Any company that wants to develop tools or clients to access content management systems would also have to support many different protocols and formats, making it difcult to work with more than a handful of the seasoned CMS players. This leads to people thinking about some sort of standard interface and protocol to access CMS systems. The rst established standard covering the content management area is Web Distributed Authoring and Versioning (WebDAV), which was proposed in February 1999 with RFC 2518 (refer to ftp://ftp.isi.edu/in-notes/rfc2518. txt). It is supported by most content management systems, including Alfresco, and is usually used to map a drive to access the content management system via, for example, Windows Explorer or Mac Finder. The problem with this way of accessing content is that most of the valuable features of a content management system cannot be used, such as setting custom metadata, managing versions, setting ne grained permissions, controlling relationships, and searching for content. So this led to more comprehensive standards such as the Java Content Repository (JCR) API, which is managed by the Java Community Process as JSR-170 (https:// www.jcp.org/en/jsr/detail?id=170) and JSR-283 (https://www.jcp.org/en/ jsr/detail?id=283) and was rst developed in 2002. The JCR standard has been supported by Alfresco for a long time, but it has never really taken off as it is Java centric and excludes content management systems such as SharePoint and Drupal.
[9]
Something needed to be done to come up with a new standard that would be easy to learn and adopt. This is where CMIS comes into the picture. CMIS provides a standard API and query language that can be used to talk to any CMS system that implements the CMIS standard. The following gure illustrates how a client application that adheres to the CMIS standard can talk to many different content management systems through one standard service-oriented interface:
Client A
CMIS Service Call
Client B
CMIS Service Call
Client C
CMIS Service Call
CMIS Service Interface CMIS Implementation CMIS Implementation CMIS Implementation CMIS Implementation CMIS Implementation
Alfresco
Documentum
FileNet
Nuxeo
OpenText
The preceding gure shows how each one of the content management systems offers access to their proprietary content and metadata via the standard CMIS service interface. The CMIS interface is web-based, which means that it can be accessed via HTTP through the Internet. Even cloud-based content management systems such as the Alfresco Cloud installation can be accessed via CMIS.
Chapter 1
WCM systems: Magnolia, Liferay, Drupal, Hippo, TYPE3, and dotCMS Blogging: Wordpress Clients: Libre Ofce, Adobe Drive, Atlassian Conuence, SAP ECM Integration, Pentaho Data Integration, SugarCRM, Trac, Kofax, and Salesforce Files SOA: Mule ESB and Spring Integration Libraries: Apache Chemistry (which includes Java, Python, PHP, .NET, and Objective-C)
So we can see there is no doubt that the CMIS standard has been very well received and adopted.
Easy workow integration: It is now much easier for a company to deploy an enterprise workow that interacts with content managed by multiple content management systems. Repository vendors get more applications: CMS vendors are more likely to get many more client applications using their server as any application that uses the CMIS API can access any CMIS repository. Applications get a bigger customer base: Applications that are written to support the CMIS interface are more likely to get a bigger customer base as they will work with a multitude of CMIS-compliant content management systems.
CMIS
Drupal
End User Repository 1
Alfresco
Repository 2
[ 12 ]
Chapter 1
CMIS
Mobile Website
End User Application
Alfresco
Repository
CMIS
SharePoint Enterprise Application
End User Application Repository 1
MuleESB
Service Broker
Alfresco
Repository 2
Another common scenario applicable to this use case is federated search, which is something that is really useful for end users. Instead of going into multiple applications to search for content in a disparate content management system, they can now just go into one search application that is hooked up to all the CMS systems.
[ 13 ]
Object ACE
1 0..1 1 id parent queryName displayName creatable queryable fileable controllablePolicy controllableACL fulltextIndexed 1 11..*
Property
id queryName displayName propertyType required cardinality choices defaultValue ... 0..*
ACL
Rendition
streamId mimeType length title kind height width 1 1
Document
Folder
Relationship
allowedSourceTypes allowedTargetTypes
Policy
Item
Secondary
Content Stream
length, mimeType, filename, stream
Legal Case
caseNumber
Group
Emailed
[ 14 ]
Chapter 1
Besides these base object types, there are a number of property types that can be used when dening new properties for an object type. They are, as can be seen in the preceding gure, String, Boolean, Decimal, Integer, and DateTime. Besides these property types, there are also the URI, ID, and HTML property types, which are not shown in the preceding gure. Let's take a closer look at each one of the following base types: Document: This base type is almost always the same as a le, although it doesn't need to have any content (when you upload a le via, for example, the AtomPub bindingexplained in the RESTful AtomPub binding section the metadata is created with the rst request and the content for the le is posted with the second request). The base document type is automatically assigned to any le, such as an MS Ofce document or an image, when it is uploaded to the repository. Folder: This is self-explanatory; it is a container for leable objects such as folders and documents. As soon as a folder or document is led in a folder, an implicit parent-child relationship is automatically created, which is different from the relationship base object type that has to be created manually. Whether an object is leable or not is specied in the object type denition with the fileable property. Relationship: This object denes a relationship between two objects (the target and source). An object can have multiple relationships with other objects. The support for relationship objects is optional. Policy: This is a way of dening administrative policies to manage objects. An object to which a policy may be applied is called a controllable object (the controllablePolicy property has to be set to true). For example, you can use a CMIS policy to dene which documents are subject to retention policies. A policy is opaque and means nothing to the repository. You would have to implement and enforce the behavior for your policy in a repositoryspecic way. For example, in Alfresco, you could use rules to enforce the policy. The support for policy objects is optional. Item (available from CMIS v1.1): This object represents a generic type of a CMIS information asset. This could be, for example, a user or group object. Item objects are not versionable and do not have content streams like documents, but they have properties like all other CMIS objects. The support for item objects is optional.
Additional object types can be dened in a repository as custom subtypes of these base types, such as the Legal Case type in the preceding gure. CMIS services are provided for the discovery of object types that are dened in a repository. However, object type management services, such as the creation, modication, and deletion of an object type, are not covered by the CMIS standard.
[ 15 ]
An object has one primary base object type, such as document or folder, which cannot be changed. An object can also have secondary object types applied to it (CMIS 1.1). A secondary type is a named class that may add properties to an object in addition to the properties dened by the object's primary base object type (if you are familiar with Alfresco, you can think of secondary object types to be the same as aspects; for example, emailed, versionable, published, and more). Every CMIS object has an opaque and immutable object identity (ID), which is assigned by the repository when the object is created. In the case of Alfresco, a so-called node reference is created, which becomes the object ID. An ID uniquely identies an object within a repository regardless of the type of the object. All CMIS objects have a set of named, but not explicitly ordered, properties. Within an object, each property is uniquely identied by its property ID. In addition, a document object can have a content stream, which is then used to hold the actual byte content for the le representing, for example, an image or a Word document. A document can also have one or more renditions associated with it. A rendition can be a thumbnail or an alternate representation of the content stream, such as a different size of an image. Document or folder objects can have one Access Control List (ACL), which then controls the access to the document or folder. An ACL is made up of a list of ACEs. An Access Control Entry (ACE) in turn represents one or more permissions being granted to a principal, such as a user, group, role, or something similar. Now, we may ask the questions such as, what does a document object look like?, what properties does it have?, what namespace is used?, and so on. The following gure shows you how the document object and the other objects are dened with properties:
CMIS Object Model
CMIS Object
cmis:objectId: Id cmis:baseTypeId: Id cmis:objectTypeId: Id cmis:secondaryObjectTypeIds: Id[] (CMIS 1.1) cmis:name: String cmis:description: String cmis:createdBy: String cmis:creationDate: DateTime cmis:lastModifiedBy: String cmis:lastModificationDate: DateTime cmis:changeToken
cmis:document
cmis:islmmutable: DateTime cmis:isLatestVersion: Boolean cmis:isMajorVersion: Boolean cmis:isPrivateWorkingCopy: Boolean cmis:versionLabel: String cmis:versionSeriesId: Id cmis:isVersionSeriesCheckedOut: Boolean cmis:versionSeriesCheckedOutBy: String cmis:versionSeriesCheckedOutId: Id cmis:checkinComment: String cmis:contentStreamLength: Integer cmis:contentStreamMimeType: String cmis:contentStreamFileName: String cmis:contentStreamId: Id
cmis:relationship
cmis:sourceId: Id cmis:targetId: Id
cmis:policy
cmis:policyText: String
cmis:item
cmis:folder
cmis:parentId: Id cmis:path: String cmis:allowedChildObjectTypeIds: Id[]
cmis:secondary
[ 16 ]
Chapter 1
All the objects and properties are dened in the cmis namespace. From now on, we'll refer to the different objects and properties by their fully qualied names, for example, cmis:document or cmis:name.
Services
The CMIS specication also denes the following set of services to access and manage the CMIS objects in the content repository: Repository services: These services are used to discover information about the repository, including repository IDs (could be more than one repository managed by the endpoint), capabilities (many features are optional and this is the way to nd out if they are supported or not), available object types, and descendants. If we are working with a CMIS v1.1-compliant repository, then it could also support creating new types dynamically on the y. The repository service methods are getRepositories, getRepositoryInfo, getTypeChildren, getTypeDescendants, getTypeDefinition, createType (CMIS 1.1), updateType (CMIS 1.1), and deleteType (CMIS 1.1). Navigation services: These services are used to navigate the folder hierarchy in a CMIS repository, and to locate documents that are checked out. The navigation service methods are getChildren, getDescendants, getFolderTree, getFolderParent, getObjectParents, and getCheckedOutDocs. Object services: These services provide ID-based CRUD (Create, Read, Update, and Delete) operations on the objects in a repository. The object service methods are createDocument, createDocumentFromSource, createFolder, createRelationship, createPolicy, createItem (CMIS 1.1), getAllowableActions, getObject, getProperties, getObjectByPath, getContentStream, getRenditions, updateProperties, bulkUpdateProperties (CMIS 1.1), moveObject, deleteObject, deleteTree, setContentStream, appendContentStream (CMIS 1.1), and deleteContentStream. Multiling services: These services are optional; they make it possible to put an object into several folders (multiling) or outside the folder hierarchy (unling). This service is not used to create or delete objects. The multiling service methods are addObjectToFolder and removeObjectFromFolder. Discovery services: These services are used to look for queryable objects within the repository (objects with the property queryable set to true). The discovery service methods are query and getContentChanges.
[ 17 ]
Versioning services: These services are used to manage versioning of document objects, other objects not being versionable. Whether or not a document can be versioned is controlled by the versionable property in the object type. The versioning service methods are checkOut, cancelCheckOut, checkIn, getObjectOfLatestVersion, getPropertiesOfLatestVersion, and getAllVersions. Relationship services: These services are optional and are used to retrieve the relationships in which an object is participating. The relationship service method is getObjectRelationships. Policy services: These services are optional and are used to apply or remove a policy object to an object which has the property controllablePolicy set to true. The policy service methods are applyPolicy, removePolicy, and getAppliedPolicies. ACL services: These services are used to discover and manage the access control list (ACL) for an object, if the object has one. The ACL service methods are applyACL and getACL.
As we can see, there are quite a few services at our disposal and we will see how they are used in the upcoming chapters. Note that when working with the different types of protocols and formats that the CMIS standard supports, the preceding method names might not be used. For example, if you wanted to get the children objects for an object, you would use the getChildren method from the navigation service. However, if we are using the AtomPub binding, this method would be referred to as the Folder Children Collection and can be accessed via a URL that looked similar to the following: .../children?id=....
Query language
The query method of the discovery service uses a query language that is based on a subset of the well known SQL-92 standard for database queries. It also has some ECM-specic extensions added to it. Each object type is treated as a logical relational table and joins are supported between these, creating a relational view of the CMIS model. The query language supports metadata and/or a full-text search (FTS is optional). The CMIS object type denitions contain some properties that are related to searching, which are as follows: The queryable property should be set to true if the object type should be searchable. Non-queryable object types are excluded from the relational view and cannot appear in the FROM clause of a query statement.
[ 18 ]
Chapter 1
The queryName property of a queryable object type is used to identify the object type in the FROM clause of a query statement. The includedInSuperType property determines if an object subtype is included in a query for any of its supertypes. So, it may be possible that all subtypes are not included in the query for a type. If an object type is not includedInSuperType, a direct query for the type is still supported if it is dened as queryable. For example, Alfresco internally models renditions as a subtype of cmis:document. Renditions are not marked as includedInSuperType and so will not appear in queries for cmis:document.
The following example selects all properties for all documents but does not include thumbnails (cm:thumbnail):
SELECT * FROM cmis:document
On the other hand, the following example includes cm:thumbnail and any subtypes that are set as includedInSuperType=true:
SELECT * FROM cm:thumbnail
To select specic properties for all documents, use the following query:
SELECT cmis:name, cmis:description FROM cmis:document
To select all documents that have a name containing the text alfresco, we can use the following:
SELECT cmis:name FROM cmis:document WHERE cmis:name LIKE '%alfresco%'
To perform a Full-Text Search (FTS), we need to use the SQL-92 CMIS extension CONTAINS() to look for any document with the text alfresco in it as follows:
SELECT * FROM cmis:document WHERE CONTAINS('alfresco')
The previous query will return all properties (columns) as we have used the wildcard *. There are also some folder-related SQL-92 CMIS extensions to search in a folder (IN_FOLDER) or folder tree (IN_TREE):
SELECT cmis:name FROM cmis:document WHERE IN_FOLDER('folder id')
The preceding query returns all documents in the folder with the identier folder id. A folder identier would be the same as a node reference in the Alfresco world. The following query returns all objects beneath the folder with folder id:
SELECT cmis:name FROM cmis:folder WHERE IN_TREE('folder id')
[ 19 ]
Protocol bindings
We have covered the object model and the available repository services. We also need to have a look at how we can actually communicate with the repository from a remote client over the wire. This is where protocol bindings come into the picture. There are three of them available: RESTful AtomPub, SOAP Web Services, and RESTful Browser (CMIS 1.1). CMIS-compliant repositories must provide a service endpoint (that is, the starting URL) for each of the bindings. The service URL and an understanding of the CMIS specications is all that a client needs to discover both the capabilities and content of a repository.
[ 20 ]
Chapter 1
Requests and responses made via the AtomPub binding are in the form of an Atom XML feed or an Atom XML entry. Usually, the response is extended to include CMIS-specic tags within one of the CMIS-specic namespaces.
[ 21 ]
Summary
In this chapter, we introduced the CMIS standard and how it came about. A couple of use cases, such as one client accessing multiple repositories, were presented, which illustrated the need for the standard. Then we covered the CMIS domain model with its ve base object types: document, folder, relationship, policy, and item (CMIS 1.1.). We also learned that the CMIS standard denes a number of services, such as navigation and discovery, which makes it possible to manipulate objects in a content management system repository. And nally, we looked at how we can communicate over the wire with a CMIS-compliant repository; this can be done with, for example, a REST-based approach over HTTP. So now that we know what CMIS is, let's take it for a spin. In the next chapter, we will start using it and see how we can manipulate objects in a CMIS-compliant repository.
[ 22 ]
Alternatively, you can buy the book from Amazon, BN.com, Computer Manuals and most internet book retailers.
www.PacktPub.com