Dynamic models

You are able to customize Alfresco by using custom content types. These customizations are typically deployed via the alfresco/extension folder and require the Alfresco server to be re-started to take effect. Since version 2.9, Alfresco supports dynamic models to facilitate the dynamic customization of models without requiring a restart of the Alfresco server.

Dynamic models are nothing but XML based model files that are uploaded to Alfresco's repository in the Company Home/Data Dictionary/Model space.

The following are the advantages of Dynamic models:

  • There is no need to restart Alfresco Server every time you make changes to the model files.
  • Both the content as well as the model files are stored in the repository. It is easier to maintain and move content along with the model files.
  • All of the model files in the <extension> folder will be considered active and will be loaded by Alfresco. However, you can activate and inactivate the dynamic models by keeping the model XML file in the repository.
  • In a multi-tenant setup, the models defined in the <extension> folder are available to all tenants. If you would like to customize content types and custom aspects for a specific tenant only, then adynamic model is the best choice.

Dynamic custom model

Creating a dynamic custom model is the same as creating a regular custom model. For this example, create a custom content type that has two properties. Create a file named dynamicModel1.xml on your personal computer with the following content.

<?xml version="1.0" encoding="UTF-8"?>

<!-- Dynamic Model -->

<model name="dynamic:dynamicModel" xmlns="http://www.alfresco.org/model/dictionary/1.0">

   <!-- Optional meta-data about the model -->   
   <description>Dynamic Model</description>
   <author></author>
   <version>1.0</version>

   <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 -->
   <!-- NOTE: The following namespace dynamic.model should be changed to reflect your own namespace -->
   <namespaces>
      <namespace uri="dynamic.model" prefix="dynamic"/>
   </namespaces>

   <types>

      <!-- Definition of new Content Type: Model1 -->
      <type name="dynamic:Model1">
         <title>Dynamic Model ONE</title>
         <parent>cm:content</parent>
         <properties>
            <property name="dynamic:property11">
               <title>Dynamic Property 11</title>
               <type>d:text</type>
            </property>
            <property name="dynamic:property12">
               <title>Dynamic Property 12</title>
               <type>d:text</type>
            </property>
         </properties>
      </type>

   </types>

</model>

Deploying a custom model

Deploying a custom model is as simple as uploading the model file to a specific space in Alfresco. Log in to Alfresco Explorer and go to the Company Home > Data Dictionary > Model space. Upload the dynamicModel1.xml file.

Activating and deactivating a custom model

By default, the model will not be active unless the Model Active checkbox is selected during the upload. To activate a previously-inactive model, select View Details and then select the Modify properties icon. In the Modify Content Properties page, select the Model Active checkbox.

Similarly, to inactivate a custom model, deselect the Model Active checkbox.

Activating and deactivating a custom model

Updating a custom model

You can directly edit or update the XML model file. If the model is active, then it will be re-loaded. If the file is checked-out, then the working copy will be ignored until such a time as the file is checked-in.

Dynamic web client

A dynamic web client configuration file will have the same name as a custom web client configuration file. For example, create a web-client-config-custom.xml file, with the content as given below, to support the dynamic content type that you created earlier.

<alfresco-config>

   <config evaluator="string-compare" condition="Content Wizards">
      <content-types>
         <type name="dynamic:Model1" />
      </content-types>
   </config>

   <config evaluator="node-type" condition="dynamic:Model1">
      <property-sheet>
         <show-property name="mimetype" display-label-id="content_type" 
                       component-generator="MimeTypeSelectorGenerator" />
         <show-property name="dynamic:property11" />
         <show-property name="dynamic:property12" />
      </property-sheet>
   </config>

   <!-- Lists the custom content type in business rules Action wizard -->
   <config evaluator="string-compare" condition="Action Wizards">
      <subtypes>
         <type name="dynamic:Model1"/>
      </subtypes>      
   </config>

</alfresco-config>

Deploying web client customizations

Deploying a dynamic web client configuration is as simple as uploading it to a specific space in Alfresco. Log in to Alfresco Explorer and go to the Company Home > Data Dictionary > Web Client Extension space. Upload the web-client-config-custom.xml file.

The custom configuration will not be applied until it is explicitly re-loaded (refer to the following section) or when the server is restarted.

Reloading web client customizations

If the web-client-config-custom.xml file has been added, edited, or updated, it can be dynamically reloaded by using the web client configuration console via:

http://<server>:<port>/alfresco/faces/jsp/admin/webclientconfig-console.jsp

This has a single command, reload, which will cause the web client configuration to be re-loaded.

Dynamic models in a multi-tenancy environment

Alfresco supports a multi-tenancy architecture, where a single instance of the software serves multiple client organizations (tenants). In Chapter 14, the section named Administering and maintaining the system contains information about setting up Alfresco in a multi-tenant environment.

When configured for a multi-tenant environment, Alfresco virtually partitions its data and configuration so that each client organization works within a customized virtual application instance. By default, the models defined in the <extension> folder are available to all of the tenants.

If you would like custom content types and custom aspects for a specific tenant only, then dynamic models are the best choice.

To test this out, create few tenant accounts (say, TenantA and TenantB), according to the instructions given in Chapter 14, Administering and Maintaining the System. Log in as a specific tenant administrator (say TenantA) and create a dynamic content type and use it. Now, log in as a different tenant administrator (say TenantB), and you will notice that the dynamic content type created by TenantA is not available to TenantB.

..................Content has been hidden....................

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