List and Create Links of a WorkItem in Java Plain API RTC
Hello, please can provide a very simple example on: 1) List Links of a given WorkItem 2) Create a link of a given WorkItem of "Related Artifacs" type. In my code I only have the workItem: workItem = workItemClient.findWorkItemById(workItemNumber, IWorkItem.FULL_PROFILE, new SysoutProgressMonitor()) How should I continue ? Thanks for the help. |
Accepted answer
It will look something like the following:
import com.ibm.team.links.client.ILinkManager; import com.ibm.team.links.common.IReference; import com.ibm.team.links.common.factory.IReferenceFactory; import com.ibm.team.workitem.common.model.WorkItemLinkTypes ...final ILinkManager linkManager = Tiago Fernandez selected this answer as the correct answer
Comments
Tiago Fernandez
commented Aug 13 '13, 8:59 p.m.
Thank you very much for the response, I will do a try and let you know how it goes. This seems to be how to create a link to a workItem, Could you kindly give an example on how to list existing links of a given workItem as well? Thank you very much.
Something like this:
final ILinkQueryPage queryPage =
linkManager.findLinksBySource(linkType, workItemRef, monitor);
final Collection<ILink> links = queryPage.getAllLinksFromHereOn();
for (final ILink l : links)
{
final IItemHandle linkHandle = (IItemHandle) l.getTargetRef().resolve();
...
}
Tiago Fernandez
commented Aug 14 '13, 10:57 a.m.
Thanks again for the response.
I like the simplicity of your responses :) , that is exactly what I need.
Also I take advanyage and I'd like to do another question not related to the title, how to set a value (for example an integer or string value) to an attribute of a workItem? (I already have the workItem and the Attribute in my code). Thanks a lot. Depends on what you want to print. IReference, the result of l.getTargetRef(), has a createURI method which is probably the best way to get the value of the target of the link in this situation (I think my last example might get a ClassCastException since the target came from a URI). The URI should be easy to print.
I've not tried modifying workitems, but I think it requires creating a working copy of the workitem, modifying the working copy, then saving it.
Tiago Fernandez
commented Aug 14 '13, 3:11 p.m.
I am trying to show the url that has link of type related artifacts of the workItem. The code I have is:
def linkManager = (ILinkManager) repo.getClientLibrary(ILinkManager.class)
}
But the print of the last for is showing another information, and I don't know what to put there. How should I use that println to show the URL and the comment of those related artifacts links? Thanks for the help. I was thinking: l.getTargetRef().createURI() For the comment: .getTargetRef().getComment()
Tiago Fernandez
commented Aug 14 '13, 4:39 p.m.
You rock!!!! :) All your responses lead me to the solution. Now my code works. I will mark this topic as Accepted Answer. Thank you very very much.
LUIZ DE ALMEIDA
commented Jan 29 '15, 8:15 a.m.
Tiago,
showing 5 of 9
show 4 more comments
|
One other answer
Hello Tiago,
|
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.