Java API extending - IVersionableManager unable to fetchCompleteState
Hi,
I want to download a file from a change set that is linked to a work item. I am using RTC 4.0.3. I find the work item by it's id and am able to populate an IChange List with the change set contents, but I am unable to call fetchCompleteState without an exception. ivhandle.hasFullState always returns false although it appears to have an itemId and stateId. Any ideas what I am doing wrong?
IWorkItemClient workItemClient = (IWorkItemClient) repo.getClientLibrary(IWorkItemClient.class);
IWorkItem workItem = workItemClient.findWorkItemById(id, IWorkItem.FULL_PROFILE, monitor);
IWorkItemCommon common = (IWorkItemCommon) ((ITeamRepository) workItem.getOrigin()).getClientLibrary(IWorkItemCommon.class);
IWorkItemReferences references = common.resolveWorkItemReferences(workItem, monitor);
List<IEndPointDescriptor> types = references.getTypes();
IVersionableManager vmgr = (IVersionableManager) repo.getClientLibrary(IVersionableManager.class);
for (IEndPointDescriptor endpointDescriptor : types) {
List<IReference> refList = references.getReferences(endpointDescriptor);
for (IReference iref : refList) {
URI uri = iref.createURI();
Location location = Location.location(uri);
IAuditableClient auditableClient = (IAuditableClient) repo.getClientLibrary(IAuditableClient.class);
IChangeSet cs = (IChangeSet) auditableClient.resolveAuditableByLocation(location, ItemProfile.createFullProfile(location.getItemType()), monitor);
List<IChange> changes = cs.changes();
for (IChange change : changes) {
System.out.println("change tostring = " + change.toString());
IVersionableHandle ivhandle = change.afterState();
if (ivhandle.hasFullState() == true) {
IVersionable iv = vmgr.fetchCompleteState(ivhandle, monitor);
System.out.println("iv name = " + iv.getName());
}
else {
System.out.println("ivhandle does not have a full state");
}
}
}
}
TIA for any assistance anyone can provide.
Peter
One answer
this means that A change record might not have an 'after' state.
|
afterState()
Returns the "after" state of the versionable item, or
null
if the change is the deletion of a versionable item from the configuration.
|
Comments
That is interesting. In my case the change is an addition of a new set of files to the repository. When I print change.toString() I see the following:
change tostring = com.ibm.team.scm.common.internal.impl.ChangeImpl@7ee87ee8 (internalId: [UUID _sN5jtOpzEeO_MsKtwSaYJA]) (kind: 1, before: null, after: [UUID _sM7TU-pzEeO_MsKtwSaYJA])
My IVersionableHandle object has populated itemId ad stateId attributes, but some others like origin are null.
My requirement is to download a copy of one of the change set files to the local file system. As far as you know, do all properties of the IVersionableHandle object need to be non-null?
its unlikely that any object MUST be completely non-null.
that is also the 1st time you have attempted to use the vmgr object..
I do so like debugging interactively thru these kinds of issues
Comments
sam detweiler
Jun 17 '14, 4:39 p.m.what is the reported exception ?
Peter Moraza
Jun 17 '14, 4:46 p.m.I get a java.lang.NullPointerException
sam detweiler
Jun 17 '14, 4:51 p.m.here?
> if (ivhandle.hasFullState() == true) {
or which line of above
Peter Moraza
Jun 17 '14, 4:52 p.m.Forget to mention there is no additional detail at all in the exception to help in troubleshooting. I see that IChangeSet.changes should not return null, so am wondering if I'm somehow missing a prerequisite step before the call to changes().
Peter Moraza
Jun 17 '14, 4:54 p.m.The exception is thrown at the following line:
Peter Moraza
Jun 17 '14, 4:56 p.m.The exception is thrown at the following line: