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
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 =
(ILinkManager) repo.getClientLibrary(ILinkManager.class);
final IReference workItemRef =
linkManager.referenceFactory().createReferenceToItem(workItemHandle);
final IReference relatedRef = IReferenceFactory.INSTANCE.createReferenceFromURI(
relatedUri, comment);
final ILink newLink = linkManager.createLink(
WorkItemLinkTypes.RELATED_ARTIFACT, workItemRef, relatedRef); linkManager.saveLink(newLink, monitor);
Comments
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.
Thanks again for the response.
I like the simplicity of your responses :) , that is exactly what I need.
In the code above, how should I do to println the link that has the linkHandle ?
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 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)
def workItemRef = linkManager.referenceFactory().createReferenceToItem(workItem)
def queryPage = linkManager.findLinksBySource(WorkItemLinkTypes.RELATED_ARTIFACT, workItemRef, new SysoutProgressMonitor());
def links = queryPage.getAllLinksFromHereOn();
for(ILink l : links){
println("Link is: " + l.getLinkTypeId() + ", url: " + l.getThisEndpointDescriptor(l.getTargetRef()).getIcon())
}
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()
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.
Tiago,
Could you share your code that lists the related workitens of a given workitem?
If you could, I will thank you so much.