cancel
Showing results for 
Search instead for 
Did you mean: 

createVersion() in Alfresco

gnsv_ramana
Champ in-the-making
Champ in-the-making
Hi All,
        I'm facing problems in implementing versioning concept for the uploading content using java to alfresco. I came across some methods like createVersion(), deleteVersion() etc. I'm unable to find their usage. Can anyone help in illustrating the createVersion() to create versionable content using java?

Thanks in advance..

Ramana
1 REPLY 1

patil
Champ on-the-rise
Champ on-the-rise
Hi Ramana,

The below is the code for enabling the versioning of the document
FacesContext context = FacesContext.getCurrentInstance();
         RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(context);
         RetryingTransactionCallback<Object> callback = new RetryingTransactionCallback<Object>()
         {
            public Object execute() throws Throwable
            {
               // add the versionable aspect to the node
               getNodeService().addAspect(getDocument().getNodeRef(), ContentModel.ASPECT_VERSIONABLE, null);
               return null;
            }
         };
         txnHelper.doInTransaction(callback);




This is the code for getting VersionHistory

/**
    * Returns a list of objects representing the versions of the
    * current document
    *
    * @return List of previous versions
    */
   public List getVersionHistory()
   {
      List<MapNode> versions = new ArrayList<MapNode>();

      if (getDocument().hasAspect(ContentModel.ASPECT_VERSIONABLE))
      {
         VersionHistory history = this.getVersionService().getVersionHistory(getDocument().getNodeRef());

         if (history != null)
         {
            for (Version version : history.getAllVersions())
            {
               // create a map node representation of the version
               MapNode clientVersion = new MapNode(version.getFrozenStateNodeRef());
               clientVersion.put("versionLabel", version.getVersionLabel());
               clientVersion.put("notes", version.getDescription());
               clientVersion.put("author", version.getCreator());
               clientVersion.put("versionDate", version.getCreatedDate());

               if(getDocument().hasAspect(ContentModel.ASPECT_MULTILINGUAL_EMPTY_TRANSLATION))
               {
                  clientVersion.put("url", null);
               }
               else
               {
                  clientVersion.put("url", DownloadContentServlet.generateBrowserURL(version.getFrozenStateNodeRef(),
                        clientVersion.getName()));
               }


               // add the client side version to the list
               versions.add(clientVersion);
            }
         }
      }

      return versions;
   }



You can get the VersionHistory from the ServiceRegistry.


Thanks,
Patil
Cignex Technologies
Bangalore