How do you assign an owner to children WIs automatically when saving a parent WI?
Accepted answer
Hi Take-san,
If you are talking about a custom followup action, I am doing like below. It doesn't work for a child WI which is created by a parent and you will need to add more exception handlings, but I think you can use this sample as a start point.
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;
if ( (saveParameter.getAdditionalSaveParameters() == null)
||
((saveParameter.getAdditionalSaveParameters() != null)
&& (!saveParameter.getAdditionalSaveParameters().contains(Recursion)))
) {
IWorkItem parent = (IWorkItem) saveParameter.getNewState();
IContributorHandle owner = parent.getOwner();
List<IWorkItemHandle> workItemHandleList = findChildHandle(saveParameter, monitor);
if(workItemHandleList.isEmpty()){
return;
}
IWorkItemServer workItemServer = getService(IWorkItemServer.class);
Iterator<IWorkItemHandle> iter = workItemHandleList.iterator();
while (iter.hasNext()){
IWorkItemHandle workItemHandle = (IWorkItemHandle)iter.next();
IWorkItem workItem = (IWorkItem) workItemServer.getAuditableCommon().resolveAuditable(workItemHandle, IWorkItem.FULL_PROFILE,
monitor).getWorkingCopy();
workItem.setOwner(owner);
workItemServer.saveWorkItem3(workItem, null, null, bypass);
}
}
}
private List<IWorkItemHandle> findChildHandle(ISaveParameter saveParameter,
IProgressMonitor monitor) throws TeamRepositoryException {
List<IWorkItemHandle> workItemHandleList = new ArrayList<IWorkItemHandle>();
List<IReference> references = saveParameter.getNewReferences()
.getReferences(WorkItemEndPoints.CHILD_WORK_ITEMS);
if (references.isEmpty())
return workItemHandleList;
for (IReference reference : references){
if (reference.isItemReference() && ((IItemReference) reference).getReferencedItem() instanceof IWorkItemHandle) {
workItemHandleList.add((IWorkItemHandle)((IItemReference) reference).getReferencedItem());
}
}
return workItemHandleList;
}
If you are talking about a custom followup action, I am doing like below. It doesn't work for a child WI which is created by a parent and you will need to add more exception handlings, but I think you can use this sample as a start point.
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;
if ( (saveParameter.getAdditionalSaveParameters() == null)
||
((saveParameter.getAdditionalSaveParameters() != null)
&& (!saveParameter.getAdditionalSaveParameters().contains(Recursion)))
) {
IWorkItem parent = (IWorkItem) saveParameter.getNewState();
IContributorHandle owner = parent.getOwner();
List<IWorkItemHandle> workItemHandleList = findChildHandle(saveParameter, monitor);
if(workItemHandleList.isEmpty()){
return;
}
IWorkItemServer workItemServer = getService(IWorkItemServer.class);
Iterator<IWorkItemHandle> iter = workItemHandleList.iterator();
while (iter.hasNext()){
IWorkItemHandle workItemHandle = (IWorkItemHandle)iter.next();
IWorkItem workItem = (IWorkItem) workItemServer.getAuditableCommon().resolveAuditable(workItemHandle, IWorkItem.FULL_PROFILE,
monitor).getWorkingCopy();
workItem.setOwner(owner);
workItemServer.saveWorkItem3(workItem, null, null, bypass);
}
}
}
private List<IWorkItemHandle> findChildHandle(ISaveParameter saveParameter,
IProgressMonitor monitor) throws TeamRepositoryException {
List<IWorkItemHandle> workItemHandleList = new ArrayList<IWorkItemHandle>();
List<IReference> references = saveParameter.getNewReferences()
.getReferences(WorkItemEndPoints.CHILD_WORK_ITEMS);
if (references.isEmpty())
return workItemHandleList;
for (IReference reference : references){
if (reference.isItemReference() && ((IItemReference) reference).getReferencedItem() instanceof IWorkItemHandle) {
workItemHandleList.add((IWorkItemHandle)((IItemReference) reference).getReferencedItem());
}
}
return workItemHandleList;
}