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