RTC Extension - Participant
Hi Jazz Team,
plugin.xml
I am creating RTC extension which will change some attr values after save but even when I am creating sample example I received error after save. Maybe somebody will have some ideas
Error: Problem An error occurred during "Save Work Item". java.lang.StackOverflowError
import org.eclipse.core.runtime.IProgressMonitor;
import com.ibm.team.process.common.IProcessConfigurationElement;
import com.ibm.team.process.common.advice.AdvisableOperation;
import com.ibm.team.process.common.advice.IProcessReport;
import com.ibm.team.process.common.advice.IReportInfo;
import com.ibm.team.process.common.advice.runtime.IOperationParticipant;
import com.ibm.team.process.common.advice.runtime.IParticipantInfoCollector;
import com.ibm.team.repository.common.IAuditable;
import com.ibm.team.repository.common.TeamRepositoryException;
import com.ibm.team.repository.service.AbstractService;
import com.ibm.team.workitem.common.ISaveParameter;
import com.ibm.team.workitem.common.model.IWorkItem;
import com.ibm.team.workitem.service.IWorkItemServer;
public class OperationParticipant extends AbstractService implements
IOperationParticipant {
@Override
public void run(AdvisableOperation operation,
IProcessConfigurationElement participantConfig,
IParticipantInfoCollector collector, IProgressMonitor monitor)
throws TeamRepositoryException {
Object data = operation.getOperationData();
if (data instanceof ISaveParameter)
{
ISaveParameter save = (ISaveParameter)data;
IAuditable audi = save.getNewState();
if(audi instanceof IWorkItem)
{
IWorkItem wi = (IWorkItem)audi;
IWorkItemServer server = getService(com.ibm.team.workitem.service.IWorkItemServer.class);
IWorkItem itemCopy=(IWorkItem)server.findWorkItemById(wi.getId(), IWorkItem.FULL_PROFILE, null).getWorkingCopy();
itemCopy.setHTMLSummary(XMLString.createFromPlainText("Test"));
server.saveWorkItem2(itemCopy, null, null);
}
}
}
}
plugin.xml
Accepted answer
// setup
private static final String Recursion = "Approvalsbypass"; // can be anything u want must be unique
private static Set<String> bypass =
new HashSet<String>(new ArrayList<String>(Arrays.asList(Recursion)));
// in handler
Object data = operation.getOperationData();
ISaveParameter saveParameter = null;
if (data instanceof ISaveParameter)
{
saveParameter = (ISaveParameter) data;
// check to see if we are being called again from our save
// if not, process, otherwise skip the work
// if no parms, or the parm is not ours, process request.
if ( (saveParameter.getAdditionalSaveParameters() == null)
||
((saveParameter.getAdditionalSaveParameters() != null)
&& (!saveParameter.getAdditionalSaveParameters().contains(Recursion)))
)
{
// do all your normal processing here
...
// if u need to update the workitem you are processing for
// this will cause this plugin to be called again
saveStatus = fWorkItemServer.saveWorkItem3(workingCopy, null, null, bypass);
}
}
private static final String Recursion = "Approvalsbypass"; // can be anything u want must be unique
private static Set<String> bypass =
new HashSet<String>(new ArrayList<String>(Arrays.asList(Recursion)));
// in handler
Object data = operation.getOperationData();
ISaveParameter saveParameter = null;
if (data instanceof ISaveParameter)
{
saveParameter = (ISaveParameter) data;
// check to see if we are being called again from our save
// if not, process, otherwise skip the work
// if no parms, or the parm is not ours, process request.
if ( (saveParameter.getAdditionalSaveParameters() == null)
||
((saveParameter.getAdditionalSaveParameters() != null)
&& (!saveParameter.getAdditionalSaveParameters().contains(Recursion)))
)
{
// do all your normal processing here
...
// if u need to update the workitem you are processing for
// this will cause this plugin to be called again
saveStatus = fWorkItemServer.saveWorkItem3(workingCopy, null, null, bypass);
}
}
One other answer
Normally this means that you are recursing through this until you run out of memory.
Remember that when you do the Save, it will invoke this same participant again (because you saved the work item).
So basically, first time, you go in, save html summary. This calls the same one, it sets the html summary and saves, which sets the HTML summary and saves, which calls it again and sets the html summary and saves .....
So you have to have something where you decide you do *not* need to set the HTML summary and you get out.
Susan
Remember that when you do the Save, it will invoke this same participant again (because you saved the work item).
So basically, first time, you go in, save html summary. This calls the same one, it sets the html summary and saves, which sets the HTML summary and saves, which calls it again and sets the html summary and saves .....
So you have to have something where you decide you do *not* need to set the HTML summary and you get out.
Susan
Comments
or you use saveworkitem3 and pass a parameter in the last parm that tells your code its you invoking the extension, and ignore it
- I looked at this and it gives me these options ... which of them would tell my code that I am invoking the extension again??
-
- additionalSaveParameters contains the additional save parameter. Supported types for additionalSaveParameters are: IAdditionalSaveParameters.IGNORE_COMMENT_UPDATES IAdditionalSaveParameters.IGNORE_BACKLINK_PROBLEMS IAdditionalSaveParameters.UPDATE_BACKLINKS IAdditionalSaveParameters.SKIP_VALIDATION_ATTRIBUTE_NAME