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

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

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)?

0 votes

Comments
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

1 vote


Accepted answer

Permanent link
 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

3 votes

Comments

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

 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!

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
 Hi lucca?
Do you know how can we get filenames of changeset associated to work item

0 votes


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

0 votes


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

0 votes


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
× 10,930

Question asked: Aug 25 '14, 4:35 a.m.

Question was seen: 7,377 times

Last updated: May 18 '17, 1:46 p.m.

Confirmation Cancel Confirm