Search in sources :

Example 1 with DelegateExecution

use of org.camunda.bpm.engine.delegate.DelegateExecution in project camunda-bpm-platform by camunda.

the class ProcessApplicationEventListenerDelegate method notify.

public void notify(final DelegateTask delegateTask) {
    if (delegateTask.getExecution() == null) {
        LOG.taskNotRelatedToExecution(delegateTask);
    } else {
        final DelegateExecution execution = delegateTask.getExecution();
        Callable<Void> notification = new Callable<Void>() {

            public Void call() throws Exception {
                notifyTaskListener(delegateTask);
                return null;
            }
        };
        try {
            performNotification(execution, notification);
        } catch (Exception e) {
            throw LOG.exceptionWhileNotifyingPaTaskListener(e);
        }
    }
}
Also used : DelegateExecution(org.camunda.bpm.engine.delegate.DelegateExecution) Callable(java.util.concurrent.Callable) ProcessApplicationUnavailableException(org.camunda.bpm.application.ProcessApplicationUnavailableException)

Example 2 with DelegateExecution

use of org.camunda.bpm.engine.delegate.DelegateExecution in project camunda-bpm-platform by camunda.

the class AbstractDeleteProcessInstanceCmd method triggerHistoryEvent.

public void triggerHistoryEvent(List<ProcessInstance> subProcesslist) {
    ProcessEngineConfigurationImpl configuration = Context.getProcessEngineConfiguration();
    HistoryLevel historyLevel = configuration.getHistoryLevel();
    for (final ProcessInstance processInstance : subProcesslist) {
        // ParseListener
        if (historyLevel.isHistoryEventProduced(HistoryEventTypes.PROCESS_INSTANCE_UPDATE, processInstance)) {
            HistoryEventProcessor.processHistoryEvents(new HistoryEventProcessor.HistoryEventCreator() {

                @Override
                public HistoryEvent createHistoryEvent(HistoryEventProducer producer) {
                    return producer.createProcessInstanceUpdateEvt((DelegateExecution) processInstance);
                }
            });
        }
    }
}
Also used : HistoryLevel(org.camunda.bpm.engine.impl.history.HistoryLevel) HistoryEventProcessor(org.camunda.bpm.engine.impl.history.event.HistoryEventProcessor) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) DelegateExecution(org.camunda.bpm.engine.delegate.DelegateExecution) HistoryEventProducer(org.camunda.bpm.engine.impl.history.producer.HistoryEventProducer) HistoryEvent(org.camunda.bpm.engine.impl.history.event.HistoryEvent) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)

Example 3 with DelegateExecution

use of org.camunda.bpm.engine.delegate.DelegateExecution in project camunda-bpm-platform by camunda.

the class ProcessApplicationEventListenerTest method testExecutionListener.

@Deployment
public void testExecutionListener() {
    final AtomicInteger eventCount = new AtomicInteger();
    EmbeddedProcessApplication processApplication = new EmbeddedProcessApplication() {

        public ExecutionListener getExecutionListener() {
            // this process application returns an execution listener
            return new ExecutionListener() {

                public void notify(DelegateExecution execution) throws Exception {
                    eventCount.incrementAndGet();
                }
            };
        }
    };
    // register app so that it is notified about events
    managementService.registerProcessApplication(deploymentId, processApplication.getReference());
    // start process instance
    runtimeService.startProcessInstanceByKey("startToEnd");
    // 7 events received
    assertEquals(7, eventCount.get());
}
Also used : EmbeddedProcessApplication(org.camunda.bpm.application.impl.EmbeddedProcessApplication) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DelegateExecution(org.camunda.bpm.engine.delegate.DelegateExecution) ExecutionListener(org.camunda.bpm.engine.delegate.ExecutionListener) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 4 with DelegateExecution

use of org.camunda.bpm.engine.delegate.DelegateExecution in project camunda-bpm-platform by camunda.

the class ProcessApplicationEventListenerTest method testExecutionListenerWithMultiInstanceBody.

