It's all about the answers!

Ask a question

How to get WorkItem references from an IChange or IChangeset?


Andy Jewell (24224868) | asked Sep 10 '15, 4:39 p.m.
edited Sep 10 '15, 4:45 p.m.
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:

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


permanent link
Ralph Schoon (55.5k23642) | answered Sep 11 '15, 3:32 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Sep 11 '15, 3:35 a.m.
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

Andy Jewell selected this answer as the correct answer

Comments
Andy Jewell commented Sep 14 '15, 1:08 p.m.

I missed that one!  Good article, thank you for sharing your work!

One other answer



permanent link
Andy Jewell (24224868) | answered Sep 14 '15, 1:10 p.m.
edited Sep 14 '15, 1:12 p.m.
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;
    }

Your answer


Register or to post your answer.