Chapter 7. Extending the Alfresco Content Model

In the previous chapters, you were able to create content that had standard properties such as name, description, author, creation date, and timestamp. You were able to add aspects such as effectivity and Dublin core metadata to the content by using business rules. What if you need to have custom properties that are very specific to your business? What if you need to have custom content that handles the data and business rules in a way that suits your business needs? The Alfresco content model is highly configurable and easily extendable as per your business requirements. In this chapter, you will understand the process of customizing the content model. You will define your own custom properties and custom content type to extend the capabilities of your business application.

By the end of this chapter, you will have learned how to:

  • Configure a custom content model
  • Define and add a custom aspect (set of properties)
  • Define and use your custom content models
  • Define associated documents for your custom content types
  • Define constraints for your custom properties
  • Preview content using custom presentation templates
  • Enable dynamic customization of models without requiring a restart of the Alfresco server

Custom configuration

The Alfresco repository provides support for the storage, management, and retrieval of content. This content may range from coarse-grained documents, to fine-grained snippets of information such as XML elements. The Alfresco repository supports a rich data dictionary, where the properties, associations, and constraints of content are present to describe the structure of such content.

The Repository Data Dictionary is, by default, pre-populated with definitions that describe common content constructs such as folders, files, and metadata schemes. However, the data dictionary is extensible—it allows the repository to manage new types of content, as each business application will have its own content requirements. This chapter explains the main concepts behind the data dictionary, and explains how to perform tasks such as defining new types of content and using them in an application.

The following table describes some of the key terms used.

Key Term

Description

Property

A meta-data element that describes the content. For example, Author is a property which specifies the person who authored the content.

Content

Binary file (a Microsoft Word or HTML file, or an image) along with a set of properties (meta-data).

Association

Relationship between content items.

Constraint

Constraints control the input property values. For example, you can specify the author's name to be not more than 40 characters.

Aspect

A collection of properties, that and also defines the behavior.

Content Type

Provides a structure for creating content. The structure includes the nature of the content, properties, aspects, constraints and associations

Configuration files for the default content model

The core Alfresco configuration files are present in the application war file, and are expanded once the server starts. This location, referred to as <configRoot>, varies depending on the environment that Alfresco runs in.

JBoss: <JBOSS_HOME>/server/default/tmp/deploy/tmp*alfresco-exp.war/WEB-INF/classes

Tomcat: <TOMCAT_HOME>/webapps/alfresco/WEB-INF/classes

A Content Model is a collection of related content types and aspects. The default configuration files for the content model maintained by Alfresco are contained in the <configRoot>/alfresco/model folder, as shown in the following screenshot:

Configuration files for the default content model

The Alfresco repository is also primed with several domain models, which that are described as follows:

  • contentModel.xml: This model describes the Content Domain Model, such as folder, file, person, category, and dublin core
  • systemModel.xml: This model describes system-level Repository concepts
  • applicationModel.xml: This model describes the Alfresco Application Model
  • dictionaryModel.xml: This model describes the Dictionary Meta-model

Several other models that support the implementation of services are defined by the repository, such as user management, versioning, actions, advanced workflow, collaboration, calendar events, and rules. You can examine the other configuration files in the <configRoot>/alfresco folder.

Note

You should not modify the default content models located in the <configRoot>/alfresco folder. This will break the ability of Alfresco to perform automatic upgrades.

The next section explains the correct mechanism for adding custom content models to Alfresco.

Configuration files for custom content model

Alfresco is built on Spring, which is a leading platform for building and running enterprise Java applications. A bean is simply an object that is instantiated and managed by a Spring container. Alfresco configuration and customization concepts are based on the Spring framework.

Note

For more information about Spring, refer to the web site http://www.springsource.org/.

You can override or extend the Alfresco content model, by placing the custom configuration files in a folder. This location, referred to as extension, varies depending on the environment that Alfresco runs in.

JBoss: <JBOSS_HOME>/server/default/conf/alfresco/extension

Tomcat: <TOMCAT_HOME>/shared/classes/alfresco/extension

When you install Alfresco, the sample custom‑content files are copied to the extension folder, for your reference. You can also examine the sample custom‑configuration files in the extension folder.

The steps to define a custom model in the extension folder are as follows:

  1. Create a custom model Spring context file.
  2. Create a custom model definition file.
  3. Create a custom web client configuration file.

The custom model Spring context file instructs Spring on how to bootstrap or load the custom model definition file. The custom model definition file defines your custom content types, aspects, and associations. The custom web client configuration file contains information on how to to display these custom content types, aspects, and associations. The relationship between these files is shown in the following screenshot::

Configuration files for custom content model

Custom model context file

The custom model context file defines the Spring bean that will be used to bootstrap the definition of your custom model. It lists one or more custom model files. When Spring starts up, it will instantiate this bean and will load your model file from disk.

Create a custom model context file and name the file as <your-custom-model-name>-context.xml, for example intranetModel-context.xml.

Note

It is very important for you to note that the Alfresco server recognizes context files as being files that end with –context.xml.

The following is the content of the custom-model-context.xml.sample file in the extension folder. Note that the custom model context file defines the customModel.xml file as the custom model file.

<?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/customModel.xml</value>
            </list>
        </property>
    </bean>
 
</beans>

Custom model file

The custom model file contains the definitions for the custom content types, aspects, and content associations.

A copy of customModel.xml file already exists in the extension folder. If you examine the customModel.xml file, you will notice a custom namespace for all of the variables, called custom. XML namespaces provides a method for avoiding element name conflicts. Therefore, every custom variable will have the prefix custom in this file, as follows:

<namespace uri="custom.model" prefix="custom"/>

Custom web client configuration file

A copy of the web client configuration file web-client-config-custom.xml already exists in the extension folder. This web client configuration file ensures that the custom content types and aspects are visible in the Alfresco Web Client application. In this file, you can also override the default web client configuration that is provided out of the box.

Hierarchy of configuration files

The hierarchy of configuration files is shown in the following screenshot::

Hierarchy of configuration files

During startup, the Alfresco server reads the configuration files in the following order:

  • Context files and then the model files in the <configRoot>/alfresco folder
  • Context files and then the model files in the <extension> folder
  • Web client configuration files in the <configRoot>/alfresco folder
  • Web client configuration files in the <extension> folder
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset