It's all about the answers!

Ask a question

Change state event - update WorkItem


Salvatore Sollami (632) | asked Feb 16 '10, 5:05 a.m.
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??

One answer



permanent link
Patrick Streule (4.9k21) | answered Feb 16 '10, 9:23 a.m.
JAZZ DEVELOPER
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

Comments
haizi wu commented Nov 17 '12, 1:26 p.m.

 I have the same problem, I notice that there was a  service.saveWorkItem2(workItem, null, null ); statement would cause the endless workitem save operation, but I still want to get the workitem saved, is any solution?


sam detweiler commented Nov 18 '12, 10:21 p.m.

yes, see my post on your same question..

use saveWorkitem3()

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.