cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert non-versionable node into first version?

joko71
Confirmed Champ
Confirmed Champ
How can I convert non-versionable node into first version in the most effective way?

So far I came up with this:


   public static void addAspect(NodeRef nodeRef, String comment) {
      
      CheckOutCheckInService checkOutCheckInService = AlfrescoServices.getServiceRegistry().getCheckOutCheckInService();
      
      AlfrescoServices.getNodeService().addAspect(nodeRef, ContentModel.ASPECT_VERSIONABLE, null);
      
      NodeRef nodeRefWorkingCopy = checkOutCheckInService.checkout(nodeRef);
      checkOutCheckInService.checkin(nodeRefWorkingCopy, Utils.getMinorVersionProperties(comment));
   }

   public static Map<String, Serializable> getMinorVersionProperties(final String comment) {
      
      Map<String, Serializable> versionProperties = new HashMap<String, Serializable>();
      versionProperties.put(Version.PROP_DESCRIPTION, comment);
      versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MINOR);

      return versionProperties;
   }

This way I get created 1.0 version, but the current user is noted as 1.0 version creator, not the original creator.

Is there a way to modify the code so that the original creator is noted as 1.0 version creator?
1 REPLY 1

_sax
Champ in-the-making
Champ in-the-making
You could read out the Creator property and set it to the original value after adding the versionable aspect. The drawback would be, that this editing of properties will lead to a subversion (1.1) being created.
Maybe, you could read out the Creator and then run the script that creates the aspect in this users context. The drawback is, I'm not aware of a way to run a class in a user's context. For Java Scripts in a workflow there's

<action class="org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript">
  <runas>admin</runas>
  <script>
    logger.log("Person " + person.properties["firstName"]);
  </script>
</action>