I am trying to retrieve the predecessor version (A.1 -> B.1) of a part. Current solution using VersionControlHelper.service.predecessorOf(part) only returns the previous iteration not version. Is there an api or a specific way to retrieve the previous part object?
Solved! Go to Solution.
Hi,
Yes this is a correct API. I use allVersionsFrom().
If you need previous revision you need to go throw all versions. They are usually sort by creation time.
First version is the latest one.
Check one by one VersionSortId if it is changed then it must be previous revision.
My solution to get previous revision. (code works for all objects not just WTPart...)
private static RevisionControlled getprevisousRevisionOfWTPart(RevisionControlled lastWTP)
{
RevisionControlled retValue = null;
String actualRev = lastWTP.getVersionIdentifier().getVersionSortId();
if (lastWTP != null)
{
try
{
QueryResult allVersions = VersionControlHelper.service.allVersionsFrom(lastWTP);
RevisionControlled prevRevision = null;
while (allVersions.hasMoreElements())
{
Object obj = allVersions.nextElement();
if (obj instanceof RevisionControlled)
{
String checkRevision = ((RevisionControlled) obj).getVersionIdentifier().getVersionSortId();
if (checkRevision.equals(actualRev))
{
System.out.println("next version");
} else
{
prevRevision = (RevisionControlled) obj;
break;
}
}
}
if (prevRevision != null)
{
retValue = prevRevision;
}
} catch (WTException e)
{
e.printStackTrace();
}
}
return retValue;
}
Hope this can help.
PetrH
Hi,
I use the following API to get the previous revision's object.
QueryResult qs = wt.vc.VersionControlHelper.service.allVersionsOf(part.getMaster());
The qs includes all version objects as descending order.
So first element of the qs is latest version.
Hi,
Yes this is a correct API. I use allVersionsFrom().
If you need previous revision you need to go throw all versions. They are usually sort by creation time.
First version is the latest one.
Check one by one VersionSortId if it is changed then it must be previous revision.
My solution to get previous revision. (code works for all objects not just WTPart...)
private static RevisionControlled getprevisousRevisionOfWTPart(RevisionControlled lastWTP)
{
RevisionControlled retValue = null;
String actualRev = lastWTP.getVersionIdentifier().getVersionSortId();
if (lastWTP != null)
{
try
{
QueryResult allVersions = VersionControlHelper.service.allVersionsFrom(lastWTP);
RevisionControlled prevRevision = null;
while (allVersions.hasMoreElements())
{
Object obj = allVersions.nextElement();
if (obj instanceof RevisionControlled)
{
String checkRevision = ((RevisionControlled) obj).getVersionIdentifier().getVersionSortId();
if (checkRevision.equals(actualRev))
{
System.out.println("next version");
} else
{
prevRevision = (RevisionControlled) obj;
break;
}
}
}
if (prevRevision != null)
{
retValue = prevRevision;
}
} catch (WTException e)
{
e.printStackTrace();
}
}
return retValue;
}
Hope this can help.
PetrH
How can I get the part based on the version method? predecessorof() gets this in WTPart or any object I want
Hi @WM_9965332
Use it same way as "VersionControlHelper.service.allVersionsFrom(lastWTP);"
Iterated iterObject = VersionControlHelper.service.predecessorof(lastWTP);
This method gives you previous Iteration. So If you put there object with iteration 5(D.5) the method return object with version D.4
if you put there object with version D.1 it returns C.x (x is latest iteration of revision C example C.3)
So you have to think about how to be sure you have really previous revision.
Iterated object can be cast to any object supports iterations
WTPart wtp = (WTPart) iterObject ;
EPMDocument epm = (EPMDocument) iterObject ;
Hope this can help
PetrH
Awesome. Thanks. I am also trying to find the previous released(state) version. Is that possible?
Hi @WM_9965332
Sure,
You just need to getState from object and control if the state is the released one of previous revision.
If previous revision is not released you continue to search again previous revision and again check the State if is released.
PetrH
Can I see it modified in your code? Trying to implement but not working
Hi @WM_9965332
Something like this?
private static RevisionControlled getprevisousRevisionOfWTPart(RevisionControlled lastWTP)
{
RevisionControlled retValue = null;
String actualRev = lastWTP.getVersionIdentifier().getVersionSortId();
if (lastWTP != null)
{
try
{
QueryResult allVersions = VersionControlHelper.service.allVersionsFrom(lastWTP);
RevisionControlled prevRevision = null;
while (allVersions.hasMoreElements())
{
Object obj = allVersions.nextElement();
if (obj instanceof RevisionControlled)
{
String checkRevision = ((RevisionControlled) obj).getVersionIdentifier().getVersionSortId();
if (checkRevision.equals(actualRev))
{
System.out.println("next version");
} else
{
RevisionControlled subprevRevision = (RevisionControlled) obj;
State state = subprevRevision.getLifeCycleState();
if (state.equals(State.toState("RELEASED"))) // here I just check the state. It is up to you how you handle the state you want to get back.
{
prevRevision = subprevRevision;
break;
} else
{
actualRev = subprevRevision.getVersionIdentifier().getVersionSortId(); // I know this is prev revision and I need to check this old revision with older one
System.out.println("next version");
}
}
}
}
if (prevRevision != null)
{
retValue = prevRevision;
}
} catch (WTException e)
{
e.printStackTrace();
}
}
return retValue;
}
PetrH
Hi. Is it possible to return the object for any given revision? Say I pass "0.3" as a string into this method, can I return the exact object with this revision regardless of the state?
Hi @WM_9965332
You have to search for it manually.
So you need to go through all iterations and control what iteration and revision are.
PetrH