It's all about the answers!

Ask a question

Plugin Participant fails when saveWorkItem2


Marcos Sánchez (19711) | asked Apr 30 '13, 10:18 a.m.
edited Apr 30 '13, 10:24 a.m.
Hi,

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


permanent link
Ralph Schoon (63.1k33646) | answered Apr 30 '13, 10:25 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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.

Marcos Sánchez selected this answer as the correct answer

Comments
Marcos Sánchez commented Apr 30 '13, 10:39 a.m. | edited Apr 30 '13, 11:22 a.m.

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.


1
sam detweiler commented Apr 30 '13, 10:46 a.m.

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 );  



Ralph Schoon commented Apr 30 '13, 11:21 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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.....

2 other answers



permanent link
Marcos Sánchez (19711) | answered May 02 '13, 8:24 a.m.
Thank you very much Ralph and Sam.

I understand / resolve my doubts and solved the problem.

permanent link
sam detweiler (12.5k6195201) | answered Apr 30 '13, 12:15 p.m.
usually you use saveWorkitem3(workitem, null, null, parm) so you can pass yourself a parameter to be able to detect recursion

saveWorkItem3(sourceWorkItem, null, null, additionalParams);


Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.