05-30-2020 09:33 AM
I couldn't find a way to do this 😞
There is "Items ar updated" but that triggers even if a property changes.
And there is "Items are created or enter this folder" which does NOT trigger when a new version is uploaded.
Is this correct?
05-30-2020 10:15 AM
You can implement a behavior.
Custom behavior can listen to onCreateVersion event or choose from below given available events on version policy and execute your custom logic from the implementation methods:
https://docs.alfresco.com/5.2/references/dev-extension-points-behaviors.html
org.alfresco.repo.version.VersionServicePolicies |
|
It could be something like:
public class ObjectVersionBehaviour implements VersionServicePolicies.OnCreateVersionPolicy { private final NodeService nodeService; private final PolicyComponent policyComponent; public ObjectVersionBehaviour(final ServiceRegistry serviceRegistry, final PolicyComponent policyComponent) { //TODO:: get the required service from serviceRegistry and this.nodeService = serviceRegistry.getNodeService(); this.policyComponent = policyComponent; //Binding on cm:content type createBindings(VersionServicePolicies.BeforeCreateVersionPolicy.QNAME, ContentModel.TYPE_CONTENT, Behaviour.NotificationFrequency.EVERY_EVENT); } private void createBindings(final QName policy, final QName type, final Behaviour.NotificationFrequency frequency) { policyComponent.bindClassBehaviour(policy, type, new JavaBehaviour(this, policy.getLocalName(), frequency)); } @Override public void onCreateVersion(final QName classRef, final NodeRef versionableNode, final Map<String, Serializable> versionProperties, final PolicyScope nodeDetails){ //Your custom logic on version creation } }
Refer this tutorial if want to learn more on implementing behaviors:
https://ecmarchitect.com/alfresco-developer-series-tutorials/behaviors/tutorial/tutorial.html
05-30-2020 10:15 AM
You can implement a behavior.
Custom behavior can listen to onCreateVersion event or choose from below given available events on version policy and execute your custom logic from the implementation methods:
https://docs.alfresco.com/5.2/references/dev-extension-points-behaviors.html
org.alfresco.repo.version.VersionServicePolicies |
|
It could be something like:
public class ObjectVersionBehaviour implements VersionServicePolicies.OnCreateVersionPolicy { private final NodeService nodeService; private final PolicyComponent policyComponent; public ObjectVersionBehaviour(final ServiceRegistry serviceRegistry, final PolicyComponent policyComponent) { //TODO:: get the required service from serviceRegistry and this.nodeService = serviceRegistry.getNodeService(); this.policyComponent = policyComponent; //Binding on cm:content type createBindings(VersionServicePolicies.BeforeCreateVersionPolicy.QNAME, ContentModel.TYPE_CONTENT, Behaviour.NotificationFrequency.EVERY_EVENT); } private void createBindings(final QName policy, final QName type, final Behaviour.NotificationFrequency frequency) { policyComponent.bindClassBehaviour(policy, type, new JavaBehaviour(this, policy.getLocalName(), frequency)); } @Override public void onCreateVersion(final QName classRef, final NodeRef versionableNode, final Map<String, Serializable> versionProperties, final PolicyScope nodeDetails){ //Your custom logic on version creation } }
Refer this tutorial if want to learn more on implementing behaviors:
https://ecmarchitect.com/alfresco-developer-series-tutorials/behaviors/tutorial/tutorial.html
05-31-2020 02:52 PM
Thank you!
As I already followed this helpful tutorial I was able to implement a custom behaviour that reacts on a change of the version.
Although I wonder why these events can not be populated to the rule definition site. That would make things easier for people not using an IDE. 🙂
Please have a look at my "follow-up-problem" that I just posted here :
Explore our Alfresco products with the links below. Use labels to filter content by product module.