cancel
Showing results for 
Search instead for 
Did you mean: 

More than one CalculateVersionLabelPolicy behaviour has been

raaftjon
Champ on-the-rise
Champ on-the-rise
hello
I would like to register my own CalculateVersionLabelPolicy for get more control about the version labes. The problem is, that the java bean registerContentWithVersionService just register a version policy:

file: core-services-context.xml
    <bean id="registerContentWithVersionService" class="org.alfresco.repo.version.VersionServiceVersionLabelRegistrationBean" init-method="register"> 
       <property name="versionService">
            <ref bean="versionService" />
        </property>
        <property name="namespacePrefixResolver">
            <ref bean="namespaceService" />
        </property>
        <property name="typeQName">
            <value>cm:content</value>
        </property>
        <property name="policy">
             <ref bean="serialVersionLabelPolicy" />
        </property>
    </bean>
Is possible to de-register or overwrite a policy for a model type? I have not found a method in the package org.alfresco.service.cmr.version.

Or is possible to define the policy to the point where I add the versionable asspect:
nodeService.addAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE, …)
I use Alfresco 4.0.d

Thanks,
Jonas
3 REPLIES 3

mitpatoliya
Star Collaborator
Star Collaborator
How about you use contentservice.
Because whenever content is updated it will create new version.
and update is method from contentservice so there you can add the behavior.
I think I understood the problem correctly.

raaftjon
Champ on-the-rise
Champ on-the-rise
I don't use contentservice directly. I would like only define the cm:versionLabel from aspect cm:versionable.

The user should by able to choose the version label, if he will create a new version: For example 1.2.3
I don't found a solution for change version labels, except that I use a own CalculateVersionLabelPolicy.

I try also to define a VersionServicePolicies.CalculateVersionLabelPolicy bean for my custom model type:
   
<bean id="somco.calculateVersionLabel.behavior" class="ch.somco.alfresco.behavior.LoggingVersionLabelsPolicy"
         init-method="init" lazy-init="false" depends-on="somco-modell">
      <property name="policyComponent" ref="policyComponent" />
   </bean>
But the result is the same as noted above:
More than one CalculateVersionLabelPolicy behaviour has been registered for the type {ch.somco.alfresco.somcoModel}somcoDocument

raaftjon
Champ on-the-rise
Champ on-the-rise
I have found a solution for use my own CalculateVersionLabelPolic:

I overwrite the original alfresco bean configuration with a own registerContentWithVersionService and get my own CalculateVersionLabelPolic bean.

file: my-context.xml
<bean id="registerContentWithVersionService" class="org.alfresco.repo.version.VersionServiceVersionLabelRegistrationBean" init-method="register">
   <property name="versionService">
      <ref bean="versionService" />
   </property>
   <property name="namespacePrefixResolver">
      <ref bean="namespaceService" />
   </property>
   <property name="typeQName">
      <value>cm:content</value>
   </property>
   <property name="policy">
      <ref bean="somcoSerialVersionLabelPolicy" />
   </property>
</bean>

<bean id="somcoSerialVersionLabelPolicy"
        class="ch.somco.alfresco.version.somcoVersionServicePolicies" >
</bean>
Below is my dummy example implementation. The dummy algorithm for calculate the next version is not recommended for imitation!
package ch.somco.alfresco.version;
import java.io.Serializable;
import java.util.Map;

import org.alfresco.repo.version.VersionServicePolicies;
import org.alfresco.service.cmr.version.Version;
import org.alfresco.service.namespace.QName;

public class somcoVersionServicePolicies implements
      VersionServicePolicies.CalculateVersionLabelPolicy {
   @Override
   public String calculateVersionLabel(QName classRef,
         Version preceedingVersion, int versionNumber,
         Map<String, Serializable> verisonProperties) {

      return "1.2." + RandomStringUtils.randomNumeric(5);
   }
}