Content Migration with Camel-CMIS
Join the DZone community and get the full member experience.
Join For FreeSome time ago(actually quite a long time ago now) I was playing with CMIS using Apache Chemistry, Camel, Talend… and created a camel-cmis connector. And recently this component reached camel trunk, so here are some example how it can be used.
Motivation
Content Management Interoperability Services (CMIS) is an open standard that defines an abstraction layer for accessing diverse document management systems and repositories using web protocols. Administered by OASIS and backed by Adobe, Alfresco, HP, IBM, Microsoft, Oracle and many more, it defines data model and query language for accessing content repositories in a language agnostic way.
Apache Chemistry project provides open source implementations of the CMIS specification. It has implementations in Java, Python, PHP and .Net.
CAMEL-CMIS
The component uses OpenCMIS (Apache Chemistry's Java implementation) and contains a producer and a consumer. The producer can be used in two ways:Create nodes (documents with content data, folders and other node types) from Camel messages. In the example below, the route will copy all of the files from the local file system into a demo directory in Alfresco demo cmis server using the file name as node name.
public class CamelCmisFileUploader extends RouteBuilder { public void configure() { from("file:src/demo?noop=true") .process(new Processor() { public void process(Exchange exchange) throws Exception { exchange.getIn().getHeaders().put(PropertyIds.CONTENT_STREAM_MIME_TYPE, "text/plain; charset=UTF-8"); exchange.getIn().getHeaders().put(PropertyIds.NAME, exchange.getIn().getHeader(Exchange.FILE_NAME)); exchange.getIn().getHeaders().put(CamelCMISConstants.CMIS_FOLDER_PATH, "/demo"); } }) .to("cmis://http://cmis.alfresco.com/cmisatom?repositoryId=371554cd-ac06-40ba-98b8-e6b60275cca7&username={{username}}&password={{password}}"); } }Query the content repository using cmis query language. The result of the query is a list in the body of the message. The route below will retrieve all documents with name containing the word 'camel', split them and store each one into the local file system, using the document name as the file name.
public class CamelCmisQueryProducer extends RouteBuilder { public void configure() { from("timer://foo?repeatCount=1") .setBody(constant("SELECT * FROM cmis:document WHERE cmis:name LIKE '%camel%'")) .to("cmis://http://cmis.demo.nuxeo.org/nuxeo/atom/cmis&username={{username}}&password={{password}}&queryMode=true&readContent=true") .split(body()) .process(new Processor() { public void process(Exchange exchange) throws Exception { Map<String, Object> body = (Map<String, Object>)exchange.getIn().getBody(); exchange.getIn().getHeaders().put(Exchange.FILE_NAME, body.get(PropertyIds.NAME)); exchange.getIn().setBody(body.get(CamelCMISConstants.CAMEL_CMIS_CONTENT_STREAM)); } }) .to("file:src/demo"); } }The consumer accepts a cmis query through the options. If the query string is not provided, the consumer will iterate the complete content tree recursively starting from the root node. Using this option you can replicate the complete cmis structure into another cmis repository (as in the following example, which tries to copy the complete alfresco repo into nuxeo one - don't do this at home) or back it up into the local file system. Notice that to retrieve the actual content data for document nodes, you have to set the readContent option additionally.
public class CamelCmisRepositoryReplication extends RouteBuilder { public void configure() { from("cmis://http://cmis.alfresco.com/cmisatom?repositoryId=371554cd-ac06-40ba-98b8-e6b60275cca7&username={{username}}&password={{password}}&readContent=true") .to("cmis://http://cmis.demo.nuxeo.org/nuxeo/atom/cmis?username={{username}}&password={{password}}"); } }If the target repository doesn't support support CMIS, but JCR try replacing the endpoint with the camel-jcr component, or choose something else from one of the 120 existing Camel components.
File system
Published at DZone with permission of Bilgin Ibryam, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
The SPACE Framework for Developer Productivity
-
Auditing Tools for Kubernetes
-
Redefining DevOps: The Transformative Power of Containerization
-
Real-Time Made Easy: An Introduction to SignalR
Comments