<?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 Re: Unable to register VersionServicePolicies.CalculateVersionLabelPolicy in Alfresco Forum</title>
    <link>https://connect.hyland.com/t5/alfresco-forum/unable-to-register-versionservicepolicies/m-p/136511#M36670</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;A href="https://migration33.stage.lithium.com/t5/user/viewprofilepage/user-id/78185"&gt;@absmith&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://migration33.stage.lithium.com/t5/user/viewprofilepage/user-id/16045"&gt;@afaust&lt;/A&gt;&amp;nbsp;is correct but you can always override default policies in the &lt;FONT face="courier new,courier"&gt;service-context.xml&lt;/FONT&gt;&amp;nbsp;file.&lt;/P&gt;&lt;P&gt;Particularly in this example, create custom&amp;nbsp;&lt;FONT face="courier new,courier"&gt;CustomSerialVersionLabelPolicy&lt;/FONT&gt; bean and inject it to the&amp;nbsp;&lt;FONT face="comic sans ms,sans-serif"&gt;registerContentWithVersionService&lt;/FONT&gt;/&lt;FONT face="courier new,courier"&gt;registerMLContainerWithVersionService&lt;/FONT&gt; bean.&lt;/P&gt;&lt;P&gt;In the CustomSerialVersionLabelPolicy.java class, you can easily write your own logic.&lt;/P&gt;&lt;P&gt;service-context.xml example:&lt;/P&gt;&lt;PRE&gt;    &amp;lt;bean id="customSerialVersionLabelPolicy" class="com.example.version.CustomSerialVersionLabelPolicy" &amp;gt;
    &amp;lt;/bean&amp;gt;

    &amp;lt;bean id="registerContentWithVersionService" class="org.alfresco.repo.version.VersionServiceVersionLabelRegistrationBean" init-method="register"&amp;gt;
       &amp;lt;property name="versionService"&amp;gt;
            &amp;lt;ref bean="versionService" /&amp;gt;
        &amp;lt;/property&amp;gt;
        &amp;lt;property name="namespacePrefixResolver"&amp;gt;
            &amp;lt;ref bean="namespaceService" /&amp;gt;
        &amp;lt;/property&amp;gt;
        &amp;lt;property name="typeQName"&amp;gt;
            &amp;lt;value&amp;gt;cm:content&amp;lt;/value&amp;gt;
        &amp;lt;/property&amp;gt;
        &amp;lt;property name="policy"&amp;gt;
             &amp;lt;ref bean="customSerialVersionLabelPolicy" /&amp;gt;
        &amp;lt;/property&amp;gt;
    &amp;lt;/bean&amp;gt;

    &amp;lt;bean id="registerMLContainerWithVersionService" class="org.alfresco.repo.version.VersionServiceVersionLabelRegistrationBean" init-method="register"&amp;gt;
       &amp;lt;property name="versionService"&amp;gt;
            &amp;lt;ref bean="versionService" /&amp;gt;
        &amp;lt;/property&amp;gt;
        &amp;lt;property name="namespacePrefixResolver"&amp;gt;
            &amp;lt;ref bean="namespaceService" /&amp;gt;
        &amp;lt;/property&amp;gt;
        &amp;lt;property name="typeQName"&amp;gt;
            &amp;lt;value&amp;gt;cm:mlContainer&amp;lt;/value&amp;gt;
        &amp;lt;/property&amp;gt;
        &amp;lt;property name="policy"&amp;gt;
             &amp;lt;ref bean="customSerialVersionLabelPolicy" /&amp;gt;
        &amp;lt;/property&amp;gt;
    &amp;lt;/bean&amp;gt;&lt;/PRE&gt;&lt;P&gt;Also be aware that this problem exists only if you want to apply custom logic to all content (cm:content), if you want to do it on custom types, you can use behaviours.&lt;/P&gt;</description>
    <pubDate>Mon, 12 Jul 2021 10:43:01 GMT</pubDate>
    <dc:creator>upforsin</dc:creator>
    <dc:date>2021-07-12T10:43:01Z</dc:date>
    <item>
      <title>Unable to register VersionServicePolicies.CalculateVersionLabelPolicy</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/unable-to-register-versionservicepolicies/m-p/136509#M36668</link>
      <description>&lt;P&gt;I am working with the Java api to implement a class which implements custom behaviors for VersionServicePolicies.CalculateVersionLabelPolicy and VersionServicePolicies.OnCreateVersionPolicy.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can get my onCreateVersionPolicy implementation registered and working without issue, however, I am not having success with the CalculateVersionLabelPolicy policy implementation.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a snippet of the error I recieve when trying to deploy the war containing my class:&lt;/P&gt;&lt;PRE&gt;Caused by: org.alfresco.error.AlfrescoRuntimeException: 00250020 Failed to execute transaction-level behaviour public abstract void org.alfresco.repo.content.ContentServicePolicies$OnContentUpdatePolicy.onContentUpdate(org.alfresco.service.cmr.repository.NodeRef,boolean) in transaction dd3e3520-1a78-4eaa-8a70-87538118cdca Caused by: org.alfresco.service.cmr.version.VersionServiceException: 00250019 More than one CalculateVersionLabelPolicy behaviour has been registered for the type {http://www.somesite.com/somepage/model/1.0}configuration"}}&lt;/PRE&gt;&lt;P&gt;Below is my class which implements these two policies:&lt;/P&gt;&lt;PRE&gt;public class CustomVersionServiceBehavior 
	implements VersionServicePolicies.CalculateVersionLabelPolicy,
	VersionServicePolicies.OnCreateVersionPolicy {
	
	private PolicyComponent policyComponent;
	private Behaviour calculateVersionLabel;
	private Behaviour onCreateVersion;
	
    public void setPolicyComponent(PolicyComponent policyComponent) {
        this.policyComponent = policyComponent;
    }

    public PolicyComponent getPolicyComponent() {
        return this.policyComponent;
    }
	
	public void init() {
		
		this.calculateVersionLabel = new JavaBehaviour(this, "calculateVersionLabel", NotificationFrequency.EVERY_EVENT);
		this.onCreateVersion = new JavaBehaviour(this, "onCreateVersion", NotificationFrequency.EVERY_EVENT);

		this.policyComponent.bindClassBehaviour(
				QName.createQName(NamespaceService.ALFRESCO_URI, "calculateVersionLabel"), 
				ContentModel.TYPE_CONTENT, this.calculateVersionLabel);
				
		this.policyComponent.bindClassBehaviour(VersionServicePolicies.OnCreateVersionPolicy.QNAME, 
				ContentModel.TYPE_CONTENT, this.onCreateVersion);
	}

	@Override
	public String calculateVersionLabel(QName arg0, Version arg1, int arg2, Map&amp;lt;String, Serializable&amp;gt; arg3) {
		System.out.println("Hello from calculateVersionLabel()");
		return null;
	}

	@Override
	public void onCreateVersion(QName arg0, NodeRef arg1, Map&amp;lt;String, Serializable&amp;gt; arg2, PolicyScope arg3) {
		System.out.println("Hello from onCreateVersionPolicy()");
	}

}&lt;/PRE&gt;&lt;P&gt;What am I missing?&lt;/P&gt;</description>
      <pubDate>Mon, 25 Jan 2021 20:45:33 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/unable-to-register-versionservicepolicies/m-p/136509#M36668</guid>
      <dc:creator>absmith</dc:creator>
      <dc:date>2021-01-25T20:45:33Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to register VersionServicePolicies.CalculateVersionLabelPolicy</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/unable-to-register-versionservicepolicies/m-p/136510#M36669</link>
      <description>&lt;P&gt;The problem is that Alfresco already has a calculate version label policy registered by default, and since policies are always additive / cumulative, never replacing each other, you end up with two if you register a custom policy. I think this is one of those parts of Alfresco where they did not really develop or test for extensibility, and since that policy is not really documented anywhere, they might not even consider it a supported extension point (though it is marked with the @AlfrescoPublicAPI annotation).&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jan 2021 16:09:49 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/unable-to-register-versionservicepolicies/m-p/136510#M36669</guid>
      <dc:creator>afaust</dc:creator>
      <dc:date>2021-01-27T16:09:49Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to register VersionServicePolicies.CalculateVersionLabelPolicy</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/unable-to-register-versionservicepolicies/m-p/136511#M36670</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;A href="https://migration33.stage.lithium.com/t5/user/viewprofilepage/user-id/78185"&gt;@absmith&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://migration33.stage.lithium.com/t5/user/viewprofilepage/user-id/16045"&gt;@afaust&lt;/A&gt;&amp;nbsp;is correct but you can always override default policies in the &lt;FONT face="courier new,courier"&gt;service-context.xml&lt;/FONT&gt;&amp;nbsp;file.&lt;/P&gt;&lt;P&gt;Particularly in this example, create custom&amp;nbsp;&lt;FONT face="courier new,courier"&gt;CustomSerialVersionLabelPolicy&lt;/FONT&gt; bean and inject it to the&amp;nbsp;&lt;FONT face="comic sans ms,sans-serif"&gt;registerContentWithVersionService&lt;/FONT&gt;/&lt;FONT face="courier new,courier"&gt;registerMLContainerWithVersionService&lt;/FONT&gt; bean.&lt;/P&gt;&lt;P&gt;In the CustomSerialVersionLabelPolicy.java class, you can easily write your own logic.&lt;/P&gt;&lt;P&gt;service-context.xml example:&lt;/P&gt;&lt;PRE&gt;    &amp;lt;bean id="customSerialVersionLabelPolicy" class="com.example.version.CustomSerialVersionLabelPolicy" &amp;gt;
    &amp;lt;/bean&amp;gt;

    &amp;lt;bean id="registerContentWithVersionService" class="org.alfresco.repo.version.VersionServiceVersionLabelRegistrationBean" init-method="register"&amp;gt;
       &amp;lt;property name="versionService"&amp;gt;
            &amp;lt;ref bean="versionService" /&amp;gt;
        &amp;lt;/property&amp;gt;
        &amp;lt;property name="namespacePrefixResolver"&amp;gt;
            &amp;lt;ref bean="namespaceService" /&amp;gt;
        &amp;lt;/property&amp;gt;
        &amp;lt;property name="typeQName"&amp;gt;
            &amp;lt;value&amp;gt;cm:content&amp;lt;/value&amp;gt;
        &amp;lt;/property&amp;gt;
        &amp;lt;property name="policy"&amp;gt;
             &amp;lt;ref bean="customSerialVersionLabelPolicy" /&amp;gt;
        &amp;lt;/property&amp;gt;
    &amp;lt;/bean&amp;gt;

    &amp;lt;bean id="registerMLContainerWithVersionService" class="org.alfresco.repo.version.VersionServiceVersionLabelRegistrationBean" init-method="register"&amp;gt;
       &amp;lt;property name="versionService"&amp;gt;
            &amp;lt;ref bean="versionService" /&amp;gt;
        &amp;lt;/property&amp;gt;
        &amp;lt;property name="namespacePrefixResolver"&amp;gt;
            &amp;lt;ref bean="namespaceService" /&amp;gt;
        &amp;lt;/property&amp;gt;
        &amp;lt;property name="typeQName"&amp;gt;
            &amp;lt;value&amp;gt;cm:mlContainer&amp;lt;/value&amp;gt;
        &amp;lt;/property&amp;gt;
        &amp;lt;property name="policy"&amp;gt;
             &amp;lt;ref bean="customSerialVersionLabelPolicy" /&amp;gt;
        &amp;lt;/property&amp;gt;
    &amp;lt;/bean&amp;gt;&lt;/PRE&gt;&lt;P&gt;Also be aware that this problem exists only if you want to apply custom logic to all content (cm:content), if you want to do it on custom types, you can use behaviours.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jul 2021 10:43:01 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/unable-to-register-versionservicepolicies/m-p/136511#M36670</guid>
      <dc:creator>upforsin</dc:creator>
      <dc:date>2021-07-12T10:43:01Z</dc:date>
    </item>
  </channel>
</rss>

