cancel
Showing results for 
Search instead for 
Did you mean: 

bindAssociationBehaviour ... how?

marcus
Champ in-the-making
Champ in-the-making
I'm trying to bind a behaviour to the onCreateChildAssociation event, but can't figure out what's meant for what… as you can see below, I've tried binding against both the parent and child class of the association, but my method for implementing the behaviour is never getting called when I add a new document to a folder. How should I be binding?


public void initialise() {
   QName onCreateChildName = QName.createQName(NamespaceService.ALFRESCO_URI, "onCreateChildAssociation");
   
   this.policyComponent.bindAssociationBehaviour(
         onCreateChildName,
         ContentModel.TYPE_FOLDER,
         new JavaBehaviour(this, "onCreateChildAssociation")
   );
   this.policyComponent.bindAssociationBehaviour(
         onCreateChildName,
         ContentModel.TYPE_CONTENT,
         new JavaBehaviour(this, "onCreateChildAssociation")
   );
   logger.debug("Behaviours bound");
}

public void onCreateChildAssociation(ChildAssociationRef childAssocRef)
{
   logger.debug("Added new child "+childAssocRef.getChildRef().getId()+" to "+childAssocRef.getParentRef().getId());
}
2 REPLIES 2

jmliege
Champ in-the-making
Champ in-the-making
Hi,

I think that the problem is your parameters:

this.policyComponent.bindAssociationBehaviour(
         onCreateChildName,
         ContentModel.TYPE_FOLDER,
         new JavaBehaviour(this, "onCreateChildAssociation")
   );

You should replace the 'ContentModel.TYPE_FOLDER' argument by the 'this' reserved keyword, but in this case, each children associations will trigger this behavior…

Take a glance at the following Alfresco's code, it may help you to understand : org.alfresco.repo.node.index.NodeIndexer

I think you can also specify on which association the behavior should be triggered through an overloaded version of the function.
In this one ,you can specify the associationRef QName.


See org.alfresco.repo.policy.PolicyComponent interface :

/**
* Bind an Association specific behaviour to an Association-level Policy
*
* @param policy  the policy name
* @param className  the class to bind against
* @param assocRef  the association to bind against
* @param behaviour  the behaviour
* @return  the registered behaviour definition
*/
public BehaviourDefinition<ClassFeatureBehaviourBinding> bindAssociationBehaviour(QName policy, QName className, QName assocName, Behaviour behaviour);

Hope it helps,

JMarc





marcus
Champ in-the-making
Champ in-the-making
Thanks for the reply. I had seen the NodeIndexer code actually, but it's not quite what I'm after as that uses service level association behaviour, which from what I can tell is executed for every association. The one I'm trying to use is for specific types of classes involved in the associations (like what you posted, but without the assocQName). Thanks anyway Smiley Happy