<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Fire a rule only when the version changes in Alfresco Forum</title>
    <link>https://connect.hyland.com/t5/alfresco-forum/fire-a-rule-only-when-the-version-changes/m-p/81123#M25048</link>
    <description>&lt;P&gt;I couldn't find a way to do this &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;There is "Items ar updated" but that triggers even if a property changes.&lt;/P&gt;&lt;P&gt;And there is "Items are created or enter this folder" which does NOT trigger when a new version is uploaded.&lt;/P&gt;&lt;P&gt;Is this correct?&lt;/P&gt;</description>
    <pubDate>Sat, 30 May 2020 13:33:03 GMT</pubDate>
    <dc:creator>akreienbring</dc:creator>
    <dc:date>2020-05-30T13:33:03Z</dc:date>
    <item>
      <title>Fire a rule only when the version changes</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/fire-a-rule-only-when-the-version-changes/m-p/81123#M25048</link>
      <description>&lt;P&gt;I couldn't find a way to do this &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;There is "Items ar updated" but that triggers even if a property changes.&lt;/P&gt;&lt;P&gt;And there is "Items are created or enter this folder" which does NOT trigger when a new version is uploaded.&lt;/P&gt;&lt;P&gt;Is this correct?&lt;/P&gt;</description>
      <pubDate>Sat, 30 May 2020 13:33:03 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/fire-a-rule-only-when-the-version-changes/m-p/81123#M25048</guid>
      <dc:creator>akreienbring</dc:creator>
      <dc:date>2020-05-30T13:33:03Z</dc:date>
    </item>
    <item>
      <title>Re: Fire a rule only when the version changes</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/fire-a-rule-only-when-the-version-changes/m-p/81124#M25049</link>
      <description>&lt;P&gt;You can implement a behavior.&lt;/P&gt;
&lt;P&gt;Custom behavior can listen to &lt;SPAN style="font-family: inherit; -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%;"&gt;onCreateVersion event or choose from below given available events on version policy and execute your custom logic from the implementation methods:&amp;nbsp;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://docs.alfresco.com/5.2/references/dev-extension-points-behaviors.html" target="_blank" rel="nofollow noopener noreferrer"&gt;https://docs.alfresco.com/5.2/references/dev-extension-points-behaviors.html&lt;/A&gt;&lt;/P&gt;
&lt;TABLE class="simpletable" border="1" summary="" cellspacing="0" cellpadding="4"&gt;
&lt;TBODY&gt;
&lt;TR class="strow"&gt;
&lt;TD valign="top" class="stentry"&gt;org.alfresco.repo.version.VersionServicePolicies&lt;/TD&gt;
&lt;TD valign="top" class="stentry"&gt;
&lt;UL class="ul"&gt;
&lt;LI class="li"&gt;beforeCreateVersion&lt;/LI&gt;
&lt;LI class="li"&gt;afterCreateVersion&lt;/LI&gt;
&lt;LI class="li"&gt;&lt;STRONG&gt;onCreateVersion&lt;/STRONG&gt;&lt;/LI&gt;
&lt;LI class="li"&gt;calculateVersionLabel&lt;/LI&gt;
&lt;/UL&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;

&lt;P&gt;It could be something like:&lt;/P&gt;
&lt;PRE&gt;public class ObjectVersionBehaviour implements &lt;STRONG&gt;VersionServicePolicies.OnCreateVersionPolicy&lt;/STRONG&gt; {
	
	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 &lt;STRONG&gt;onCreateVersion&lt;/STRONG&gt;(final QName classRef, final NodeRef versionableNode, 
				final Map&amp;lt;String, Serializable&amp;gt; versionProperties,
				final PolicyScope nodeDetails){
&lt;STRONG&gt;		//Your custom logic on version creation
&lt;/STRONG&gt;	}
}
&lt;/PRE&gt;
&lt;P&gt;Refer this tutorial if want to learn more on implementing behaviors:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://ecmarchitect.com/alfresco-developer-series-tutorials/behaviors/tutorial/tutorial.html" target="_blank" rel="noopener nofollow noreferrer"&gt;https://ecmarchitect.com/alfresco-developer-series-tutorials/behaviors/tutorial/tutorial.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 30 May 2020 14:15:08 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/fire-a-rule-only-when-the-version-changes/m-p/81124#M25049</guid>
      <dc:creator>abhinavmishra14</dc:creator>
      <dc:date>2020-05-30T14:15:08Z</dc:date>
    </item>
    <item>
      <title>Re: Fire a rule only when the version changes</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/fire-a-rule-only-when-the-version-changes/m-p/81125#M25050</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;As I already followed this helpful tutorial I was able to implement a custom behaviour that reacts on a change of the version.&lt;/P&gt;&lt;P&gt;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. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Please have a look at my "follow-up-problem" that I just posted &lt;A href="https://hub.alfresco.com/t5/alfresco-content-services-forum/ondeletenode-and-beforedeletenode-fired-when-a-new-version-is/m-p/299221#M19575" target="_self" rel="nofollow noopener noreferrer"&gt;here&lt;/A&gt;&amp;nbsp;:&lt;/P&gt;</description>
      <pubDate>Sun, 31 May 2020 18:52:17 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/fire-a-rule-only-when-the-version-changes/m-p/81125#M25050</guid>
      <dc:creator>akreienbring</dc:creator>
      <dc:date>2020-05-31T18:52:17Z</dc:date>
    </item>
  </channel>
</rss>

