@@ -0,0 +1,3403 @@
+package org.nuxeo.ecm.platform.jbpm.core.helper;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0Aimport org.apache.commons.logging.Log;%0Aimport org.apache.commons.logging.LogFactory;%0Aimport org.jbpm.graph.exe.ExecutionContext;%0Aimport org.nuxeo.ecm.core.api.ClientException;%0Aimport org.nuxeo.ecm.core.api.CoreSession;%0Aimport org.nuxeo.ecm.core.api.DocumentModel;%0Aimport org.nuxeo.ecm.core.api.NuxeoPrincipal;%0Aimport org.nuxeo.ecm.core.event.EventProducer;%0Aimport org.nuxeo.ecm.core.event.impl.DocumentEventContext;%0Aimport org.nuxeo.ecm.platform.jbpm.AbstractJbpmHandlerHelper;%0Aimport org.nuxeo.ecm.platform.jbpm.JbpmService;%0Aimport org.nuxeo.ecm.platform.jbpm.VirtualTaskInstance;%0Aimport org.nuxeo.runtime.api.Framework;%0A%0A/**%0A * @author %3Ca href=%22mailto:akervern@nuxeo.com%22%3EArnaud Kervern%3C/a%3E%0A */%0Apublic class SendEventActionHandler extends AbstractJbpmHandlerHelper %7B%0A%0A    protected static final String INITIATOR = %22initiator%22;%0A%0A    protected static final String PARTICIPANTS = %22participants%22;%0A%0A    private static final Log log = LogFactory.getLog(%0A            AbstractJbpmHandlerHelper.class);%0A%0A    protected String eventName;%0A%0A    protected String recipients;%0A%0A    @Override%0A    public void execute(ExecutionContext executionContext) throws Exception %7B%0A        this.executionContext = executionContext;%0A        assert eventName != null;%0A        assert recipients != null;%0A%0A        if (nuxeoHasStarted()) %7B%0A            DocumentModel documentModel = (DocumentModel) getTransientVariable(%0A                    JbpmService.VariableName.document.name());%0A            NuxeoPrincipal principal = (NuxeoPrincipal) getTransientVariable(%0A                    JbpmService.VariableName.principal.name());%0A            if (documentModel == null) %7B%0A                return;%0A            %7D%0A%0A            CoreSession coreSession = getCoreSession(principal);%0A            try %7B%0A                EventProducer eventProducer = getEventProducerService();%0A                DocumentEventContext ctx = new DocumentEventContext(coreSession,%0A                        principal, documentModel);%0A                ctx.setProperty(%22recipients%22, getRecipients());%0A                eventProducer.fireEvent(ctx.newEvent(eventName));%0A            %7D finally %7B%0A                closeCoreSession(coreSession);%0A            %7D%0A        %7D%0A    %7D%0A%0A    protected EventProducer getEventProducerService() throws ClientException %7B%0A        try %7B%0A            return Framework.getService(EventProducer.class);%0A        %7D catch (Exception e) %7B%0A            throw new ClientException(e);%0A        %7D%0A    %7D%0A%0A    protected String%5B%5D getRecipients() %7B%0A        List%3CString%3E recipientsVal = new ArrayList%3CString%3E();%0A        if (recipients.equals(PARTICIPANTS)) %7B%0A            VirtualTaskInstance participant = (VirtualTaskInstance) executionContext%0A                .getContextInstance().getVariable(%0A                    JbpmService.VariableName.participants.name());%0A            if (participant != null) %7B%0A                recipientsVal.addAll(participant.getActors());%0A            %7D%0A        %7D else if (recipients.equals(INITIATOR)) %7B%0A            String actorId = (String) executionContext.getContextInstance()%0A                    .getVariable(JbpmService.VariableName.initiator.name());%0A            recipientsVal.add(actorId);%0A        %7D else %7B%0A            log.info(%22Unknown recipient : %22 + recipients);%0A        %7D%0A        return recipientsVal.toArray(new String%5B%5D%7B%7D);%0A    %7D%0A%7D%0A

Add new ActionHandler to fire a specified event.