With the RTC Java API, how do you modify a Changeset to associate a Work Item?
IWorkItemClient workItemClient = (IWorkItemClient)repo.getClientLibrary(IWorkItemClient.class);
IWorkItem workItem = workItemClient.findWorkItemById(workItemId, IWorkItem.FULL_PROFILE, myProgressMonitor);
// associate work item with changeset
IWorkItemWorkingCopyManager workItemWorkingCopyManager = workItemClient.getWorkItemWorkingCopyManager();
workItemWorkingCopyManager.connect(workItem, IWorkItem.FULL_PROFILE, null);
WorkItemWorkingCopy workItemWorkingCopy = workItemWorkingCopyManager.getWorkingCopy(workItem);
IItemType itemType = changeset.getItemType();
IItemHandle itemHandle = itemType.createItemHandle(changeset.getItemId(), changeset.getStateId());
IItemReference itemReference = IReferenceFactory.INSTANCE.createReferenceToItem(itemHandle);
IEndPointDescriptor endpoint = LinkTypeRegistry.INSTANCE.getLinkType(WorkItemLinkTypes.RELATED_CHANGE_MANAGEMENT).getTargetEndPointDescriptor();
workItemWorkingCopy.getReferences().add(endpoint, itemReference);
workItemWorkingCopy.save(myProgressMonitor);
One answer
This is most likely because the link type is incorrect. You want to use WorkItemLinkTypes.CHANGE_SET.
Note, that link type can only be created by the SCM component and you will likely have to do something about that. I would start with
com.ibm.team.filesystem.internal.rcp.ui.workitems.actions.AssociateWorkItemToChangeSetAction.run(Shell, IWorkbenchPage, IStructuredSelection)
Which uses com.ibm.team.filesystem.client.workitems.IFileSystemWorkItemManager.createLink(IWorkspaceHandle, IChangeSetHandle, IWorkItemHandle[], IProgressMonitor) to create the link.
Comments
I'm in an environment that is running outside of eclipse. It's a web based tool that needs to be able to checkin and deliver changes to various files that the tool makes. I don't have a Shell, IWorkbenchPage or anything else eclipse related that I can rely on. Is there something else I can use in the SCM component to do this that doesn't require me to be running in eclipse?
You use the Plain Java Client Libraries, so you have enough Java. I have no example code handy for what you want. My suggestion was to look in the RTC Eclipse Client set up with an SDK. You want to have this environment for development and debugging anyway. Look at the source code from com.ibm.team.filesystem.client.workitems.IFileSystemWorkItemManager.createLink(IWorkspaceHandle, IChangeSetHandle, IWorkItemHandle[], IProgressMonitor) . Maybe use this API to create the link?
https://rsjazz.wordpress.com/2015/09/30/learning-to-fly-getting-started-with-the-rtc-java-apis/ explains how to set up a proper development environment.
https://rsjazz.wordpress.com/2012/11/01/restrict-delivery-of-changesets-to-workitem-types-advisordelivery-of-changesets-associated-to-wrong-work-item-types-advisor/ shows linking (reading the link) from the SCM API perspective.
1 vote