cancel
Showing results for 
Search instead for 
Did you mean: 

Updating Metadata from Content on content update

buje85
Champ in-the-making
Champ in-the-making

Hi. 

I have some content within an excel file that i also want as Metadata. When a value in the content changes I want the Metadata to update too.   I have attempted to do this in a java behavior and it works using the onUpdateProperties policy.  The problem with this is that it runs when any property is updated.

 To solve this I tried using the onContentUpdated policy  but when I try to get a content reader on the node so I can read the value in the content stream  null is returned, a content reader isn't returned. 

Is there a different policy I should use or is there a better solution to update Metadata based on content data. Thanks

1 ACCEPTED ANSWER

afaust
Legendary Innovator
Legendary Innovator

The onContentPropertyUpdate or onContentUpdate policies are both valid candidates for this use case. One potential issue you may be facing may be related to the notification frequency of the policy / behaviour. I.e. if you react to TRANSACTION_COMMIT there is a delay between the trigger of the policy and its execution (within the transaction) - some code can potentially mess with your content / node before you get a chance to retrieve the reader. You might want to try EVERY_EVENT instead to avoid this kind of problem.

Of course this is only one potential reason for the behaviour - it is just one I have seen more often than others.

There is also another alternative: metadata extractors. These are components that are explicitly called when anything from the file content should be extracted as properties, which happens automatically e.g. when you upload or update content via Share. It can also be triggered by simple rules as there is a default action for this particular functionality. You can register metadata extractors per mimetype and they already get the ContentReader provided as a parameter of the operation defined by the interface.

View answer in original post

2 REPLIES 2

afaust
Legendary Innovator
Legendary Innovator

The onContentPropertyUpdate or onContentUpdate policies are both valid candidates for this use case. One potential issue you may be facing may be related to the notification frequency of the policy / behaviour. I.e. if you react to TRANSACTION_COMMIT there is a delay between the trigger of the policy and its execution (within the transaction) - some code can potentially mess with your content / node before you get a chance to retrieve the reader. You might want to try EVERY_EVENT instead to avoid this kind of problem.

Of course this is only one potential reason for the behaviour - it is just one I have seen more often than others.

There is also another alternative: metadata extractors. These are components that are explicitly called when anything from the file content should be extracted as properties, which happens automatically e.g. when you upload or update content via Share. It can also be triggered by simple rules as there is a default action for this particular functionality. You can register metadata extractors per mimetype and they already get the ContentReader provided as a parameter of the operation defined by the interface.

buje85
Champ in-the-making
Champ in-the-making

Thanks Axel, changing the transaction commit frequency fixed the issue. I will have a look into the metadata extractors, they sound useful.