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.

11 comments:

  1. in the first steps you say to copy custom-model-context.xml and then edit customModel.xml. is there a missing step or miswritten file names?
    thanks, this blog is very interesting

    ReplyDelete
  2. Thanks for pointing this out!
    In the first step you rename the custom-model-context.xml.sample file and in the second step you will edit the customModel.xml to add our custom aspect.
    The "custom-model-context.xml" file has a ref. to the "customModel.xml" where the actual aspect is defined.

    Sorry for the delay in response. Please let me know if you have any other question.

    ReplyDelete
  3. Thanks for the information, but after creating the custom aspect, I tried adding a file to the folder, I get the error msg "•Failed to create content due to error: 02150012 The aspect is invalid: {custom.model}ProductDetails"
    Do you know what I am missing?
    Thx

    ReplyDelete
  4. Hi Kina - If you have not solved this already, you can send me the customModel.xml file and I can look at it.

    ReplyDelete
  5. hi i have a problem with add customer details.
    when i add new document i get this error
    Failed to create content due to error: 06050000 The aspect is invalid: {http://www.alfresco.org/model/content/1.0}Customer Details
    please help me

    ReplyDelete
  6. please send me the answer as soon as possible.

    ReplyDelete
  7. Great! Easy steps to get aspects work!

    ReplyDelete
  8. Cannot find custom-model-context.xml.sample file in the Alfresco Community version I installed last week...

    Any ideas?
    Thanks!

    ReplyDelete
  9. Hi, I did as per your article, I am able to see the Product details when I check in using the Alfresco(http://ip:8080/Alfresco). But when I try to check in using Share(http://ip:8080/share) I cannot see the Product details. What should I do to see the same information when I checking using share. Also while checking in the document properties in SHARE I cannot see the Product details
    Thanks
    Joseph John

    ReplyDelete
  10. language : French

    bonjour,
    merci beaucoup , votre tutoriel me bien plaƮt.

    ReplyDelete
  11. hiiiiiiiiiii,dis example is not working,send me the correct answer as soon as possible.

    ReplyDelete