Search in sources :

Example 1 with TaskListener

use of org.activiti.engine.delegate.TaskListener in project Activiti by Activiti.

the class DelegateExpressionTaskListener method notify.

public void notify(DelegateTask delegateTask) {
    // Note: we can't cache the result of the expression, because the
    // execution can change: eg. delegateExpression='${mySpringBeanFactory.randomSpringBean()}'
    Object delegate = expression.getValue(delegateTask.getExecution());
    ClassDelegate.applyFieldDeclaration(fieldDeclarations, delegate);
    if (delegate instanceof TaskListener) {
        try {
            Context.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(new TaskListenerInvocation((TaskListener) delegate, delegateTask));
        } catch (Exception e) {
            throw new ActivitiException("Exception while invoking TaskListener: " + e.getMessage(), e);
        }
    } else {
        throw new ActivitiIllegalArgumentException("Delegate expression " + expression + " did not resolve to an implementation of " + TaskListener.class);
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) TaskListenerInvocation(org.activiti.engine.impl.delegate.TaskListenerInvocation) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) TaskListener(org.activiti.engine.delegate.TaskListener) ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException)

Example 2 with TaskListener

use of org.activiti.engine.delegate.TaskListener in project carbon-business-process by wso2.

the class AnalyticsConfigurationService method configureTaskLevelEvents.

@PUT
@Path("/processes/{process_id}/tasks/{task_id}")
@Consumes({ MediaType.APPLICATION_JSON })
public void configureTaskLevelEvents(@PathParam("process_id") String processDefinitionId, @PathParam("task_id") String taskId, DataPublisherConfig dataPublisherConfig) {
    try {
        RepositoryService repositoryService = BPMNOSGIService.getRepositoryService();
        ProcessDefinition process = repositoryService.getProcessDefinition(processDefinitionId);
        if (process != null && process instanceof ProcessDefinitionEntity) {
            ProcessDefinitionEntity processDefinitionEntity = (ProcessDefinitionEntity) process;
            Map<String, TaskDefinition> taskDefinitions = processDefinitionEntity.getTaskDefinitions();
            TaskDefinition taskDefinition = taskDefinitions.get(taskId);
            if (taskDefinition != null) {
                if (dataPublisherConfig.isEnabled()) {
                    List<TaskListener> completionListeners = taskDefinition.getTaskListener(TaskListener.EVENTNAME_COMPLETE);
                    TaskListener taskCompletionListener = null;
                    for (TaskListener listener : completionListeners) {
                        if (listener instanceof TaskCompletionListener) {
                            taskCompletionListener = listener;
                            break;
                        }
                    }
                    if (taskCompletionListener == null) {
                        if (log.isDebugEnabled()) {
                            log.debug("Adding task completion listener to task: " + taskId + " of process: " + processDefinitionId);
                        }
                        taskDefinition.addTaskListener(TaskListener.EVENTNAME_COMPLETE, new TaskCompletionListener());
                    }
                } else {
                    List<TaskListener> completionListeners = taskDefinition.getTaskListener(TaskListener.EVENTNAME_COMPLETE);
                    TaskListener taskCompletionListener = null;
                    for (TaskListener listener : completionListeners) {
                        if (listener instanceof TaskCompletionListener) {
                            taskCompletionListener = listener;
                            break;
                        }
                    }
                    if (taskCompletionListener != null) {
                        if (log.isDebugEnabled()) {
                            log.debug("Removing task completion listener from task: " + taskId + " of process: " + processDefinitionId);
                        }
                        completionListeners.remove(taskCompletionListener);
                    }
                }
            }
        }
    } catch (Exception e) {
        String msg = "Failed to configure events for task: " + taskId + " of process: " + processDefinitionId;
        log.error(msg, e);
        throw new BPMNRestException(msg, e);
    }
}
Also used : TaskCompletionListener(org.wso2.carbon.bpmn.analytics.publisher.listeners.TaskCompletionListener) TaskDefinition(org.activiti.engine.impl.task.TaskDefinition) TaskListener(org.activiti.engine.delegate.TaskListener) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) BPMNRestException(org.wso2.carbon.bpmn.rest.common.exception.BPMNRestException) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) BPMNRestException(org.wso2.carbon.bpmn.rest.common.exception.BPMNRestException) RepositoryService(org.activiti.engine.RepositoryService)

Example 3 with TaskListener

use of org.activiti.engine.delegate.TaskListener in project carbon-business-process by wso2.

the class TaskParseHandler method executeParse.

@Override
protected void executeParse(BpmnParse bpmnParse, BaseElement element) {
    TaskDefinition taskDefinition = (TaskDefinition) bpmnParse.getCurrentActivity().getProperty(UserTaskParseHandler.PROPERTY_TASK_DEFINITION);
    // We have to check if data publishing listener has already been associated at server startup
    TaskListener taskCompletionListener = null;
    List<TaskListener> completionListeners = taskDefinition.getTaskListener(TaskListener.EVENTNAME_COMPLETE);
    if (completionListeners != null) {
        for (TaskListener listener : completionListeners) {
            if (listener instanceof TaskCompletionListener) {
                taskCompletionListener = listener;
                break;
            }
        }
    }
    if (taskCompletionListener == null) {
        if (log.isDebugEnabled()) {
            log.debug("Adding data publishing listener to task: " + taskDefinition.getKey());
        }
        taskDefinition.addTaskListener(TaskListener.EVENTNAME_COMPLETE, new TaskCompletionListener());
    }
}
Also used : TaskCompletionListener(org.wso2.carbon.bpmn.analytics.publisher.listeners.TaskCompletionListener) TaskDefinition(org.activiti.engine.impl.task.TaskDefinition) TaskListener(org.activiti.engine.delegate.TaskListener)

