Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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:

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

0 votes


Accepted answer

Permanent link
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

0 votes

Comments

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


One other answer

Permanent link
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;
    }

0 votes

Comments

Thanks Andy Jewell, your code helped me 

Future Users can use below code along with above comment works for Client API 
IWorkItem workItem =  (IWorkItem) teamRepository.itemManager().fetchCompleteItem(wih, IItemManager.DEFAULT, monitor); 

Your answer

Register or log in to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,938
× 411

Question asked: Sep 10 '15, 4:39 p.m.

Question was seen: 5,446 times

Last updated: Jan 15 '21, 5:26 a.m.

Confirmation Cancel Confirm