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?? |
One answer
public class Evento extends AbstractService implements 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..
|
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.