It's all about the answers!

Ask a question

RTC Extension - Participant


Bartosz Chrabski (3.4k22949) | asked Jun 24 '14, 5:24 p.m.
edited Jun 24 '14, 5:35 p.m.
Hi Jazz Team,

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


permanent link
sam detweiler (12.5k6195201) | answered Jun 24 '14, 7:11 p.m.
edited Jun 24 '14, 7:16 p.m.
    // 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);      
            }
       }
Bartosz Chrabski selected this answer as the correct answer

Comments
Susan Hanson commented Jun 24 '14, 7:30 p.m.

SWEET!!!!  You have just made my day!


Bartosz Chrabski commented Jun 25 '14, 5:43 a.m.

Thanks a lot  

One other answer



permanent link
Susan Hanson (1.6k2201194) | answered Jun 24 '14, 5:41 p.m.
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

Comments
sam detweiler commented Jun 24 '14, 6:33 p.m.

or you use saveworkitem3 and pass a parameter in the last parm that tells your code its you invoking the extension, and ignore it


Susan Hanson commented Jun 24 '14, 6:42 p.m.
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

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.