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

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?




1

1 vote

Comments

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.

1 vote

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?

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...

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

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

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

1 vote

Comments

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

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.

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

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
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.

1 vote

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
× 516

Question asked: May 28 '13, 4:13 p.m.

Question was seen: 7,067 times

Last updated: May 30 '13, 3:44 p.m.

Confirmation Cancel Confirm