How to associate change set with work item using RTC Plain JAVA API ?
I am trying to associate the change set with work item with the following code and it saves the work item succefully but I can not see the Change set in the links of the work item.
IItemType changeItemType= changSet.getItemType();
IItemHandle changeItemHandle = changeItemType.createItemHandle(changSet.getItemId(),
changSet.getStateId());
IItemReference reference = IReferenceFactory.INSTANCE
.createReferenceToItem(changeItemHandle);
IEndPointDescriptor endpoint = LinkTypeRegistry.INSTANCE.getLinkType(
WorkItemLinkTypes.CHANGE_SET).getTargetEndPointDescriptor();
workItemWorkingCopy.getReferences().add(endpoint, reference);
workItemWorkingCopy.save(monitor);
However when I change the WorkItemLinkTypes to
'RELATED_CHANGE_MANAGEMENT' instead of 'CHANGE_SET' then the change set gets linked with work item.
Is there any way to link the 'WorkItemLinkTypes.CHANGE_SET' or can anyone check if I am missing anything in the above code ?
6 answers
Hi
I can successfully attach the changeset to the work item with the IFileSystemWorkItemManager as given below :
IFileSystemWorkItemManager fileSystemWorkItemManager = (IFileSystemWorkItemManager) teamRepository.getClientLibrary(IFileSystemWorkItemManager.class);
fileSystemWorkItemManager.createLink(workspaceHandle , changeSetHandle,workItemhandle , null);
Hi Lauren
Thanks for your quick reply and suggestion. I have tried the given solution but getting NullPointerException while retreving the ILinkServiceLibrary i.e. line marked in bold below. Also I am trying to do this using RTC JAVA client/plain API's and not using participant from server side.
ILinkService linkService = (ILinkService)repo.getClientLibrary(ILinkService.class);
ILinkServiceLibrary ls = (ILinkServiceLibrary) linkService.getServiceLibrary(ILinkServiceLibrary.class);
IReference changeReference= IReferenceFactory.INSTANCE.createReferenceToItem(changeSetHandle);
IReference workItemReference= IReferenceFactory.INSTANCE.createReferenceToItem(((IItem) workItemWorkingCopy).getItemHandle());
ILink il = ls.createLink(WorkItemLinkTypes.CHANGE_SET, changeReference, workItemReference);
ls.saveLink(il);
Hi Ralph
Thanks for your suggestions.
I have refered the links you given , however the change set is not getting linked with the work item with below code first without using ILinkServiceLibrary.
IItemType changeItemType= changSet.getItemType();
IItemHandle changeItemHandle = changeItemType.createItemHandle(changSet.getItemId(),
changSet.getStateId());
IItemReference reference = IReferenceFactory.INSTANCE
.createReferenceToItem(changeItemHandle);
IEndPointDescriptor endpoint = LinkTypeRegistry.INSTANCE.getLinkType(
WorkItemLinkTypes.CHANGE_SET).getTargetEndPointDescriptor();
workItemWorkingCopy.getReferences().add(endpoint, reference);
workItemWorkingCopy.save(monitor);
When I change the WorkItemLinkTypes to
'RELATED_CHANGE_MANAGEMENT' instead of 'CHANGE_SET' then the change set gets linked with work item as Related Change request and not as the ChangeSets .
Not sure if I am missing anything in the above code to link the change set as 'WorkItemLinkTypes.CHANGE_SET' to work item.
Hi Ralph
Thanks for your suggestions.
I have refered the links you given , however the change set is not getting linked with the work item with below code without using ILinkServiceLibrary.
IItemType changeItemType= changSet.getItemType();
IItemHandle changeItemHandle = changeItemType.createItemHandle(changSet.getItemId(),
changSet.getStateId());
IItemReference reference = IReferenceFactory.INSTANCE
.createReferenceToItem(changeItemHandle);
IEndPointDescriptor endpoint = LinkTypeRegistry.INSTANCE.getLinkType(
WorkItemLinkTypes.CHANGE_SET).getTargetEndPointDescriptor();
workItemWorkingCopy.getReferences().add(endpoint, reference);
workItemWorkingCopy.save(monitor);
When I change the WorkItemLinkTypes to
'RELATED_CHANGE_MANAGEMENT' instead of 'CHANGE_SET' then the change set gets linked with work item as Related Change request and not as the ChangeSets .
Not sure if I am missing anything in the above code to link the change set as 'WorkItemLinkTypes.CHANGE_SET' to work item.