How to retrieve the changesets associated to a workitem via Java API
Accepted answer
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;
}
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);
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
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();
}
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();
}
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.
Comments
Kevin Eifinger
Sep 03 '14, 3:23 a.m.1 vote