10-21-2016 11:53 AM
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
10-21-2016 01:41 PM
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.
10-21-2016 01:41 PM
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.
10-23-2016 01:25 PM
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?
10-21-2016 03:22 PM
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);
|
Your class declaration should be something like this
public class ApprovedFilePolicy implements
NodeServicePolicies.OnUpdateNodePolicy,
NodeServicePolicies.OnUpdatePropertiesPolicy{
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.