Thursday, July 30, 2009

Constraints in Alfresco

Constraints enable validating user input.  In a simplest term these are validation rules that can be defined and applied to aspects and content types.  Constraints are defined separately from aspects and content types, enabling reuse and  better manageability. You can refer to constraints from within the property type definition of an aspect or content type.

Alfresco version 3.2 Community

Out of the box there are four types of constraints available.  Of course as anything else in Alfresco, you can create your own custom constraint types as needed.  Constraint types available out of the box include: REGEX, LIST, MINMAX, and LENGTH.  These are self explanatory so won’t go in details explaining these.

Below are a couple of examples of how to create custom constraints using out of the box constraints types.  In the following, we will also see an example of how to use these constraints in aspects.

  • Open customModel.xml file for editing (location /tomcat/shared/classes/alfresco/extensions)
  • Between </namespaces> and <types> add following custom constraints

<constraints>
  <constraint name="custom:product_list" type="LIST">
    <parameter name="allowedValues">
      <list>
        <value>Laptops</value>
        <value>Harddrives</value>
        <value>Memory</value>
      </list>
    </parameter>
  </constraint>
  <constraint name="custom:name_length" type="LENGTH">
    <parameter name="minLength">
      <value>5</value>
    </parameter>
    <parameter name="maxLength">
      <value>25</value>
    </parameter>
  </constraint>
</constraints>

  • Above we created two custom constraints using LIST and LENGTH constraint types
  • Now to use these constraints simply add  constraints in the property type definition of an aspect or content type.  Below we will add constraint to an aspect

<aspects>
  <aspect name="custom:ProductDetails">
    <title>Product Details</title>
    <properties>
      <property name="custom:ProductName">
        <title>Product Name</title>
        <type>d:text</type>
        <protected>false</protected>
        <mandatory>true</mandatory>
        <multiple>false</multiple>
        <constraints>
          <constraint ref="custom:name_length"/>
        </constraints>

      </property>

Tuesday, July 28, 2009

Configuring Alfresco Explorer Space Views

Alfresco Version: 3.2 Community Version

Alfresco provides four different ways to view a space out of the box. This is similar to the "Views" option available in the windows explorer (Microsoft Windows). Different available view options are:

  • Details View: Displays detailed information about documents. This is a table like view.
  • Icon View: Default view displays icon, name, and modification date time property in addition to the actions icons.
  • Browse View: Display spaces and any sub-spaces under it.
  • Custom View: By default disabled as no custom views are available out of the box.

Out of the box "Icon View" is the default view and if you change it to something else, the change is effective only for that session. You can modify the default configuration and make something else as a default view. You can also change the number of documents displayed per page. Below are the steps to make these configuration changes.

Note: These configuration changes are global and will changes the behavior for all the users.

  • Go to the extensions folder (/tomcat/shared/classes/alfresco/extensions) and open web-client-config.xml file for editing
  • Add the following code block at the end of the file, right above </alfresco-config>

<config evaluator="string-compare" condition="Views">
  <views>
    <view-defaults>
      <browse>
        <view>details</view>
        <page-size>
        <list>10</list>
        <details>20</details>
        <icons>9</icons>
        </page-size>
      </browse>
    </view-defaults>
  </views>
</config>

  • Save and close

You can reload the configuration either by restarting alfresco or by using the utility provided in Alfresco. To reload configuration without restarting, follow these steps

Saturday, July 11, 2009

Additional properties using aspect

This is one basic question that every one asks especially if you worked on other commercial ECM platforms such as EMC's Documentum or IBM's FileNet.

In Alfresco, adding custom properties (meta-data) can be achieved in a couple of ways:
  • Creating custom aspect
  • Creating custom content type
Both has its own benefits, which one to choose depends on the business problem you are trying to solve. I will discuss this later in other post.
For now, below are the detailed steps for creating a custom aspect and then creating a business rule to capture the data for the properties defined in the custom aspect.

Steps for version 3.2 Community 
  • Go to the extensions folder (/tomcat/shared/classes/alfresco/extensions) and rename the custom-model-context.xml.sample to custom-model-context.xml if you haven't extended the model yet.
  • Open customModel.xml file and add your custom aspect at the end of the file, right above "</model>". For e.g. you can add the following, this will add a custom aspect called ProductDetails
<aspects>
<aspect name="custom:ProductDetails">
<title>Product Details</title>
<properties>
<property name="custom:ProductName">
<title>Product Name</title>
<type>d:text</type>
<protected>false</protected>
<mandatory>true</mandatory>
<multiple>false</multiple>
</property>
<property name="custom:ProductDescription">
<title>Product Description</title>
<type>d:text</type>
</property>
<property name="custom:ProductID">
<title>Product ID</title>
<type>d:int</type>
</property>
</properties>
</aspect>
</aspects>
  • Now modify web-client-config-custom.xml file in the extension folder. This will enable the web client application to recognize the new custom aspect and display it in the web interface.
  • Add the following XML code at the end of the file, right above </alfresco-config>. This will list our custom aspect in the business rules "Set action values" page.
<config evaluator="string-compare" condition="Action Wizards">
<aspects>
<aspect name="custom:ProductDetails"/>
</aspects>
</config>
  • Still in web-client-config-custom.xml file. Add the following right after the above code block. The code below will ensure that the custom properties will be displayed in the content's view details page.
<config evaluator="aspect-name" condition="custom:ProductDetails">
<property-sheet>
<separator name="sepProduct1" display-label="Product Details" component-generator="HeaderSeparatorGenerator" />
<show-property name="custom:ProductName"/>
<show-property name="custom:ProductDescription"/>
<show-property name="custom:ProductID"/>
</property-sheet>
</config>
  • Now we have our custom aspect defined with our additional properties that we want to capture based on our business rules. Lets restart alfresco now for the bootstrap to load this information.
  • Use custom aspect as a business rule.
  • Log in to alfresco as an admin and navigate to the space where you want to capture additional properties.
  • While in the space for e.g. Company Home > Products, click "More Actions" and then "Manage Content Rules"
  • Click "Create Rule", this is a 4 step process
  • Step1: Select Condition: All Items
  • Step2: Select Action: Add aspect to item; Set Values: Product Details
  • Step3: Type: Inbound; Title: <some title>; Description: <some description>; Check apply rule to sub spaces;
  • Step4: Review and click Finish
Thats it you are done! try adding documents to the "Product" space, you will see your custom properties.