cancel
Showing results for 
Search instead for 
Did you mean: 

ContentServicePolicies.OnContentPropertyUpdatePolicy not raise event

colandr
Champ in-the-making
Champ in-the-making
Hello,

I have created a new aspect which should execute function when metadata is modified. In the init method I have

   
    
     this.policyComponent.bindClassBehaviour(
                ContentServicePolicies.OnContentPropertyUpdatePolicy.QNAME,
                ASPECT_CONTENT_HITS,
                new JavaBehaviour(this, "onContentPropertyUpdate", NotificationFrequency.TRANSACTION_COMMIT));
   


but the onContentPropertyUpdate function is never called when an attribute is modified (from web interface) whereas,
when the file is edited and saved (still on the web interface) , onContentPropertyUpdate is called with the "content" property name.

I precise that I'm a beginner in Alfresco but I have not found any topic related to my problem. My alfresco version is 4.0.e
4 REPLIES 4

mitpatoliya
Star Collaborator
Star Collaborator
Refer the <b>CustomAspect</b> Example of Alfresco SDK.
You will get idea on how to create custom behaviors and associate them with policies.

colandr
Champ in-the-making
Champ in-the-making
I have already seen the CustomAspect of Alfresco SDK, it's ok to detect file modification and file creation, but still impossible to detect metadata modification. Moreover, it seems that my CustomAspect example of Alfresco SDK uses deprecated enumeration (
ContentServicePolicies.ON_CONTENT_READ
and
ContentServicePolicies.ON_CONTENT_UPDATE
) but it's no problem to replace them by
ContentServicePolicies.OnContentReadPolicy.QNAME
and
ContentServicePolicies.OnContentUpdatePolicy.QNAME
).

These 3 behaviours work properly
<java>
        // Register the policy behaviours
        this.policyComponent.bindClassBehaviour(
                                 QName.createQName(NamespaceService.ALFRESCO_URI, "onAddAspect"),
                                 ASPECT_CONTENT_HITS,
                                 new JavaBehaviour(this, "onAddAspect", NotificationFrequency.FIRST_EVENT));
        this.policyComponent.bindClassBehaviour(
                                 ContentServicePolicies.OnContentReadPolicy.QNAME,
                                 ASPECT_CONTENT_HITS,
                                 new JavaBehaviour(this, "onContentRead", NotificationFrequency.TRANSACTION_COMMIT));
        this.policyComponent.bindClassBehaviour(
                                 ContentServicePolicies.OnContentUpdatePolicy.QNAME,
                                 ASPECT_CONTENT_HITS,
                                 new JavaBehaviour(this, "onContentUpdate", NotificationFrequency.TRANSACTION_COMMIT));
</java>

but as I said in my first post, the fourth does not detect anything except if a file is modified:
<java>
        this.policyComponent.bindClassBehaviour(
             ContentServicePolicies.OnContentPropertyUpdatePolicy.QNAME,
             ASPECT_CONTENT_HITS,
             new JavaBehaviour(this, "onContentPropertyUpdate", NotificationFrequency.TRANSACTION_COMMIT));

</java>

And that is the function which should be called when metadata is modified
<java>
   public void onContentPropertyUpdate(NodeRef nodeRef,
                                            QName propertyQName,
                             ContentData beforeValue,
                                            ContentData afterValue) {
       System.out.println("Metadata Modified!! ");
       System.out.println("   on node        : " + nodeRef);
       System.out.println("   Propertie name : " + propertyQName.getLocalName());
       System.out.println("   old value      : " + beforeValue);
       System.out.println("   new value      : " + afterValue);
        }
</java>

All of my methods seems to be correct but maybe I have forgot something

afaust
Legendary Innovator
Legendary Innovator
Hello,

onContentPropertyUpdate is the wrong policy to implement in your specfici use case as I understand it. This policy will only be called if the actual file content changes and you will always end up with the
cm:content
property as the only property to reach your policy as long as you don't define specific types that have other content-related properties.
If you want your policy to be called when metadata changes, you need to use the onUpdateProperties policy callback from the NodeServicePolicies interface.

Regards
Axel

colandr
Champ in-the-making
Champ in-the-making
Thank you very much for your help AFaust.
It works fine now !