It's all about the answers!

Ask a question

RTC 4.0.3+ how to convert a URI to an ILink


1
1
Jossie McManus (11113) | asked May 28 '13, 4:13 p.m.
edited May 28 '13, 4:22 p.m.
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?





Comments
1
sam detweiler commented May 29 '13, 8:16 a.m.

you said 'remote server'.. so my assumption is you have two rtc servers and are trying to build a link between workitems on different servers.

support for links only works in the SAME server.  (unless it is one of the special change requests as part of the project sharing configuration)..

you can create a 'related artifact' which is really just a standard html link.


Jossie McManus commented May 30 '13, 12:26 a.m.

If by "project sharing configuration" you mean that I have setup both servers to be "friends", then yes, they are setup that way in the configuration using the instructions from 2b on in this article: https://jazz.net/library/article/535

What is a related artifact?  Can you point me to where I can get more info for this?



Jossie McManus commented May 30 '13, 1:54 p.m.

All I have is the URI object for the change request and I just need a way to convert that URI object into a properly created ILink or IReference object.  I don't actually need a link between the points, because I'm just trying to pass that ILink object to the client so they can query and do additional work with that change request.  Not sure that the related artifact can be useful for my scenario...


sam detweiler commented May 30 '13, 2:33 p.m.

If you are on system A, with a Change Request to system B, there is not much you can do.  you cannot query THRU the change request link, and you cannot get a direct link to the far side (system B) workitem. as link objects are server specific


Jossie McManus commented May 30 '13, 3:04 p.m.

That confirms my findings. 

What about getting an IReference from a URI object?  I created an IReference but it seems like an incomplete object, getLink() returns null.  Maybe I'm creating it wrong?


            IReferenceFactory factory= IReferenceFactory.INSTANCE;
            for (URI uri : uriList) {
                IURIReference iRef = factory.createReferenceFromURI(uri);
                if (iRef != null) {
                    realLinks.add(iRef.getLink());                   
                }
            }


sam detweiler commented May 30 '13, 3:44 p.m.

ILinks need two IReferences

you need to use the ILinkManager service to manage (create/modify/delete) ILinks.

showing 5 of 7 show 2 more comments

2 answers



permanent link
Kyle Christianson (1261615) | answered May 29 '13, 8:00 a.m.
edited May 29 '13, 8:01 a.m.
 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
Evan Hughes commented May 29 '13, 9:28 a.m.
JAZZ DEVELOPER

Your example is for client code. How would a repository fetch the workitem object from another repository?


Ralph Schoon commented May 29 '13, 9:39 a.m. | edited May 29 '13, 11:19 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

As below, you can look into 

https://rsjazz.wordpress.com/2012/09/20/the-rtc-workitem-server-link-api-linking-to-work-items-and-other-elements/ how server API works. Server and client API is very similar, you only use different services and get them in a different way. The code above and the example in the link should provide you with enough example code to get it working.


Kyle Christianson commented May 29 '13, 11:07 a.m.

I'm not real familiar with how two repositories communicate, but wouldn't one repository essentially act as the client of the other? 


Ralph Schoon commented May 29 '13, 11:51 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

As far as I can tell, you have to be registered against the same JTS with two servers,or they have to have a friends relationship to be able to set up a CLM link.


permanent link
Ralph Schoon (54.0k13641) | answered May 29 '13, 8:14 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
In Addition to Kyle's example you can find example code here: https://rsjazz.wordpress.com/2012/09/20/the-rtc-workitem-server-link-api-linking-to-work-items-and-other-elements/ there are also other examples e.g. for the Plain Java Client Libraries.

Your answer


Register or to post your answer.