Example 4 with TaskListener

use of org.activiti.engine.delegate.TaskListener in project Activiti by Activiti.

the class ListenerNotificationHelper method executeTaskListeners.

public void executeTaskListeners(UserTask userTask, TaskEntity taskEntity, String eventType) {
    for (ActivitiListener activitiListener : userTask.getTaskListeners()) {
        String event = activitiListener.getEvent();
        if (event.equals(eventType) || event.equals(TaskListener.EVENTNAME_ALL_EVENTS)) {
            BaseTaskListener taskListener = createTaskListener(activitiListener);
            if (activitiListener.getOnTransaction() != null) {
                planTransactionDependentTaskListener(taskEntity.getExecution(), (TransactionDependentTaskListener) taskListener, activitiListener);
            } else {
                taskEntity.setEventName(eventType);
                taskEntity.setCurrentActivitiListener(activitiListener);
                try {
                    Context.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(new TaskListenerInvocation((TaskListener) taskListener, taskEntity));
                } catch (Exception e) {
                    throw new ActivitiException("Exception while invoking TaskListener: " + e.getMessage(), e);
                } finally {
                    taskEntity.setEventName(null);
                    taskEntity.setCurrentActivitiListener(null);
                }
            }
        }
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) TaskListenerInvocation(org.activiti.engine.impl.delegate.invocation.TaskListenerInvocation) BaseTaskListener(org.activiti.engine.delegate.BaseTaskListener) BaseTaskListener(org.activiti.engine.delegate.BaseTaskListener) TaskListener(org.activiti.engine.delegate.TaskListener) TransactionDependentTaskListener(org.activiti.engine.delegate.TransactionDependentTaskListener) ActivitiListener(org.activiti.bpmn.model.ActivitiListener) ActivitiException(org.activiti.engine.ActivitiException)

Example 5 with TaskListener

use of org.activiti.engine.delegate.TaskListener in project Activiti by Activiti.

the class ListenerNotificationHelper method createTaskListener.

protected BaseTaskListener createTaskListener(ActivitiListener activitiListener) {
    BaseTaskListener taskListener = null;
    ListenerFactory listenerFactory = Context.getProcessEngineConfiguration().getListenerFactory();
    if (ImplementationType.IMPLEMENTATION_TYPE_CLASS.equalsIgnoreCase(activitiListener.getImplementationType())) {
        taskListener = listenerFactory.createClassDelegateTaskListener(activitiListener);
    } else if (ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION.equalsIgnoreCase(activitiListener.getImplementationType())) {
        taskListener = listenerFactory.createExpressionTaskListener(activitiListener);
    } else if (ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION.equalsIgnoreCase(activitiListener.getImplementationType())) {
        if (activitiListener.getOnTransaction() != null) {
            taskListener = listenerFactory.createTransactionDependentDelegateExpressionTaskListener(activitiListener);
        } else {
            taskListener = listenerFactory.createDelegateExpressionTaskListener(activitiListener);
        }
    } else if (ImplementationType.IMPLEMENTATION_TYPE_INSTANCE.equalsIgnoreCase(activitiListener.getImplementationType())) {
        taskListener = (TaskListener) activitiListener.getInstance();
    }
    return taskListener;
}
Also used : BaseTaskListener(org.activiti.engine.delegate.BaseTaskListener) BaseTaskListener(org.activiti.engine.delegate.BaseTaskListener) TaskListener(org.activiti.engine.delegate.TaskListener) TransactionDependentTaskListener(org.activiti.engine.delegate.TransactionDependentTaskListener) ListenerFactory(org.activiti.engine.impl.bpmn.parser.factory.ListenerFactory)

Aggregations

TaskListener (org.activiti.engine.delegate.TaskListener)5 ActivitiException (org.activiti.engine.ActivitiException)2 BaseTaskListener (org.activiti.engine.delegate.BaseTaskListener)2 TransactionDependentTaskListener (org.activiti.engine.delegate.TransactionDependentTaskListener)2 TaskDefinition (org.activiti.engine.impl.task.TaskDefinition)2 TaskCompletionListener (org.wso2.carbon.bpmn.analytics.publisher.listeners.TaskCompletionListener)2 ActivitiListener (org.activiti.bpmn.model.ActivitiListener)1 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)1 RepositoryService (org.activiti.engine.RepositoryService)1 ListenerFactory (org.activiti.engine.impl.bpmn.parser.factory.ListenerFactory)1 TaskListenerInvocation (org.activiti.engine.impl.delegate.TaskListenerInvocation)1 TaskListenerInvocation (org.activiti.engine.impl.delegate.invocation.TaskListenerInvocation)1 ProcessDefinitionEntity (org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity)1 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)1 BPMNRestException (org.wso2.carbon.bpmn.rest.common.exception.BPMNRestException)1