Getting build result linked to a work item
Hi, I am writing a RTC server-side plugin (operation participant) and would like to get the build result record linked to a work item ie. Using the "Reported against Build" link on the work item. This particular link is not defined in both WorkItemTypes.java or WorkItemEndPoints.java (in com\ibm\team\workitem\common\model). Any one know how I can do this? I can't find anything that may also list all links (from which I can look for the one I need).
Thanks.
Sola
Thanks.
Sola
Accepted answer
The build-related link types are defined by the Build component. The Work Items component doesn't know about them. Constants for them are defined in com.ibm.team.build.internal.common.links.BuildLinkTypes, i.e.
These are item links, so the source reference is a build result item handle, and the target reference is a work item handle.
To create the link, use ILinkServiceLibrary methods, e.g. something like:
where getLinkServiceLibrary() is:
/**
* Link between a build and a work item to indicate that the work item was
* reported against the build.
*/
public static final String REPORTED_WORK_ITEMS = "com.ibm.team.build.linktype.reportedWorkItems"; //$NON-NLS-1$
/**
* Link between a build and a work item to indicate that the changes
* associated with the work item are included in the build.
*/
public static final String INCLUDED_WORK_ITEMS = "com.ibm.team.build.linktype.includedWorkItems"; //$NON-NLS-1$
These are item links, so the source reference is a build result item handle, and the target reference is a work item handle.
To create the link, use ILinkServiceLibrary methods, e.g. something like:
ILinkServiceLibrary linkService = getLinkServiceLibrary();
IBuildResultHandle buildResultHandle = ...;
IWorkItemHandle workItemHandle = ...;
IItemReference buildResultRef = linkService.referenceFactory().createReferenceToItem(buildResultHandle);
IItemReference workItemRef = linkService.referenceFactory().createReferenceToItem(workItemHandle);
ILink link = linkService.createLink("com.ibm.team.build.linktype.reportedWorkItems", buildResultRef, workItemRef);
linkService.saveLink(link);
where getLinkServiceLibrary() is:
private ILinkServiceLibrary getLinkServiceLibrary() {
return (ILinkServiceLibrary) getService(ILinkService.class).getServiceLibrary(ILinkServiceLibrary.class);
}
3 other answers
The build-related link types are defined by the Build component. The Work Items component doesn't know about them. Constants for them are defined in com.ibm.team.build.internal.common.links.BuildLinkTypes, i.e./**
* Link between a build and a work item to indicate that the work item was
* reported against the build.
*/
public static final String REPORTED_WORK_ITEMS = "com.ibm.team.build.linktype.reportedWorkItems"; //$NON-NLS-1$
/**
* Link between a build and a work item to indicate that the changes
* associated with the work item are included in the build.
*/
public static final String INCLUDED_WORK_ITEMS = "com.ibm.team.build.linktype.includedWorkItems"; //$NON-NLS-1$
These are item links, so the source reference is a build result item handle, and the target reference is a work item handle.
To create the link, use ILinkServiceLibrary methods, e.g. something like:
ILinkServiceLibrary linkService = getLinkServiceLibrary();
IBuildResultHandle buildResultHandle = ...;
IWorkItemHandle workItemHandle = ...;
IItemReference buildResultRef = linkService.referenceFactory().createReferenceToItem(buildResultHandle);
IItemReference workItemRef = linkService.referenceFactory().createReferenceToItem(workItemHandle);
ILink link = linkService.createLink("com.ibm.team.build.linktype.reportedWorkItems", buildResultRef, workItemRef);
linkService.saveLink(link);
where getLinkServiceLibrary() is:
private ILinkServiceLibrary getLinkServiceLibrary() {
return (ILinkServiceLibrary) getService(ILinkService.class).getServiceLibrary(ILinkServiceLibrary.class);
}
Hi,
Do you know how we can do the same from a snippet because we don't see ILinkServiceLibrary on the plain libraries client size.
Thanks
The corresponding client-side methods are all on com.ibm.team.links.client.ILinkManager, which you can get as a client library from the ITeamRepository connection.
For example, Build's (internal) WorkItemHelper class uses these as follows:
For example, Build's (internal) WorkItemHelper class uses these as follows:
public static IWorkItemHandle[] getLinkedWorkItems(ITeamRepository teamRepository,
IBuildResultHandle buildResultHandle, String buildLinkType, IProgressMonitor monitor)
throws TeamRepositoryException {
ValidationHelper.validateNotNull("teamRepository", teamRepository); //$NON-NLS-1$
ValidationHelper.validateNotNull("buildResultHandle", buildResultHandle); //$NON-NLS-1$
ValidationHelper.validateNotNull("buildLinkType", buildLinkType); //$NON-NLS-1$
List<IWorkItemHandle> reportedWorkItems = new ArrayList<IWorkItemHandle>();
ILinkManager linkManager = (ILinkManager) teamRepository.getClientLibrary(ILinkManager.class);
IReference source = linkManager.referenceFactory().createReferenceToItem(buildResultHandle);
ILinkCollection referencesToResults = linkManager.findLinksBySource(buildLinkType, source,
monitor).getAllLinksFromHereOn();
for (Object object : referencesToResults) {
ILink link = (ILink) object;
IWorkItemHandle workItemHandle = (IWorkItemHandle) link.getTargetRef().resolve();
if (workItemHandle != null) {
reportedWorkItems.add(workItemHandle);
}
}
return (IWorkItemHandle[]) reportedWorkItems.toArray(new IWorkItemHandle[reportedWorkItems.size()]);
}