It's all about the answers!

Ask a question

How to retrieve the changesets associated to a workitem via Java API


Luca Martinucci (1.0k294112) | asked Aug 25 '14, 4:35 a.m.
I am developing a Java extension (a follow-up action) to RTC 4.0.5, and I need to retrieve the list of changesets associated to a work item.
I have already managed  to retrieve a IWorkItem object; how can I retrieve its changesets (using server-side classes)?

Comments
1
Kevin Eifinger commented Sep 02 '14, 5:25 a.m. | edited Sep 03 '14, 3:23 a.m.
Hi Luca,

I have never done this but
I'd try to iterate over the links and find links which link to a changeset.

You can retrieve all links from a workItem with:
workItemCommon.resolveWorkItemReferences(workItem, monitor)

Hope this helps

Accepted answer


permanent link
Olivier CRIDLIG (52610) | answered Sep 02 '14, 11:52 a.m.
 Hi,

see below an example :

     private List<IChangeSet> getChangeSets(IWorkItem wi)
             throws TeamRepositoryException {
        
         IRepositoryItemService repositoryItemService = getService(IRepositoryItemService.class);

         ILinkService linkService = getService(ILinkService.class);
         ILinkServiceLibrary linkLibrary = (ILinkServiceLibrary) linkService
                 .getServiceLibrary(ILinkServiceLibrary.class);
         IItemReference workItemRef = IReferenceFactory.INSTANCE
                 .createReferenceToItem(wi);
         ILinkQueryPage linkPage = linkLibrary.findLinks(
                 WorkItemLinkTypes.CHANGE_SET, workItemRef);

         List<IChangeSet> changeSets = new ArrayList<IChangeSet>();

         for (ILink link : linkPage.getAllLinksFromHereOn()) {
             // Change set links should be item references
             IChangeSetHandle changeSetHandle = (IChangeSetHandle) link
                     .getSourceRef().resolve();
             IChangeSet changeSet = (IChangeSet) repositoryItemService
                     .fetchItem(changeSetHandle, IRepositoryItemService.COMPLETE);
             changeSets.add(changeSet);
         }
         return changeSets;
     }


Luca Martinucci selected this answer as the correct answer

Comments
Luca Martinucci commented Sep 04 '14, 5:59 a.m.

Olivier, thanks for providing me with this example: it worked, with some minor corrections.


Alissa Ahrens commented May 18 '17, 10:43 a.m. | edited May 18 '17, 11:36 a.m.

 Hello,


In this example there is getService method: 
        
 IRepositoryItemService repositoryItemService = getService(IRepositoryItemService.class); 
         ILinkService linkService = getService(ILinkService.class);


Where does this come from/what are the contents of this method? 

Thanks!


Ralph Schoon commented May 18 '17, 1:44 p.m. | edited May 18 '17, 1:46 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

That is server side API. The extension extends AbstractService which provides getService().

See https://rsjazz.wordpress.com/2016/02/03/setting-access-control-permissions-for-scm-versionables/ for server and Client API. See https://rsjazz.wordpress.com/2015/09/30/learning-to-fly-getting-started-with-the-rtc-java-apis/ to get started.

3 other answers



permanent link
vikrant kamble (1322996) | answered Aug 14 '15, 5:30 a.m.
 Hi lucca?
Do you know how can we get filenames of changeset associated to work item

permanent link
Olivier CRIDLIG (52610) | answered Aug 14 '15, 10:15 a.m.
 Hi,
 
 I think it should work :
 
 
 for (Object o : changeSet.changes()) {
     IChange change = (IChange) o;
     IVersionableHandle handle = change.item();
    
     IVersionable afterVersionable = workspaceManager.versionableManager().fetchCompleteState(handle, new SysoutProgressMonitor());
     afterVersionable.getName();
}

permanent link
vikrant kamble (1322996) | answered Sep 07 '15, 9:04 a.m.
 Hi Olivier,
In your above answer to fetch change set associated to work item, you have used server API.
Could you please tell me about java client API which does similar thing.
I figured out that instead of IRepositoryItemService we can use IItemManager at client side.
instead of ILinkServiceLibrary we can use ILinkManager at client side. 
Other are common API.
but 
 IChangeSet changeSet = (IChangeSet) repositoryItemService
                     .fetchItem(changeSetHandle, IRepositoryItemService.COMPLETE);

I replaced it with

IChangeSet changeSet = (IChangeSet) itemManager.fetchCompleteItem(changeSetHandle,itemManager.DEFAULT, monitor);
but at this line it is throwing null pointer exception
Could you please tell me about client API which will does similar thing.

Your answer


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