Problem in Operation Participant code.
Hi,
This is operation Participant code , It works fine only when I was create a new RCN it adds some description, but when I did some modifications in RCN page and again save, it didn't update the RCN description.
I want to update description whenever I click on save button.
what is the problem in the code I don't understand .....any help??
Code :
package test;
import org.eclipse.core.runtime.IProgressMonitor;
import com.ibm.team.foundation.common.text.XMLString;
import com.ibm.team.process.common.IProcessConfigurationElement;
import com.ibm.team.process.common.advice.AdvisableOperation;
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.IWorkItemCommon;
import com.ibm.team.workitem.common.model.IAttribute;
import com.ibm.team.workitem.common.model.IWorkItem;
import com.ibm.team.workitem.service.IWorkItemServer;
public class TestClass extends AbstractService implements IOperationParticipant {
private static final String SAVE_DESCRIPTION="description";
private IWorkItemServer workItemServer;
private IWorkItemCommon wiCommon;
public void run(AdvisableOperation operation,
IProcessConfigurationElement participantConfig,
IParticipantInfoCollector collector, IProgressMonitor monitor)
throws TeamRepositoryException
{
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_DESCRIPTION, monitor);
String str=workItemWC.getHTMLSummary()+"update new ";
workItemWC.setValue(summaryAttribute, str);
workItemServer.saveWorkItem2(workItemWC, null, null);
}
catch (Exception e)
{
// TODO: handle exception
}
}
}
}
}
This is operation Participant code , It works fine only when I was create a new RCN it adds some description, but when I did some modifications in RCN page and again save, it didn't update the RCN description.
I want to update description whenever I click on save button.
what is the problem in the code I don't understand .....any help??
Code :
package test;
import org.eclipse.core.runtime.IProgressMonitor;
import com.ibm.team.foundation.common.text.XMLString;
import com.ibm.team.process.common.IProcessConfigurationElement;
import com.ibm.team.process.common.advice.AdvisableOperation;
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.IWorkItemCommon;
import com.ibm.team.workitem.common.model.IAttribute;
import com.ibm.team.workitem.common.model.IWorkItem;
import com.ibm.team.workitem.service.IWorkItemServer;
public class TestClass extends AbstractService implements IOperationParticipant {
private static final String SAVE_DESCRIPTION="description";
private IWorkItemServer workItemServer;
private IWorkItemCommon wiCommon;
public void run(AdvisableOperation operation,
IProcessConfigurationElement participantConfig,
IParticipantInfoCollector collector, IProgressMonitor monitor)
throws TeamRepositoryException
{
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_DESCRIPTION, monitor);
String str=workItemWC.getHTMLSummary()+"update new ";
workItemWC.setValue(summaryAttribute, str);
workItemServer.saveWorkItem2(workItemWC, null, null);
}
catch (Exception e)
{
// TODO: handle exception
}
}
}
}
}