RTC 4.0.3+ how to convert a URI to an ILink
I need to get an ILink from a String URI that points to a WI in a remote server, so the String URI is really an OSLC URI.
This is what I'm doing...after converting the String to an URI object, I then convert it to an IURIReference to run getLink(), but it returns empty, no ILink is associated with it.
The OSLC URI looks something like this:
https://localhost:9443/jazz/resource/itemName/com.ibm.team.workitem.WorkItem/71
I eventually want to get the full item from the remote server via the ILink. Does anyone know if this is possible? Or if there's a better and more correct way to do this?
This is what I'm doing...after converting the String to an URI object, I then convert it to an IURIReference to run getLink(), but it returns empty, no ILink is associated with it.
The OSLC URI looks something like this:
https://localhost:9443/jazz/resource/itemName/com.ibm.team.workitem.WorkItem/71
I eventually want to get the full item from the remote server via the ILink. Does anyone know if this is possible? Or if there's a better and more correct way to do this?
2 answers
Hi Jossie,
If you are writing client code, you need the ILinkManager.
If you are writing server code, you need the ILinkServiceLibrary.
Both of the interfaces above provide methods to create and save links in the repository. Also, if you are not doing so already, you should use the IReferenceFactory to create the IReference from the URI object.
Finally, I have written a method to convert a URI to a IWorkItem. This only works if you already have a client connection to the remote server via ITeamRepository.
public IWorkItemHandle getWorkItemFromURI(URI workItemURI, ITeamRepository repository) {
try{
Location workItemLocation = Location.location(workItemURI);
IItemHandle itemHandle = repository.itemManager().fetchPartialItem(workItemLocation, IItemManager.DEFAULT, Collections.emptyList(), null);
if(itemHandle != null && itemHandle instanceof IWorkItemHandle){
return (IWorkItemHandle) itemHandle;
}else{
return null;
}
}catch(ItemNotFoundException e){
throw e;
}catch(TeamRepositoryException e){
throw new TeamRepositoryException("Error fetching item by location uri: " + workItemURI.toString(), e);
}
}
Comments
sam detweiler
May 29 '13, 8:16 a.m.1 vote
Jossie McManus
May 30 '13, 12:26 a.m.sam detweiler
May 30 '13, 8:40 a.m.Jossie McManus
May 30 '13, 1:54 p.m.sam detweiler
May 30 '13, 2:33 p.m.Jossie McManus
May 30 '13, 3:04 p.m.sam detweiler
May 30 '13, 3:44 p.m.