Change state event - update WorkItem
Hi,
I would like to change some attribute after a chenge state event.
I created a new plu-in
<xml>
<eclipse>
<plugin>
<extension>
<operationParticipant>
<extensionService>
<prerequisites>
<requiredService>
<requiredService>
<requiredService>
</prerequisites>
</extensionService>
</operationParticipant>
</extension>
<extension>
<eventHandler>
<extensionService>
<prerequisites>
<requiredService>
<requiredService>
<requiredService>
</prerequisites>
</extensionService>
</eventHandler>
</extension>
</plugin>
and a class Evento
public class Evento extends AbstractService implements IChangeEventHandler {
private IProcessConfigurationElement fConfigurationElement;
private IProjectArea fProjectArea;
private IProcessArea fProcessArea;
@Override
public void handleEvent(IChangeEvent event,
IProcessConfigurationElement handlerConfiguration)
throws TeamRepositoryException {
// TODO Auto-generated method stub
fProcessArea = (IProcessArea) event.getProcessArea();
IRepositoryItemService repoService = super.getService(IRepositoryItemService.class);
fProjectArea = (IProjectArea) repoService.fetchItem(fProcessArea.getProjectArea(), IRepositoryItemService.COMPLETE);
IAuditable auditable = ((ISaveParameter) event).getNewState();
IWorkItem workItem = (IWorkItem) auditable;
String summary = workItem.getHTMLSummary().getPlainText();
if(summary.contains("te")) {
IWorkItemServer service= getService(IWorkItemServer.class);
workItem.setHTMLSummary(XMLString.createFromPlainText("Example work item"));
service.saveWorkItem2(workItem, null, null );
}
}}
but don't work.
Any suggestion??
I would like to change some attribute after a chenge state event.
I created a new plu-in
<xml>
<eclipse>
<plugin>
<extension>
<operationParticipant>
<extensionService>
<prerequisites>
<requiredService>
<requiredService>
<requiredService>
</prerequisites>
</extensionService>
</operationParticipant>
</extension>
<extension>
<eventHandler>
<extensionService>
<prerequisites>
<requiredService>
<requiredService>
<requiredService>
</prerequisites>
</extensionService>
</eventHandler>
</extension>
</plugin>
and a class Evento
public class Evento extends AbstractService implements IChangeEventHandler {
private IProcessConfigurationElement fConfigurationElement;
private IProjectArea fProjectArea;
private IProcessArea fProcessArea;
@Override
public void handleEvent(IChangeEvent event,
IProcessConfigurationElement handlerConfiguration)
throws TeamRepositoryException {
// TODO Auto-generated method stub
fProcessArea = (IProcessArea) event.getProcessArea();
IRepositoryItemService repoService = super.getService(IRepositoryItemService.class);
fProjectArea = (IProjectArea) repoService.fetchItem(fProcessArea.getProjectArea(), IRepositoryItemService.COMPLETE);
IAuditable auditable = ((ISaveParameter) event).getNewState();
IWorkItem workItem = (IWorkItem) auditable;
String summary = workItem.getHTMLSummary().getPlainText();
if(summary.contains("te")) {
IWorkItemServer service= getService(IWorkItemServer.class);
workItem.setHTMLSummary(XMLString.createFromPlainText("Example work item"));
service.saveWorkItem2(workItem, null, null );
}
}}
but don't work.
Any suggestion??
One answer
public class Evento extends AbstractService implements
IChangeEventHandler {
private IProcessConfigurationElement fConfigurationElement;
private IProjectArea fProjectArea;
private IProcessArea fProcessArea;
@Override
public void handleEvent(IChangeEvent event,
IProcessConfigurationElement handlerConfiguration)
throws TeamRepositoryException {
// TODO Auto-generated method stub
fProcessArea = (IProcessArea) event.getProcessArea();
IRepositoryItemService repoService =
super.getService(IRepositoryItemService.class);
fProjectArea = (IProjectArea)
repoService.fetchItem(fProcessArea.getProjectArea(),
IRepositoryItemService.COMPLETE);
IAuditable auditable = ((ISaveParameter) event).getNewState();
IWorkItem workItem = (IWorkItem) auditable;
String summary = workItem.getHTMLSummary().getPlainText();
if(summary.contains("te")) {
IWorkItemServer service= getService(IWorkItemServer.class);
workItem.setHTMLSummary(XMLString.createFromPlainText("Example
work item"));
service.saveWorkItem2(workItem, null, null );
}
}}
but don't work.
Any suggestion??
I assume you get a class cast exception on this line:
fProcessArea = (IProcessArea) event.getProcessArea();
event.getProcessArea() returns only a handle that needs to be resolved
first.
You certainly get a class cast exception on this line:
IAuditable auditable = ((ISaveParameter) event).getNewState();
You cannot cast an IChangeEvent to an ISaveParameter. They are unrelated.
Use fetchItem(event.getItem(), ...) instead.
Please also note that saving a work item will create another change
event. Your code above will be called endlessly because you
unconditionally update the work item for each change event.
--
Regards,
Patrick
Jazz Work Item Team