How do you get an IIteration object from an IIterationHandle with the Server API?
I've included a part of my code below. I'm trying to create a server extension that can subscribe users based on where a work item is in our plans/sprints so I access to the planned for value. Everything I've found talking about converting the IIterationHandle to an IIteration deals with the client API. How do you do this with the server API?
public void run(AdvisableOperation operation, IProcessConfigurationElement participantConfig,
IParticipantInfoCollector collector, IProgressMonitor monitor)
throws TeamRepositoryException
{
Object data = operation.getOperationData();
ISaveParameter saveParameter = null;
if(!(data instanceof ISaveParameter))
return;
saveParameter = (ISaveParameter) data;
IAuditable auditable = saveParameter.getNewState();
IWorkItem workitem = null;
if (auditable instanceof IWorkItem)
workitem = (IWorkItem) auditable;
if(workitem == null)
return;
workitem = (IWorkItem) workitem.getWorkingCopy();
IIterationHandle plannedForHandle = workitem.getTarget();
IIteration plannedFor = null;
if(plannedForHandle != null)
{
plannedFor = (IIteration)plannedForHandle.getFullState();
}
One answer
I found the solution for this issue.
I needed to use IRepositoryItemService.fetchItem to retrieve the IIteration object from the IIterationHandle.
Here's the snippets of code I added to my extension:
import com.ibm.team.repository.service.IRepositoryItemService;
private IRepositoryItemService itemService;
itemService = getService(IRepositoryItemService.class);
IIterationHandle plannedForHandle = workitem.getTarget();
IIteration plannedFor = (IIteration) itemService.fetchItem(plannedForHandle, null);