How to get linked SVN revision URI via RTC Java API?
I'm looking for a way to use Java API to extract all the SVN revision URIs attached to an RTC workitem.
I tried to get all the workitem references via
workItemCommon.resolveWorkItemReferences(workitem, null);
but the link to SVN revision is not among the references I get. So what can I do to get these URIs via Java API?
Upd: this is about RTC 4.0.2 SDK, client API.
Accepted answer
the following is a code snippet that will allow you to retrieve SVN link references from a work item. I tested in a precondition in my environment (so the code is server side), where "workItemNew" is the new state of the work item being saved. In your initial code it would be the "workitem" you are passing as parameter:
IWorkItemServer workItemServer = getService(IWorkItemServer.class); IWorkItemReferences references = workItemServer.resolveWorkItemReferences(workItemNew, monitor); List<IReference> SVNreferences = references.getReferences(ILinkTypeRegistry.INSTANCE.getLinkType(RevisionLinks.REVISION_2_WORK_ITEM_LINK_TYPE).getSourceEndPointDescriptor()); for(IReference ref : SVNreferences) { if (ref.isURIReference()) { IURIReference svnRef = (IURIReference) ref; ... } }
Note that the link type is declared in "com.ibm.team.scm.svn.common.RevisionLinks", which is part of "com.ibm.team.scm.svn.common".
Hope this helps.
Regards,
Jorge.
Comments
Note "SVNreferences" is of type "List<IReference>", formatting changed capitalization, trying to fix that.
Thank you, Jorge, worked like a charm. The only thing I had to do was to replace IWorkItemServer with
IWorkItemClient workItemClient = (IWorkItemClient) repository.getClientLibrary(IWorkItemClient.class);as it is about a client application.
One other answer
Comments
I would be puzzled if it was no link. The other SCM references are links as well. Consider to parse all links. There are different link types and different ways how links are used. E.h. WorkItem Link Tpyes and CLM link types are handled differently.
Hi, Ralph.
I'm probably missing something here. I looked through examples in your blog and there you use IWorkItemCommon to get workitem references and further process them. My problem is that when I get this list of all references, reference to the svn revision is not there.
For example, I created a workitem with a single parent reference and a single svn revision reference. When I get the list of IReference objects from a workitem as stated in the question, it contains a single item - the parent reference.
I also looked through reference types and link types available and couldn't find a type similar to SVN_REVISION.
Btw, this is about RTC 4.0.2 SDK, client app.
Too bad, I can't test that currently.
I did something similar when I wrote http://rsjazz.wordpress.com/2012/09/19/the-rtc-workitem-link-api-linking-workitems-to-other-elements/
I used
// get all references from the work item workingcopy IWorkItemReferences references = workingCopy.getReferences();Or the code you used up there. I then iterated all the endpoint types in the references.
I did not have SVN links, mind you, but I would have expected them to show up if I did.
Unfortunately I don't have time to test your scenario right now. Maybe someone else can chime in?
Unfortunately, the IBM Rational Software Support was unable to help us with an answer so we're still looking for a way get these links to SVN revisions. Is there a chance you could look into the case?
I can't. I would have to setup SVN and make it work. I don't have the time to do that right now. I asked a colleague who is looking into SVN links for other reasons.He might have some code. However, from talking to him, SVN links should be accessible by the code I shared on my blog in these posts: http://rsjazz.wordpress.com/tag/links/