Behaviors - maksudsharif/Armedia-Training-Module GitHub Wiki
Behaviors
If you haven't completed Jeff Pott's tutorial on Behaviors, read and complete that before following along here.
Behaviors allow you to complete automatic tasks that are triggered based on events that occur within Alfresco. It is a very powerful way to fine tune content rules and common tasks associated with it. An example of a simple behavior that we will implement is generating unique IDs. There are two ways of implementing a behavior, Java and JavaScript. I am going to focus on using Java, but either way is fine.
The way to create behaviors is simple:
- Create a Java class that implements a
Policy
. - Create a bean for the aforementioned Java class.
There are several ServicePolicies
contains Policies to which custom behaviors can be bound to. Whenever a certain policy is triggered (by events in Alfresco), all associated behaviors bound to that Policy will be triggered. Jeff Potts' tutorial has a good list of potential Policies to use. The big 3 that are very useful are: onCreateNode
, onUpdateProperties
, and onMoveNode
.
If you have completed the Jeff Potts tutorial on Behaviors, you should have a good foundation of the types of things that can be done with Behaviors. For the assignment, you are going to be implementing a simple GenerateID
behavior and subsequently create Behaviors to support the Draft/Pending/Publish
folder structure.
Things to Know
Useful NodeServicePolicies
Interface | Method |
---|---|
org.alfresco.repo.content.ContentServicePolicies | onContentPropertyUpdate |
onContentRead | |
onContentUpdate | |
org.alfresco.repo.copy.CopyServicePolicies | beforeCopy |
onCopyComplete | |
onCopyNode | |
org.alfresco.repo.node.NodeServicePolicies | beforeAddAspect |
beforeArchiveNode | |
beforeCreateNode | |
beforeCreateStore | |
beforeDeleteAssociation | |
beforeDeleteChildAssociation | |
beforeDeleteNode | |
beforeMoveNode | |
beforeRemoveAspect | |
beforeSetNodeType | |
beforeUpdateNode | |
onAddAspect | |
onCreateAssociation | |
onCreateChildAssociation | |
onCreateNode | |
onCreateStore | |
onDeleteAssociation | |
onDeleteChildAssociation | |
onDeleteNode | |
onMoveNode | |
onRemoveAspect | |
onSetNodeType | |
onUpdateNode | |
onUpdateProperties | |
org.alfresco.repo.version.VersionServicePolicies | beforeCreateVersion |
afterCreateVersion | |
onCreateVersion | |
calculateVersionLabel |
PolicyComponent/Java Behaviour
When creating a new behavior you must have an init-method which binds the behavior to an appropriate policy. A good guideline for proper binding is as follows:
this.policyComponent.bindClassBehaviour(NodeServicePolicies.OnCreateNodePolicy.QNAME, ContentModel.CONTENT_TYPE, new JavaBehaviour(this, "onCreateNode", Behaviour.NotificationFrequency.TRANSACTION_COMMIT));
Assignments
Generating IDs
To implement this behavior you will need:
- Java class implementing an appropriate policy
- Add a corresponding bean to inject appropriate Alfresco services and register the behavior
In the included code, a framework for what you might need is provided for you. Some things you should consider include: which policy is appropriate for this behavior and what Alfresco Services will I need.
Publish Folders Model
To implement this behavior you will need:
- Java class(es) implementing appropriate policies.
- Corresponding beans to inject appropriate Alfresco services and register the behaviors.
This behavior consists of a general workflow: Submission ( or Upload to Draft folder) -> Move to Draft -> Notify a Coordinator to review -> Move to pending based on outcome -> Start general review -> Move to Published based on outcome.
It is recommended you split up the behaviors into multiple classes, however you also use a single behavior class but it increases the complexity.