Fetching WorkItems based on some text on URI of Related Artifacts using plain java API
2 answers
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/
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/
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
-------
}
}
//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
-------
}
}