@Deployment
public void testExecutionListenerWithMultiInstanceBody() {
    final AtomicInteger eventCountForMultiInstanceBody = new AtomicInteger();
    EmbeddedProcessApplication processApplication = new EmbeddedProcessApplication() {

        public ExecutionListener getExecutionListener() {
            return new ExecutionListener() {

                public void notify(DelegateExecution execution) throws Exception {
                    if ("miTasks#multiInstanceBody".equals(execution.getCurrentActivityId()) && (ExecutionListener.EVENTNAME_START.equals(execution.getEventName()) || ExecutionListener.EVENTNAME_END.equals(execution.getEventName()))) {
                        eventCountForMultiInstanceBody.incrementAndGet();
                    }
                }
            };
        }
    };
    // register app so that it is notified about events
    managementService.registerProcessApplication(deploymentId, processApplication.getReference());
    // start process instance
    runtimeService.startProcessInstanceByKey("executionListener");
    // complete task
    List<Task> miTasks = taskService.createTaskQuery().list();
    for (Task task : miTasks) {
        taskService.complete(task.getId());
    }
    // 2 events are expected: one for mi body start; one for mi body end
    assertEquals(2, eventCountForMultiInstanceBody.get());
}
Also used : DelegateTask(org.camunda.bpm.engine.delegate.DelegateTask) Task(org.camunda.bpm.engine.task.Task) EmbeddedProcessApplication(org.camunda.bpm.application.impl.EmbeddedProcessApplication) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DelegateExecution(org.camunda.bpm.engine.delegate.DelegateExecution) ExecutionListener(org.camunda.bpm.engine.delegate.ExecutionListener) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 5 with DelegateExecution

use of org.camunda.bpm.engine.delegate.DelegateExecution in project camunda-bpm-platform by camunda.

the class ProcessApplicationEventListenerTest method testIntermediateSignalEvent.

@Deployment
public void testIntermediateSignalEvent() {
    // given
    final List<String> timerEvents = new ArrayList<String>();
    EmbeddedProcessApplication processApplication = new EmbeddedProcessApplication() {

        public ExecutionListener getExecutionListener() {
            return new ExecutionListener() {

                public void notify(DelegateExecution delegateExecution) {
                    String currentActivityId = delegateExecution.getCurrentActivityId();
                    String eventName = delegateExecution.getEventName();
                    if ("signal".equals(currentActivityId) && (ExecutionListener.EVENTNAME_START.equals(eventName) || ExecutionListener.EVENTNAME_END.equals(eventName))) {
                        timerEvents.add(delegateExecution.getEventName());
                    }
                }
            };
        }
    };
    // register app so that it is notified about events
    managementService.registerProcessApplication(deploymentId, processApplication.getReference());
    // when
    runtimeService.startProcessInstanceByKey("process");
    runtimeService.signalEventReceived("abort");
    // then
    assertEquals(2, timerEvents.size());
    // "start" event listener
    assertEquals(ExecutionListener.EVENTNAME_START, timerEvents.get(0));
    // "end" event listener
    assertEquals(ExecutionListener.EVENTNAME_END, timerEvents.get(1));
}
Also used : EmbeddedProcessApplication(org.camunda.bpm.application.impl.EmbeddedProcessApplication) ArrayList(java.util.ArrayList) DelegateExecution(org.camunda.bpm.engine.delegate.DelegateExecution) ExecutionListener(org.camunda.bpm.engine.delegate.ExecutionListener) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

DelegateExecution (org.camunda.bpm.engine.delegate.DelegateExecution)23 EmbeddedProcessApplication (org.camunda.bpm.application.impl.EmbeddedProcessApplication)9 ExecutionListener (org.camunda.bpm.engine.delegate.ExecutionListener)9 Deployment (org.camunda.bpm.engine.test.Deployment)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 DelegateExecutionAsserter (org.camunda.bpm.engine.test.api.delegate.AssertingJavaDelegate.DelegateExecutionAsserter)6 DelegateTask (org.camunda.bpm.engine.delegate.DelegateTask)3 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)3 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)3 Task (org.camunda.bpm.engine.task.Task)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 IdentityService (org.camunda.bpm.engine.IdentityService)2 Authentication (org.camunda.bpm.engine.impl.identity.Authentication)2 ProcessDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)2 Map (java.util.Map)1 Callable (java.util.concurrent.Callable)1 ProcessApplicationUnavailableException (org.camunda.bpm.application.ProcessApplicationUnavailableException)1 ProcessEngineConfigurationImpl (org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)1 HistoryLevel (org.camunda.bpm.engine.impl.history.HistoryLevel)1