cancel
Showing results for 
Search instead for 
Did you mean: 

behaviour not triggered on property changed

tcuser
Champ on-the-rise
Champ on-the-rise
Hi all,

I'm trying to bind an Alfresco behaviour to a certain custom aspect preoperty change, but it isn't never triggered.

My aspect is defined as follows:

 
      <aspect name="sc:customAspect">
         <title>Custom Aspect</title>
         <properties>
            <property name="sc:customProperty">
               <type>d:text</type>
            </property>
         </properties>
      </aspect>


I want my behaviour to be triggered when customProperty is changed, so my init method is:

 
    public void init() {

        this.policyComponent.bindPropertyBehaviour(NodeServicePolicies.OnUpdatePropertiesPolicy.QNAME,
                QName.createQName(TcModel.NAMESPACE_TC_CONTENT_MODEL, TcModel.ASPECT_CUSTOM_ASPECT),
                QName.createQName(TcModel.NAMESPACE_TC_CONTENT_MODEL, TcModel.PROP_CUSTOM_PROPERTY),
                new JavaBehaviour(this, "onUpdateProperties", NotificationFrequency.TRANSACTION_COMMIT));

    }


And the onUpdateProperties method is never reached. If I change my init mthod to:

 
    public void init() {

        this.policyComponent.bindClassBehaviour(NodeServicePolicies.OnUpdatePropertiesPolicy.QNAME,
                QName.createQName(TcModel.NAMESPACE_TC_CONTENT_MODEL, TcModel.ASPECT_CUSTOM_ASPECT),
                new JavaBehaviour(this, "onUpdateProperties", NotificationFrequency.TRANSACTION_COMMIT));

    }


It works, but the problem is that it enters in onUpdateProperties everyTime I change any property of the node.

How can I bind the behaviour in this case? Thank you!!
6 REPLIES 6

jpotts
World-Class Innovator
World-Class Innovator
Does your class implement NodeServicePolicies.OnUpdatePropertiesPolicy?

Jeff

tcuser
Champ on-the-rise
Champ on-the-rise
Yes, this is the full class code:


public class WFBehaviour implements NodeServicePolicies.OnUpdatePropertiesPolicy {

    private NodeService nodeService;
    private PolicyComponent policyComponent;

    public NodeService getNodeService() {
        return nodeService;
    }

    public void setNodeService(NodeService nodeService) {
        this.nodeService = nodeService;
    }

    public PolicyComponent getPolicyComponent() {
        return policyComponent;
    }

    public void setPolicyComponent(PolicyComponent policyComponent) {
        this.policyComponent = policyComponent;
    }

    public void init() {

        this.policyComponent.bindPropertyBehaviour(NodeServicePolicies.OnUpdatePropertiesPolicy.QNAME,
                QName.createQName("http://www.mycompany.com/model/content/1.0", "customAspect"),
                QName.createQName("http://www.mycompany.com/model/content/1.0", "customProperty"),
                new JavaBehaviour(this, "onUpdateProperties", NotificationFrequency.EVERY_EVENT));

    }

    @Override
    public void onUpdateProperties(NodeRef arg0, Map<QName, Serializable> arg1, Map<QName, Serializable> arg2) {

        System.out.println("onUpdateProperties IN");

    }

}

tcuser
Champ on-the-rise
Champ on-the-rise
And this is the spring context:


   <bean id="wfPolicy" class="com.mycompany.alfresco.behavior.WFBehaviour" init-method="init">
      <property name="policyComponent" ref="policyComponent" />
      <property name="nodeService" ref="NodeService" />
   </bean>   

niketapatel
Star Contributor
Star Contributor
Hi, I believe bindPropertyBehaviour is not getting triggered not sure if bug. You may try bindClassBehaviour.

         

this.policyComponent.bindClassBehaviour(NodeServicePolicies.OnUpdatePropertiesPolicy.QNAME,
                QName.createQName("http://www.mycompany.com/model/content/1.0", "customAspect"),
                new JavaBehaviour(this, "onUpdateProperties", NotificationFrequency.EVERY_EVENT));
            

Thank you, niketapatel. That's how I finally made it, but in that case I have to use an if inside the onUpdateProperties method to control that the property that has change is mu customProperty…

niketapatel
Star Contributor
Star Contributor
Yes true. Its bound to your customAspect. So if any property from your customAspect gets changed then only it gets triggered. So yes need to use if to check your specific custom property.