Search in sources :

Example 1 with ErrorThrowingEventListener

use of org.activiti.engine.impl.bpmn.helper.ErrorThrowingEventListener in project Activiti by Activiti.

the class ErrorThrowingEventListenerTest method testThrowError.

@Deployment
public void testThrowError() throws Exception {
    ErrorThrowingEventListener listener = null;
    try {
        listener = new ErrorThrowingEventListener();
        processEngineConfiguration.getEventDispatcher().addEventListener(listener, ActivitiEventType.TASK_ASSIGNED);
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testError");
        assertNotNull(processInstance);
        // Fetch the task and assign it. Should cause error-event to be dispatched
        Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).taskDefinitionKey("userTask").singleResult();
        assertNotNull(task);
        taskService.setAssignee(task.getId(), "kermit");
        // Error-handling should have been called, and "escalate" task should be available instead of original one
        task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).taskDefinitionKey("escalatedTask").singleResult();
        assertNotNull(task);
    } finally {
        processEngineConfiguration.getEventDispatcher().removeEventListener(listener);
    }
}
Also used : Task(org.activiti.engine.task.Task) ErrorThrowingEventListener(org.activiti.engine.impl.bpmn.helper.ErrorThrowingEventListener) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Example 2 with ErrorThrowingEventListener

use of org.activiti.engine.impl.bpmn.helper.ErrorThrowingEventListener in project Activiti by Activiti.

the class DefaultListenerFactory method createEventThrowingEventListener.

@Override
public ActivitiEventListener createEventThrowingEventListener(EventListener eventListener) {
    BaseDelegateEventListener result = null;
    if (ImplementationType.IMPLEMENTATION_TYPE_THROW_SIGNAL_EVENT.equals(eventListener.getImplementationType())) {
        result = new SignalThrowingEventListener();
        ((SignalThrowingEventListener) result).setSignalName(eventListener.getImplementation());
        ((SignalThrowingEventListener) result).setProcessInstanceScope(true);
    } else if (ImplementationType.IMPLEMENTATION_TYPE_THROW_GLOBAL_SIGNAL_EVENT.equals(eventListener.getImplementationType())) {
        result = new SignalThrowingEventListener();
        ((SignalThrowingEventListener) result).setSignalName(eventListener.getImplementation());
        ((SignalThrowingEventListener) result).setProcessInstanceScope(false);
    } else if (ImplementationType.IMPLEMENTATION_TYPE_THROW_MESSAGE_EVENT.equals(eventListener.getImplementationType())) {
        result = new MessageThrowingEventListener();
        ((MessageThrowingEventListener) result).setMessageName(eventListener.getImplementation());
    } else if (ImplementationType.IMPLEMENTATION_TYPE_THROW_ERROR_EVENT.equals(eventListener.getImplementationType())) {
        result = new ErrorThrowingEventListener();
        ((ErrorThrowingEventListener) result).setErrorCode(eventListener.getImplementation());
    }
    if (result == null) {
        throw new ActivitiIllegalArgumentException("Cannot create an event-throwing event-listener, unknown implementation type: " + eventListener.getImplementationType());
    }
    result.setEntityClass(getEntityType(eventListener.getEntityType()));
    return result;
}
Also used : ErrorThrowingEventListener(org.activiti.engine.impl.bpmn.helper.ErrorThrowingEventListener) MessageThrowingEventListener(org.activiti.engine.impl.bpmn.helper.MessageThrowingEventListener) SignalThrowingEventListener(org.activiti.engine.impl.bpmn.helper.SignalThrowingEventListener) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) BaseDelegateEventListener(org.activiti.engine.impl.bpmn.helper.BaseDelegateEventListener)

Example 3 with ErrorThrowingEventListener

use of org.activiti.engine.impl.bpmn.helper.ErrorThrowingEventListener in project Activiti by Activiti.

the class ErrorThrowingEventListenerTest method testThrowErrorWithErrorcode.

@Deployment
public void testThrowErrorWithErrorcode() throws Exception {
    ErrorThrowingEventListener listener = null;
    try {
        listener = new ErrorThrowingEventListener();
        listener.setErrorCode("123");
        processEngineConfiguration.getEventDispatcher().addEventListener(listener, ActivitiEventType.TASK_ASSIGNED);
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testError");
        assertNotNull(processInstance);
        // Fetch the task and assign it. Should cause error-event to be dispatched
        Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).taskDefinitionKey("userTask").singleResult();
        assertNotNull(task);
        taskService.setAssignee(task.getId(), "kermit");
        // Error-handling should have been called, and "escalate" task should be available instead of original one
        task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).taskDefinitionKey("escalatedTask").singleResult();
        assertNotNull(task);
        // Try with a different error-code, resulting in a different task being created
        listener.setErrorCode("456");
        processInstance = runtimeService.startProcessInstanceByKey("testError");
        assertNotNull(processInstance);
        // Fetch the task and assign it. Should cause error-event to be dispatched
        task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).taskDefinitionKey("userTask").singleResult();
        assertNotNull(task);
        taskService.setAssignee(task.getId(), "kermit");
        task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).taskDefinitionKey("escalatedTask2").singleResult();
        assertNotNull(task);
    } finally {
        processEngineConfiguration.getEventDispatcher().removeEventListener(listener);
    }
}
Also used : Task(org.activiti.engine.task.Task) ErrorThrowingEventListener(org.activiti.engine.impl.bpmn.helper.ErrorThrowingEventListener) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Deployment(org.activiti.engine.test.Deployment)

Aggregations

ErrorThrowingEventListener (org.activiti.engine.impl.bpmn.helper.ErrorThrowingEventListener)3 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)2 Task (org.activiti.engine.task.Task)2 Deployment (org.activiti.engine.test.Deployment)2 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)1 BaseDelegateEventListener (org.activiti.engine.impl.bpmn.helper.BaseDelegateEventListener)1 MessageThrowingEventListener (org.activiti.engine.impl.bpmn.helper.MessageThrowingEventListener)1 SignalThrowingEventListener (org.activiti.engine.impl.bpmn.helper.SignalThrowingEventListener)1