AnsweredAssumed Answered

Problem binding Association change behaviors

Question asked by cseickel on Mar 1, 2019
Latest reply on Mar 4, 2019 by afaust

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.

Outcomes