Fork me on GitHub

How to use CMIS Replication Module

Prerequisites

These instruction assumes that you have maven 2 or 3 based build for your site.

Maven 2 repository

Add this repository to your root pom.xml:

    <repository>
      <id>hippo-maven2-forge</id>
      <name>Hippo Maven 2 Forge</name>
      <url>http://maven.onehippo.com/maven2-forge</url>
    </repository>

Specifying the dependency in a CMS/Repository Application project

Add the following dependency in your CMS/Repository Application project. CMIS Replication Module depends on Spring Daemon Module. So, you should add Spring Framework dependencies. One of the simplest ways to include Spring Framework dependency is to use HST-2's Spring Dependency POM dependency as described below.

    <!-- CMIS Replication requires Spring Daemon Module -->
    
    <dependency>
      <groupId>org.onehippo.cms7.hst.dependencies</groupId>
      <artifactId>hst-spring-dependencies</artifactId>
      <type>pom</type>
      <version>${hippo.hst.version}</version>
    </dependency>
    
    <!-- Spring Daemon Module dependency -->
    <dependency>
      <groupId>org.onehippo.forge.springdaemon</groupId>
      <artifactId>springdaemon</artifactId>
      <version>${forge.springdaemon.version}</version>
    </dependency>
    
    <!-- CMIS Replication Module -->
    <dependency>
      <groupId>org.onehippo.forge.cmisreplication</groupId>
      <artifactId>cmisreplication</artifactId>
      <version>${forge.cmisreplication.version}</version>
    </dependency>
        

With the dependency addtion of CMIS Replication Module, an asset document replicated from CMIS Repository will be of the following type:

<hippogallery='http://www.onehippo.org/jcr/hippogallery/nt/2.0'>
<cmisreplication='http://www.onehippo.org/jcr/cmis/cmisreplication/nt/1.0'>

[cmisreplication:exampleAssetSet] > hippogallery:exampleAssetSet
- cmisreplication:objectId (string)
- cmisreplication:name (string)
- cmisreplication:createdBy (string)
- cmisreplication:creationDate (date)
- cmisreplication:lastModifiedBy (string)
- cmisreplication:lastModificationDate (date)
- cmisreplication:versionLabel (string)
- * (string) 
- * (string) multiple
- * (boolean) 
- * (boolean) multiple
- * (long) 
- * (long) multiple
- * (double) 
- * (double) multiple
- * (date) 
- * (date) multiple
        

All the new property definitions with 'cmisreplication' prefix are for CMIS Document Metadata. Also, if you want to customize the replicator POJO bean, you may add any other properties easily because it already contains anonymous property definitions.

Add your POJO beans with Leveraging Spring Framework Components

Add a resource, classpath:org/onehippo/forge/springdaemon/SpringDaemonModule.xml. Normally, you can add a file under /WEB-INF/classes/ to override the configuration.

<!-- classpath:org/onehippo/forge/springdaemon/SpringDaemonModule.xml -->

<beans xmlns="http://www.springframework.org/schema/beans" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
  
  <!-- Import demo scheduler -->
  <import resource="classpath:org/onehippo/forge/cmisreplication/cmis-replication-scheduler.xml" />
  
</beans>
        

In the configuration above, a separated scheduler configuration, cmis-replication-scheduler.xml, can be added somewhere. You can choose any location.

<!-- classpath:org/onehippo/forge/cmisreplication/cmis-replication-scheduler.xml -->

