My previous blog talks about extending CMIS data model for Open-CMIS in memory repository. In this blog I will explain on extending CMIS content model for alfresco repository.
Alfresco provides mechanism for extending CMIS data model. All we have to do is just register custom data model.
First step would be defining the custom content model. Defined custom content model should follow modelSchema.xsd which can be found under Alfresco\tomcat\webapps\alfresco\WEB-INF\classes\alfresco\model.
Let’s take an example where I want to define custom document type with addition properties.
<type name="Lib:BookHistory">
<title>Book History</title>
<parent>cm:doc</parent>
<properties>
<property name="Lib:BookId">
<type>d:text</type>
<mandatory>true</mandatory>
</property>
</properties>
</type>
Suppose we name this file as LibModel.xml. Complete content of the file is attached at the end of blog.
Now the next step would be registering our content model as extension. For that we need to create a file with suffix context in the name referring to custom model i.e. Lib-model-context.xml.
Name can be anything as long as it has suffix context. Custom model can be referred in the custom file as follows-
<!-- Registration of new models -->
<bean id="extension.dictionaryBootstrap" parent="dictionaryModelBootstrap" depends-on="dictionaryBootstrap">
<property name="models">
<list>
<value>alfresco/extension/LibModel.xml</value>
</list>
</property>
</bean>
We need to put these xml files in following directory Alfresco\tomcat\webapps\alfresco\WEB-INF\classes\alfresco\extension.
Using custom model in Open-CMIS:
Custom types can be referred with prefix D: and custom properties can be referred as it is in Open-CMIS client API. For example in case of our custom defined model type will be referred as D: Lib:BookHistory and property will be referred as Lib:BookId.
Issue with the alfresco:
Alfresco community edition 3.3 has a bug which doesn’t allow CMIS client to persist values for custom properties in alfresco repository. Fix for this is available in alfresco head build.
Content of LibModel.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Definition of new Model -->
<model name="Lib:LibModel" xmlns="http://www.alfresco.org/model/dictionary/1.0">
<!-- Optional meta-data about the model -->
<description>Someco Model</description>
<author>Optaros</author>
<version>1.0</version>
<!-- Imports are required to allow references to definitions in other models -->
<imports>
<!-- Import Alfresco Dictionary Definitions -->
<import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d" />
<!-- Import Alfresco Content Domain Model Definitions -->
<import uri="http://www.alfresco.org/model/content/1.0" prefix="cm" />
</imports>
<!-- Introduction of new namespaces defined by this model -->
<namespaces>
<namespace uri="http://www.someco.com/model/content/1.0" prefix="Lib" />
</namespaces>
<types>
<!-- Enterprise-wide generic document type -->
<type name="Lib:BookHistory">
<title>Book Histroy</title>
<parent>cm:content</parent>
<properties>
<property name="Lib:BookId">
<type>d:text</type>
<mandatory>true</mandatory>
</property>
</properties>
</type>
</types>
</model>
Content of Lib-model-context.xml
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
<!-- Registration of new models -->
<bean id="extension.dictionaryBootstrap" parent="dictionaryModelBootstrap" depends-on="dictionaryBootstrap">
<property name="models">
<list>
<value>alfresco/extension/LibModel.xml</value>
</list>
</property>
</bean>
</beans>
No comments:
Post a Comment