Plugin Participant fails when saveWorkItem2
Hi,
I want to create a plugin (IOperationParticipant) thats auto create Approvers (with the creator)
I want to create a plugin (IOperationParticipant) thats auto create Approvers (with the creator)
public class WIAprovalsParticipand extends AbstractService implements IOperationParticipant {
private static final String APPROVAL_NAME = "Aprobacion DA";
private IWorkItemServer fWorkItemServer = null;
private IProcessServerService fProcessServerService = null;
private IAuditableCommon fAuditableCommon = null;
public void run(AdvisableOperation operation,IProcessConfigurationElement participantConfig,IParticipantInfoCollector collector, IProgressMonitor monitor) throws TeamRepositoryException {
Object data= operation.getOperationData();
fWorkItemServer = getService(IWorkItemServer.class);
fAuditableCommon = getService(IAuditableCommon.class);
if (data instanceof ISaveParameter) {
IAuditable auditable = ((ISaveParameter)data).getNewState();
if (auditable instanceof IWorkItem) {
IWorkItem workItem = (IWorkItem) auditable;IWorkItem workingCopy = (IWorkItem) fWorkItemServer .getAuditableCommon() .resolveAuditable(workItem, IWorkItem.FULL_PROFILE, monitor) .getWorkingCopy();
Approvals approvals = workingCopy.getApprovals();
IApprovalDescriptor descriptor= approvals.createDescriptor(WorkItemApprovals.REVIEW_TYPE.getIdentifier(), APPROVAL_NAME);
IContributorHandle reviewer = workingCopy.getCreator();
IApproval approval= approvals.createApproval(descriptor, reviewer); approvals.add(approval);
IStatus saveStatus = fWorkItemServer.saveWorkItem2(workingCopy, null, null ); ...
I Can add the follow action to Save WI, but doesnt work, the server is "Saving" loop and dont stop, the ccm log is full with:
2013-04-30 15:08:57,021 [ WebContainer : 6] ERROR com.ibm.team.workitem.common - Error invoking value provider 'com.ibm.team.workitem.valueproviders.VALUE_PROVIDER._QNifQGC9EeKTg8I24BTQkg'java.lang.NullPointerException
I Can add the follow action to Save WI, but doesnt work, the server is "Saving" loop and dont stop, the ccm log is full.
think my error is in the SaveWorkitem? because I prove and I access to the attributes of the WorkItem.
Anybody can help me?
Thanks.
Accepted answer
Marcos,
here a description how such a participant can be developed: https://rsjazz.wordpress.com/2012/11/30/a-create-approval-work-item-save-participant/ - with code - and here a deeper reasoning on how to avoid recursions https://rsjazz.wordpress.com/2012/07/31/rtc-update-parent-duration-estimation-and-effort-participant/ look at the end of the post if you are in a hurry.
Hope that helps.
here a description how such a participant can be developed: https://rsjazz.wordpress.com/2012/11/30/a-create-approval-work-item-save-participant/ - with code - and here a deeper reasoning on how to avoid recursions https://rsjazz.wordpress.com/2012/07/31/rtc-update-parent-duration-estimation-and-effort-participant/ look at the end of the post if you are in a hurry.
Hope that helps.
Comments
Thanks Ralph for your time.
I dont understand why I have a recursion problem (like parents,child) if I want to create Approvers only and not affect to "Links Parents/Childs), no?
Thanks.
if you change some workitem and SAVE it, then the participant chain will run again.. BEFORE the current chain finishes..
IStatus saveStatus = fWorkItemServer.saveWorkItem2(workingCopy, null, null );
1 vote
Exactly, you save a work item. So all advisors and postconditions will run again. If you don't filter the save out, especially your participant will run again, which might add an approval, which will.....