How to find the Author and WI associated to change set using plain java Api
2 answers
Assuming you got an IChangeSet cs, you can retrieve the author this way:
IContributorHandle authorHandle = cs.getModifiedBy();
AbstractService abstractService = ....;
linkService = abstractService.getService(ILinkService.class);
ILinkServiceLibrary linkLibrary = (ILinkServiceLibrary) this.linkService.getServiceLibrary(ILinkServiceLibrary.class);
IItemReference changeSetRef = IReferenceFactory.INSTANCE.createReferenceToItem(cs);
ILinkQueryPage linkPage = linkLibrary.findLinks(ILinkConstants.CHANGESET_WORKITEM_LINKTYPE_ID, changeSetRef);
List<IWorkItem> workItems = new ArrayList<IWorkItem>();
IWorkItem workItem = null;
for (ILink link : linkPage.getAllLinksFromHereOn()) {
IWorkItemHandle IWorkItemHandle = (IWorkItemHandle) link.getTargetRef().resolve();
workItem = (IWorkItem) this.repositoryItemService.fetchItem(IWorkItemHandle, IRepositoryItemService.COMPLETE);
workItems.add(workItem);
}
Comments
But user name i get it in uuid format not proper name or ID.
The Java API usually returns handles and you have to resolve the handle, to get all the data. See https://rsjazz.wordpress.com/2013/03/20/understanding-and-using-the-rtc-java-client-api/ for some introduction. On that blog are many examples with code. You can search also e.g. for IContributorHandle and find code that uses this.
See https://rsjazz.wordpress.com/2012/11/01/restrict-delivery-of-changesets-to-workitem-types-advisordelivery-of-changesets-associated-to-wrong-work-item-types-advisor/ for the genral approach. That is however server API. Instead of WorkItemService you want to use the IWorkitemCommon or IWorkItemClient and instead of the itemservice you use the ITeamRepository you get. Also see