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

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.

0 votes


Accepted answer

Permanent link
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 =
          (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);

Tiago Fernandez selected this answer as the correct answer

1 vote

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.

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();
      ...
}

 

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've not tried modifying workitems, but I think it requires creating a working copy of the workitem, modifying the working copy, then saving it.

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.

showing 5 of 9 show 4 more comments

One other answer

Permanent link

Hello Tiago,

Can you share the code please? I have the same problem.
Thanks!

0 votes

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,927
× 478
× 411
× 169

Question asked: Aug 13 '13, 2:59 p.m.

Question was seen: 11,034 times

Last updated: Mar 28 '17, 5:54 a.m.

Confirmation Cancel Confirm