How do I retrieve potential duplicates of a work item
Hi,
I would like to be able to retrieve potential duplicates of a work item programmatically, as is done by the context menu "Find Potential Duplicates". I used the following code snippet to do that:
IWorkItemWorkingCopyManager manager = workItemClient.getWorkItemWorkingCopyManager();
manager.connect((IWorkItemHandle) sourceItem.getItemHandle(), IWorkItem.FULL_PROFILE, null);
sourceWorkingCopy = manager.getWorkingCopy((IWorkItemHandle) sourceItem.getItemHandle());
IWorkItemReferences references = sourceWorkingCopy.getReferences();
List<IReference> duplicates = references.getReferences(WorkItemEndPoints.DUPLICATE_WORK_ITEM);
// Check whether 'duplicates' is empty. If so, do:
duplicates = references.getReferences(WorkItemEndPoints.DUPLICATE_OF_WORK_ITEM);
I expected that 'duplicates' wouldn't be empty because when I executed "Find Potential Duplicates" on the source work item via the GUI, it returned some work items that have similar description. However, with the code above, the 'duplicates' list turned out to be empty. So, I suspected that
getReferences(WorkItemEndPoints.DUPLICATE_WORK_ITEM);
only returns the duplicates that are explicitly created as duplicates.
So, what is another way to retrieve potential duplicates? Your help will be appreciated.
Thanks,
Petcharat
I would like to be able to retrieve potential duplicates of a work item programmatically, as is done by the context menu "Find Potential Duplicates". I used the following code snippet to do that:
IWorkItemWorkingCopyManager manager = workItemClient.getWorkItemWorkingCopyManager();
manager.connect((IWorkItemHandle) sourceItem.getItemHandle(), IWorkItem.FULL_PROFILE, null);
sourceWorkingCopy = manager.getWorkingCopy((IWorkItemHandle) sourceItem.getItemHandle());
IWorkItemReferences references = sourceWorkingCopy.getReferences();
List<IReference> duplicates = references.getReferences(WorkItemEndPoints.DUPLICATE_WORK_ITEM);
// Check whether 'duplicates' is empty. If so, do:
duplicates = references.getReferences(WorkItemEndPoints.DUPLICATE_OF_WORK_ITEM);
I expected that 'duplicates' wouldn't be empty because when I executed "Find Potential Duplicates" on the source work item via the GUI, it returned some work items that have similar description. However, with the code above, the 'duplicates' list turned out to be empty. So, I suspected that
getReferences(WorkItemEndPoints.DUPLICATE_WORK_ITEM);
only returns the duplicates that are explicitly created as duplicates.
So, what is another way to retrieve potential duplicates? Your help will be appreciated.
Thanks,
Petcharat
One answer
Hi,
you can take a look at com.ibm.team.workitem.rcp.ui.QueriesUI.showRelatedWorkItems(IWorkbenchWindow, IWorkItem, boolean) which is used from the "Find potential duplicates" action. It creates an Expression for a duplicate search and sends it to the server for evaluation. Using work item references will - as you already found out - only return explicit duplicates, but not potential ones. To receive potential duplicates, a fulltext query is executed on the server.
Ben
Foundation & Work Item Team
you can take a look at com.ibm.team.workitem.rcp.ui.QueriesUI.showRelatedWorkItems(IWorkbenchWindow, IWorkItem, boolean) which is used from the "Find potential duplicates" action. It creates an Expression for a duplicate search and sends it to the server for evaluation. Using work item references will - as you already found out - only return explicit duplicates, but not potential ones. To receive potential duplicates, a fulltext query is executed on the server.
Ben
Foundation & Work Item Team