Custom Behavior in Alfresco

In Previous article I have explain about Behavior and Policies in Alfresco. Now in this Article I am going to explain how to implement Custom Behavior with one example. We have a requirement where we want to keep track of number of time a document is viewed in this case we cannot use any rule we are going to use behavior . We will have one property which will keep track of number of time documents is viewed value of that property will be incremented each time anyone view the document. We can achieve this by following below steps.

Step 1:

Create custom aspect with Custom property No of Document Views. If you are not aware about custom content model you can refer my previous articles to implement this.

“custom:docviewno”

Step 2:

Identify the policy which needs to be associated with behavior to achieve our goal. In this case we need to invoke our code each time document is viewed and for this operation we can use this policy.

Generally this class has two dependencies that Spring will handle for us. One is the NodeService which will be used in the average calculation logic and the other is the PolicyComponent which is used to bind the behavior to the policies.