cancel
Showing results for 
Search instead for 
Did you mean: 

How to Search different versions of same file.

prateekgoyal
Champ in-the-making
Champ in-the-making
Hello,
I have a querry,
when we searches for a file using its name, then it searches for the latest version of that file. I want to ask is their any way out so that we can search various versions of the same file which is having different metadata and content in it.

Thanks in advance.
1 REPLY 1

openpj
Elite Collaborator
Elite Collaborator
If you would like to search the old versions for a content you need to use the versionStore as your StoreRef in this way:

private Store versionStore = new Store("versionStore", "lightWeightVersionStore");

And then you can get the content for a specific version in this way:

VersionHistory versionHistory =  WebServiceFactory.getAuthoringService().getVersionHistory(ReferenceFactory.newReference(uuid, nodePath));
Version[] versions = versionHistory.getVersions();
  for(Version nodeVersion : versions) {
    if(nodeVersion.getLabel().equals(version)) {
        InputStream result = null;
    Reference reference = new Reference(versionStore, nodeVersion.getId().getUuid(), nodeVersion.getId().getPath());
    Predicate predicate = new Predicate(new Reference[] { reference }, versionStore, null);
    Content[] contents = WebServiceFactory.getContentService().read(predicate, Constants.TYPE_CONTENT);
    result = ContentUtils.getContentAsInputStream(contents[0]);
    return result;
  }
}
Hope this helps.