With the RTC Java API, how do you modify a Changeset to associate a Work Item?
I have found a lot of examples where you create a reference to a changeset in a work item, using the RTC Java API, but I need to do the opposite.
The reason being that my environment requires change sets to have work items associated with them, in order to deliver code.
When I attempt to deliver, I get the following Exception:
exception occured com.ibm.team.process.common.advice.TeamOperationCanceledException: 'Deliver' failed. Preconditions have not been met: A work item or change request must be associated with the change set.
I am running on RTC 6.0.2
The related code is as follows:
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);
.
Thanks for any help solving this.
One answer
I don't understand the question. I think you say you use the code above and the advisor does not recognize the link.
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.
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
1 vote