<beans xmlns="http://www.springframework.org/schema/beans" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:task="http://www.springframework.org/schema/task"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                           http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd">
  
  <!-- To use an external properties file, put Spring's built-in PropertyPlaceholderConfigurator here. -->
  <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <!-- You can use any configuration properties file location -->
    <property name="location" value="classpath:org/onehippo/forge/cmisreplication/cmis-replication-scheduler.properties" />
  </bean>
  
  <!-- Put Spring Daemon's built-in SessionAware bean which provides JCR session through #getSession() -->
  <bean id="jcrSessionProvider" class="org.onehippo.forge.springdaemon.SessionProvider" />
  
  <!-- The CMIS Documents Replicator POJO Bean -->
  <bean id="cmisDocumentsReplicator" class="org.onehippo.forge.cmisreplication.CmisDocumentsReplicator">
    <property name="jcrSession">
      <bean class="org.springframework.beans.factory.config.PropertyPathFactoryBean">
        <property name="targetObject" ref="jcrSessionProvider" />
        <property name="propertyPath" value="session" />
      </bean>
    </property>
    <property name="cmisRepoConfig">
      <bean class="org.onehippo.forge.cmisreplication.CmisRepoConfig">
        <property name="url" value="${cmis.replication.source.url}" />
        <property name="username" value="${cmis.replication.source.username}" />
        <property name="password" value="${cmis.replication.source.password}" />
        <property name="repositoryId" value="${cmis.replication.source.repositoryId}" />
        <property name="rootPath" value="${cmis.replication.source.rootPath}" />
        <property name="maxItemsPerPage" value="500" />
        <property name="skipCount" value="0" />
      </bean>
    </property>
    <property name="hippoRepoConfig">
      <bean class="org.onehippo.forge.cmisreplication.HippoRepoConfig">
        <property name="rootPath" value="${cmis.replication.target.rootPath}" />
      </bean>
    </property>
    <property name="updateCmisDocumentsToRepository" value="${cmis.replication.updateCmisDocumentsToRepository}" />
    <property name="updateRepositoryDocumentsToCmis" value="${cmis.replication.updateRepositoryDocumentsToCmis}" />
  </bean>
  
  <!-- Simple Task Scheduler Task configuration which executes the POJO, cmisDocumentsReplicator. -->
  <task:scheduled-tasks scheduler="cmisDocImportingScheduler">
    <task:scheduled ref="cmisDocumentsReplicator" method="execute" fixed-delay="${cmis.replication.execution.delay}" />
  </task:scheduled-tasks>
  
  <!-- Simple Java Task Executor scheduler configuration -->
  <task:scheduler id="cmisDocImportingScheduler" pool-size="1" />

</beans>
        

In the example scheduler configuration above, we added the simple POJO, cmisDocumentsReplicator, which basically replicates/synchronizes from CMIS Repository to Hippo Repository. This bean can be just copied and pasted in your project.

# classpath:org/onehippo/forge/cmisreplication/cmis-replication-scheduler.properties

# CMIS Replication Scheduler Execution Fixed Delay Time in Milliseconds
cmis.replication.execution.delay = 10000
# CMIS Replication Source CMIS URL
cmis.replication.source.url = http://localhost:8080/nuxeo/atom/cmis
# CMIS Replication Source CMIS Repository ID
cmis.replication.source.repositoryId = default
# CMIS Replication Source CMIS Repository Credentials
cmis.replication.source.username = Administrator
cmis.replication.source.password = Administrator
# CMIS Replication Source CMIS Repository Root Path where documents are replicated from.
cmis.replication.source.rootPath = /default-domain/sections/marketing
# CMIS Replication Target Hippo Repository Root Path where documents are replicated to.
cmis.replication.target.rootPath = /content/assets/marketing
# Flag whether the replication from source to target is on/off
cmis.replication.updateCmisDocumentsToRepository = true
# Flag whether the replication from target to source is on/off; 
# When turned on, deleting an asset from Hippo Repository triggers deleting the corresponding document in CMIS Repository.
cmis.replication.updateRepositoryDocumentsToCmis = false
        

To externalize the configuration, we have a separated properties file which is used by the Spring's built-in PropertyPlaceholderConfigurer.

For the POJO, cmisDocumentsReplicator, you can configure the following properties as shown above:

Property Path Description Example Value Default Value
jcrSession The JCR Session used to connect to Hippo Repository. The JCR Session is always given to a bean implementing SessionAware interface by the Spring Daemon Module. In the example configuration above, the built-in SessionProvider bean implements SessionAware, so we just use #getSession() property getter to inject JCR Session.
cmisRepoConfig.url CMIS Repository Server URL http://localhost:8080/nuxeo/atom/cmis
cmisRepoConfig.username The user name for CMIS Repository Administrator
cmisRepoConfig.password The password for CMIS Repository Administrator
cmisRepoConfig.repositoryId The Repository ID of the CMIS Repository default
cmisRepoConfig.rootPath The source CMIS Repository Document Path where documents are replicated from /default-domain/sections/marketing
cmisRepoConfig.maxItemsPerPage The max item count which is configured to Open CMIS Operation Context API 500 100
cmisRepoConfig.skipCount The skip count which is configured to Open CMIS Operation Context API 0 0
hippoRepoConfig.rootPath The target Hippo Repository Asset Documents Path where documents are replicated to /content/assets/marketing
updateCmisDocumentsToRepository Flag whether the replication from source to target is on/off true false
updateRepositoryDocumentsToCmis Flag whether the replication from target to source is on/off; When turned on, deleting an asset from Hippo Repository triggers deleting the corresponding document in CMIS Repository. false false