It's all about the answers!

Ask a question

How to get linked SVN revision URI via RTC Java API?

Serghei Zagorinyak (482913) | asked Jul 17 '13, 7:24 a.m.
edited Jul 18 '13, 5:04 a.m.

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

permanent link
Jorge Diaz (8664434) | answered Jul 26 '13, 7:52 a.m.
Hello Serghei,

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 "", which is part of "".

Hope this helps.


Serghei Zagorinyak selected this answer as the correct answer

Jorge Diaz commented Jul 26 '13, 7:55 a.m.

Note "SVNreferences" is of type "List<IReference>", formatting changed capitalization, trying to fix that.

Serghei Zagorinyak commented Jul 29 '13, 4:30 a.m. | edited Jul 29 '13, 4:33 a.m.

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

permanent link
Ralph Schoon (63.0k33645) | answered Jul 18 '13, 3:58 a.m.
As you have already understood, that is most likely a link. See and other posts on that blog for how to work with links.

Ralph Schoon commented Jul 18 '13, 4:00 a.m.

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.

Serghei Zagorinyak commented Jul 18 '13, 5:02 a.m.

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.

Ralph Schoon commented Jul 18 '13, 5:43 a.m.

Too bad, I can't test that currently.

I did something similar when I wrote

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?

Serghei Zagorinyak commented Jul 26 '13, 4:14 a.m.

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?

Ralph Schoon commented Jul 26 '13, 4:42 a.m.

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:

Your answer

Register or to post your answer.