I am trying to create behaviors to react to association changes, but it is not working and I cannot figure out why. I'm sure it must be something simple like a typo. Can anyone help me out?
I know the init method is being called because I put a break in the debugger and it hit and executed just fine. The problem is that the onCreateAssociation and onDeleteAssociation methods are never called.
Here is the relevant portions of the content model and java code:
<namespaces>
<namespace uri="http://www.rwjf.org/model/content/investments/1.0" prefix="invest"/>
<namespace uri="http://www.rwjf.org/model/content/common/1.0" prefix="rwjf"/>
</namespaces>
...<aspect name="invest:investmentsDocument">
<title>Investments Document</title>
<associations>
<association name="invest:entity">
<title>Entity</title>
<source>
<mandatory>false</mandatory>
<many>true</many>
</source>
<target>
<class>invest:entityAspect</class>
<mandatory>false</mandatory>
<many>true</many>
</target>
</association>
</associations>
</aspect>
public class AssociationChanges implements NodeServicePolicies.OnDeleteAssociationPolicy,
NodeServicePolicies.OnCreateAssociationPolicy{ // Dependencies
private NodeLocatorService nodeLocatorService;
private ServiceRegistry serviceRegistry;
private PolicyComponent policyComponent;
// Behaviours
private Behaviour onCreateAssociation;
private Behaviour onDeleteAssociation;
private Logger logger = Logger.getLogger(AssociationChanges.class);
public void init() {
if (logger.isDebugEnabled()) logger.debug("Initializing association change behaviors");
// Create behaviours
this.onCreateAssociation = new JavaBehaviour(this, "onCreateAssociation", NotificationFrequency.EVERY_EVENT);
this.onDeleteAssociation = new JavaBehaviour(this, "onDeleteAssociation", NotificationFrequency.EVERY_EVENT);
this.policyComponent.bindAssociationBehaviour(
QName.createQName(NamespaceService.ALFRESCO_URI,"onCreateAssociation"),
QName.createQName("http://www.rwjf.org/model/content/investments/1.0", "investmentsDocument"),
QName.createQName("http://www.rwjf.org/model/content/investments/1.0", "entity"),
this.onCreateAssociation);
this.policyComponent.bindAssociationBehaviour(
QName.createQName(NamespaceService.ALFRESCO_URI,"onDeleteAssociation"),
QName.createQName("http://www.rwjf.org/model/content/investments/1.0", "investmentsDocument"),
QName.createQName("http://www.rwjf.org/model/content/investments/1.0", "entity"),
this.onDeleteAssociation);
}
public void onCreateAssociation(AssociationRef assocRef) {
if (logger.isDebugEnabled()) logger.debug("Inside onCreateAssociation");
handleAssociationChange(assocRef);
}
public void onDeleteAssociation(AssociationRef assocRef) {
if (logger.isDebugEnabled()) logger.debug("Inside onDeleteAssociation");
handleAssociationChange(assocRef);
}
I had also tried the three argument constructor of bindAssociationBehaviour and had the same results.
One thing I always recommend: Make use of constants instead of creating QName instances by hand.
E.g. the interfaces for OnCreateAssociationPolicy and its deleted counterpart all define a QNAME constant with the name to use during registration. With regards to your own model, it is always recommended to create a custom interface / class to define your own QName constants. I have seen a lot of issues caused just by the smallest typo or misuse of a namespace URI in such manual QName instantiation code, which always was very hard to spot.
In this case I myself can't spot any typos.
One thing to keep in mind: The OnCreateAssociationPolicy is only triggered IF the source node already has the relevant aspect applied at the time the association is added. If the node does not have the aspect applied yet, the policy will be triggered only for the type and other aspects at the time, before the "missing" aspect is added. That means there is a "notification gap" in the Alfresco behaviour code, which can cause you to miss on events - and maybe your tests fall into that notification gap.
Thanks for that info about the notification gap. It does not apply to this situation but I know that would have caused me problems in the future had I not known about it.
I had switched to using NodeServicePolicies.OnCreateAssociationPolicy.QNAME and NodeServicePolicies.OnDeleteAssociationPolicy.QNAME just in case it made a difference, but still no results.
Perhaps there are errors somewhere that I don't know about, but I can't find the logs. This is a little off topic, but do you know where the alfresco.log and catalina.out files are when using SDK 4.0?
As I rarely use the SDK (only one customer and one community project with SDK 2.x), and even then never to run an embedded / RAD process, I actually don't know that off the top of my hat.
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.