How to get WorkItem references from an IChange or IChangeset?
Hi. . . There are numerous examples online and on the forum of getting references to IChangesets through the WorkItem/WorkItemCopy. Most clearly, from Ralph's blog:
Also, in this RTC article (reference "Discovering Links Between Items") by Chris McGee.
However, these are examples of finding various links from a workitem. Is there a way to find links from a changeset or from a change? I have an IChangeset and I want to find all the work items that are linked to it.
Also, I don't see any reference in the 5.0.2 java API docs for IReference, ILink, or ILinkManager. Does anyone know the reason for that?
Thanks!
Andy
public List<IChangeSet> findChangesetsOnWorkItem(WorkItemWorkingCopy wc) throws RtcException, TeamRepositoryException{ IWorkItemReferences references = wc.getReferences();
List<IReference> chgsetrefs = new ArrayList<IReference>();
for (IEndPointDescriptor iEndPointDescriptor : references.getTypes()) {
if(iEndPointDescriptor.getDisplayName().equalsIgnoreCase(PMLT.ChangesetLink.toString())){
// blah
}
}
// now resolve items
List<IChangeSet> itemlist = null;
try {
itemlist = resolveChangesetReferences(chgsetrefs);
} catch (TeamRepositoryException e) {
throw new RtcException("Had a problem while resolving changeset references",e);
}
return itemlist;
}
Also, in this RTC article (reference "Discovering Links Between Items") by Chris McGee.
However, these are examples of finding various links from a workitem. Is there a way to find links from a changeset or from a change? I have an IChangeset and I want to find all the work items that are linked to it.
Also, I don't see any reference in the 5.0.2 java API docs for IReference, ILink, or ILinkManager. Does anyone know the reason for that?
Thanks!
Andy
Accepted answer
You are starting with a change set and not a work item. In that case this might be more appropriate:
Restrict Delivery of Changesets Associated to Wrong Work Item Types Advisor
One other answer
This is what I did, based on code referenced in answer:
/** * Get work item links from a changeset * @param chgset
* @return
* @throws TeamRepositoryException
*/
public Set<IWorkItemHandle>getWorkItemLinks(IChangeSetHandle chgset) throws TeamRepositoryException{ Set<IWorkItemHandle> wis = new TreeSet<IWorkItemHandle>();
// Get the ProviderFactory to be able to find the links
ProviderFactory pf = (ProviderFactory) repo.getClientLibrary(ProviderFactory.class);
List<ILink> links = ChangeSetLinks.findLinks(pf,chgset,
new String[] { ILinkConstants.CHANGESET_WORKITEM_LINKTYPE_ID },
monitor);
for (ILink link : links) {
Object resolved = link.getTargetRef().resolve();
if (resolved instanceof IWorkItemHandle) {
IWorkItemHandle wih = (IWorkItemHandle)resolved;
wis.add(wih);
}
}
return wis;
}