It's all about the answers!

Ask a question

Can we update defect through IWorkItemSave followup action


Riddhi Shah (3721518) | asked Aug 06 '12, 9:11 a.m.
edited Aug 06 '12, 1:17 p.m. by Jared Burns (4.5k29)
Hi,

I need to update state of RTC Defect on save operation. For example, If user has moved status to "Reopen", description should be updated with "Reopen template" automatically. Is it possible to write followup action plugin for IWorkItemSave ?

If I try to update defect through OSLC service in "IWorkItemSave" followup plugin , it gives error of can not acquire lock in database.

- Riddhi

4 answers



permanent link
sam detweiler (12.5k6195201) | answered Aug 06 '12, 9:27 a.m.
well, you write a followup action (operation participant)  that is triggered on Workitem Save (server).. so it will be triggered whenever a workitem is saved.. it is up to your code to determine if the save action is one that needs to be handled..

Sam

Comments
Riddhi Shah commented Aug 06 '12, 9:41 a.m.

My question is , is it possible to update defect on trigger of workitem save ? On save, when trigger comes to followup action handler, I am trying to update state of defect through oslc service. which gives me error of can not acquire database lock.


David Olsen commented Aug 06 '12, 1:31 p.m.
JAZZ DEVELOPER

I think you want to use the Java interfaces to update the work item, not the OSLC services. The Java interfaces will use the same transaction and lock that are already held by the original save operation. The OSLC services take a different path and will try to open a new transaction. (This is partly a guess, so I could be completely wrong here.)


permanent link
Riddhi Shah (3721518) | answered Aug 17 '12, 1:20 a.m.
Hi David,

Event with java api, If I try to update my defect on followup action ( operation participant plugin on workitem save) it does not update the state of it. Following is my code for plugin:

 public void run(AdvisableOperation operation,
            IProcessConfigurationElement participantConfig,
            IParticipantInfoCollector collector, IProgressMonitor monitor)
            throws TeamRepositoryException
    {
        // TODO Auto-generated method stub
        Object data = operation.getOperationData();
        if (data instanceof ISaveParameter)
        {
            ISaveParameter saveParameter = (ISaveParameter) data;
            IAuditable auditable = saveParameter.getNewState();
       
            if (auditable instanceof IWorkItem)
            {
                workItemServer = getService(IWorkItemServer.class);
                wiCommon = getService(IWorkItemCommon.class);
               
                IWorkItem workItem = (IWorkItem) auditable;
                           
                            IWorkItem workItemWC = (IWorkItem)workItem.getWorkingCopy();
                           
                            if (workItemWC == null) {
                   
                                System.out.println("Work Item not found.");
                   
                                return;
                   
                            }
                            try
                            {
                                IAttribute summaryAttribute = wiCommon.findAttribute(workItemWC.getProjectArea(),SAVE_SUMMARY, monitor);
                               
                           
                                workItemWC.setValue(summaryAttribute, "updated from plugin");
                                workItemServer.saveWorkItem2(workItemWC, null, null);
                               
                            }
                            catch (Exception e)
                            {
                                    e.printStackTrace();
                               
                            }
                                   
                           
            }
        }
Above code works fine and auto updates summary on create of Defect. But on all subsequent updates it does not update summary.

permanent link
Filip Wieladek (30413) | answered Nov 26 '12, 11:50 a.m.
edited Nov 26 '12, 11:58 a.m.
Hey Riddhi,
As stated in the Javadoc in com.ibm.team.workitem.service.IWorkItemPostSaveParticipant a work item post save participant is not allowed to change the state of the work item. 
/**...
 * A work item post-save participant is run after a work item has been successfully saved.
 * If the work item save transaction fails, the participant will not be invoked. The participant
 * runs after the transaction and cannot modify the work item.
...
*/
Unfortunately, there is no actual save participant for work items ( as of RTC 4.0.1 ). You can only "veto" the save action either before the save action, or after the save action. If you need to perform something relatively simple, your best approach would be to use a Script based calculated value (Under Attribute Customization) which runs on every save action on a given attribute.

permanent link
sam detweiler (12.5k6195201) | answered Nov 26 '12, 12:11 p.m.
a participant (followup action) CAN update this or other workitems.

the saveworkitem2() call will cause ANOTHER trip thru the advisor and participants chain.  recursively.

so, it is recommended (required?) to use saveWorkitem3() which takes a last parameter to pass a flag to the newly invoked participant to ignore. (else, you save recursively until you run out of stack and cause an exception.

see https://jazz.net/forum/questions/94075/how-to-get-custom-attribute-value-with-java-api

Your answer


Register or to post your answer.