AnsweredAssumed Answered

OnDeleteChildAssociationPolicy problem

Question asked by nowhere on Apr 8, 2009
Latest reply on May 12, 2009 by nowhere
Hi all,
I have created my class as follow:

public class MyClass
   implements NodeServicePolicies.OnCreateChildAssociationPolicy,
            NodeServicePolicies.OnDeleteChildAssociationPolicy {

   // Dependencies
    private NodeService nodeService;
    private PolicyComponent policyComponent;
    private ServiceRegistry serviceRegistry;
    // Behaviours
    private Behaviour onCreateNode;
    private Behaviour onDeleteNode;
   
    private Logger logger = Logger.getLogger(MyClass.class);
   
    public void init() {
       if (logger.isDebugEnabled()) logger.debug("Initializing behaviors");
       
        // Create behaviours
        this.onCreateNode = new JavaBehaviour(this, "onCreateChildAssociation", NotificationFrequency.TRANSACTION_COMMIT);
        this.onDeleteNode = new JavaBehaviour(this, "onDeleteChildAssociation", NotificationFrequency.TRANSACTION_COMMIT);

        // Bind behaviours to node policies
        this.policyComponent.bindAssociationBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onCreateChildAssociation"), QName.createQName(myModel.NAMESPACE_MY_CONTENT_MODEL, myModel.ASPECT_MY_COMPONIBILE), QName.createQName(myModel.NAMESPACE_MT_CONTENT_MODEL, myModel.ASSN_TIPO1), this.onCreateNode);
        this.policyComponent.bindAssociationBehaviour(QName.createQName(NamespaceService.ALFRESCO_URI, "onDeleteChildAssociation"), QName.createQName(visiteIspettiveModel.NAMESPACE_VISIT_CONTENT_MODEL, myModel.ASPECT_MY_COMPONIBILE), QName.createQName(myModel.NAMESPACE_MY_CONTENT_MODEL, myModel.ASSN_TIPO1), this.onDeleteNode);
     }

that overrides following methods:

   
public void onCreateChildAssociation(ChildAssociationRef childAssocRef, boolean arg1) {
      if (logger.isDebugEnabled()) logger.debug("Inside onCreateNode");      
      method(childAssocRef);
      
   }

public void onDeleteChildAssociation(ChildAssociationRef childAssocRef) {
      if (logger.isDebugEnabled()) logger.debug("Inside onDeleteNode");
      method(childAssocRef);
      
   }

Now, my problem is that if I create a node with following code :

NodeRef mynode = nodeService.createNode(nodoContenitore, QName.createQName(myModel.NAMESPACE_MY_CONTENT_MODEL , myModel.ASSN_TIPO1) ,ContentModel.TYPE_CONTENT, QName.createQName(myModel.NAMESPACE_MY_CONTENT_MODEL , myModel.TYPE_MY_TYPE)).getChildRef();

It executes the behaviour and the onCreateChildAssociation method, so it works.

But the behaviour doesn't start if I delete an association with the following code

nodeService.removeChildAssociation(assRef);

where getTypeQName(assRef) is  {http://www.mymodel.com/model/content/1.0}ass1

It's to say that are valid the following:
public static final String NAMESPACE_MY_CONTENT_MODEL  = "http://www.mymodel.com/model/content/1.0";
public static final String ASSN_TIPO1 = "ass1";

and association "ass1" is defined in a custom model of mine:


<aspect name="my:aspectDefined">
      <title>Title here</title>
      <properties>
   
      </properties>
      <associations>
         <child-association name="my:ass1">
            <title></title>
            <source>
               <mandatory>false</mandatory>
               <many>true</many>
            </source>
            <target>
               <class>my:mydocument</class>
               <mandatory>false</mandatory>
               <many>true</many>
            </target>
         </child-association>
         
      </associations>
   </aspect>

Where am I in wrong in defining the onDeleteChildAssociation behaviour? Can you help me? I didn't find much documentation around.
Thanks!  :)

Outcomes