It's all about the answers!

Ask a question

Fetching WorkItems based on some text on URI of Related Artifacts using plain java API


Sridhar Kuna (1601417) | asked Aug 27 '15, 11:03 a.m.
edited Aug 28 '15, 4:59 a.m.
We want to retrieve workItems based on some text (eg: ibm) from 'Related artifacts' (which is really standard html link, eg URI: www.ibm.com/developerworks) attached as Links in the Links tab. Any help would be really appreciated?

2 answers



permanent link
sam detweiler (12.4k6172200) | answered Aug 28 '15, 5:27 a.m.
You can create a workitem query that will return workitems that HAVE Related Artifact links.
then you can examine each workitem..

I provided a sample that will dump out all workitems returned in a query, the accepted answer here.
https://jazz.net/forum/questions/94776/assertionfailedexception-problem-with-getting-the-values-of-attributes

after you get that to work, you can add code to create the query dynamically.
see Ralphs blog
https://rsjazz.wordpress.com/2012/10/29/using-work-item-queris-for-automation/


permanent link
Sridhar Kuna (1601417) | answered Sep 02 '15, 11:16 a.m.
Thanks sam for your quick reply. I have not tried using workitem query. But worked for me as below,

//First get the required workitems and on each workitem do some logic based on "Related artifact" link defined.
-----------------------------------------
com.ibm.team.workitem.common.query.IQueryResult<IResolvedResult<IWorkItem>> results = queryClient.getResolvedExpressionResults(projectArea, term, IWorkItem.FULL_PROFILE);

while (results.hasNext(monitor)) {
  IResolvedResult<IWorkItem> workitemResult = (IResolvedResult<IWorkItem>) results.next(monitor);
  IWorkItem workItem = workitemResult.getItem();
  ILinkManager linkManager = (ILinkManager)      teamRepository.getClientLibrary(ILinkManager.class);
  workItemReference =  linkManager.referenceFactory().createReferenceToItem(workItem);

linkQueryPage = linkManager.findLinksBySource(WorkItemLinkTypes.RELATED_ARTIFACT, workItemReference, monitor);
linkCollection = linkQueryPage.getAllLinksFromHereOn();

for (ILink l : linkCollection) {
    System.out.println("URL: " + l.getTargetRef().createURI()+ ", Comment: " + l.getTargetRef().getComment());
    if (l.getTargetRef().createURI().toString().contains("some string that you would be searching as part of URI"))
    //Once you determined that WorkItem with specific URI string
   //DO your logic
    -------
   }
}

Your answer


Register or to post your answer.