It's all about the answers!

Ask a question

With the RTC Java API, how do you modify a Changeset to associate a Work Item?

Eric Nelson (1515) | asked Aug 12 '16, 11:10 a.m.
edited Aug 15 '16, 9:42 a.m. by David Lafreniere (4.8k7)
 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 '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);;

Thanks for any help solving this. 

One answer

permanent link
Ralph Schoon (63.3k33646) | answered Aug 15 '16, 4:02 a.m.
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, IWorkbenchPage, IStructuredSelection)
Which uses, IChangeSetHandle, IWorkItemHandle[], IProgressMonitor) to create the link.

Eric Nelson commented Aug 17 '16, 11:33 a.m.

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?


Ralph Schoon commented Aug 18 '16, 3:38 a.m. | edited Aug 18 '16, 3:49 a.m.

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, IChangeSetHandle, IWorkItemHandle[], IProgressMonitor) . Maybe use this API to create the link? explains how to set up a proper development environment.

Ralph Schoon commented Aug 18 '16, 3:43 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER shows linking (reading the link) from the SCM API perspective.

Your answer

Register or to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.