Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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??

0 votes



One answer

Permanent link
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

0 votes

Comments

 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?

yes, see my post on your same question..

use saveWorkitem3()

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,938

Question asked: Feb 16 '10, 5:05 a.m.

Question was seen: 7,119 times

Last updated: Nov 18 '12, 10:21 p.m.

Confirmation Cancel Confirm