Can we update defect through IWorkItemSave followup action
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
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
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
Sam
Comments
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.
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.)
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.
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.
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.
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.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.
* 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.
...
*/
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
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