cancel
Showing results for 
Search instead for 
Did you mean: 

PolicyComponent - How to use bindPropertyBehaviour?

filip
Champ on-the-rise
Champ on-the-rise

Hello everyone,

I am just wondering if bindPropertyBehaviour method is working or not. There are already several questions but no satisfying answer:

behaviour not triggered on property changed or bindPropertyBehaviour not functioning correctly

My example is:

public class ApprovedFilePolicy implements NodeServicePolicies.OnUpdatePropertiesPolicy {

    private Logger logger = Logger.getLogger(ApprovedFilePolicy.class);

    private PolicyComponent policyComponent;

    private NodeService nodeService;

   

    public void init() {

        logger.debug("ApprovedFilePolicy is registered");

        final Behaviour onUpdateProperties = new JavaBehaviour(this, NodeServicePolicies.OnUpdatePropertiesPolicy.QNAME.getLocalName(), NotificationFrequency.TRANSACTION_COMMIT);

        policyComponent.bindPropertyBehaviour(NodeServicePolicies.OnUpdatePropertiesPolicy.QNAME, ContentModel.ASPECT_TITLED,ContentModel.PROP_TITLE, onUpdateProperties);

    }

   

    @Override

    public void onUpdateProperties(NodeRef nodeRef, Map<QName, Serializable> before, Map<QName, Serializable> after) {

        logger.debug("ApprovedFilePolicy ||| for node " + nodeRef.toString());

    }

    // Setters for NodeService and PolicyComponent

}

Bean is properly registered in service-context.xml since I can see debug message (mentioned in init) during Alfresco startup. However, onUpdateProperties is not executed during title change.

Am I doing anything wrong?

As a workaround, I can still use bindClassBehaviour which works just fine. Btw, I am using 5.1.

Thanks for your comments,

Filip

1 ACCEPTED ANSWER

afaust
Legendary Innovator
Legendary Innovator

The operation bindPropertyBehaviour is working just fine. The reason that the onUpdateProperties behaviour is not called is that it is not a "property policy" - it is a "class policy". If you think about it, the behaviour is about notifying about ALL property changes on a node of a specific class, not a specific property. This can also be seen with the bindAssociationBehaviour which can only be used for events that are association related, like onCreateAssociation or onCreateChildAssociation.

bindClassBehaviour in this case is not a workaround - it is actually the correct way of registering for onUpdateProperties.

View answer in original post

3 REPLIES 3

afaust
Legendary Innovator
Legendary Innovator

The operation bindPropertyBehaviour is working just fine. The reason that the onUpdateProperties behaviour is not called is that it is not a "property policy" - it is a "class policy". If you think about it, the behaviour is about notifying about ALL property changes on a node of a specific class, not a specific property. This can also be seen with the bindAssociationBehaviour which can only be used for events that are association related, like onCreateAssociation or onCreateChildAssociation.

bindClassBehaviour in this case is not a workaround - it is actually the correct way of registering for onUpdateProperties.

filip
Champ on-the-rise
Champ on-the-rise

Thank you Axel for the explanation. I understand that it is not a property policy. Anyway, could you give me any use case where bindPropertyBehaviour is used?

mitpatoliya
Star Collaborator
Star Collaborator

You probably require to study how exactly behavior and policy work in alfresco. Best way is just understand concept and checkout one of the sample provided by alfresco. Also checkout how alfresco use it internally in their classes.

You can call your code during each node update for content of specific type.

this.policyComponent.bindClassBehaviour(OnUpdateNodePolicy.QNAME,ContentModel.TYPE_CONTENT, this.onUpdateNode);

this.policyComponent.bindClassBehaviour(OnUpdatePropertiesPolicy.QNAME,ContentModel.TYPE_CONTENT, this.onUpdateProperties);

Your class declaration should be something like this

public class ApprovedFilePolicy implements

  NodeServicePolicies.OnUpdateNodePolicy,

  NodeServicePolicies.OnUpdatePropertiesPolicy{