org.flowable.engine.delegate.TaskListener Java Examples

The following examples show how to use org.flowable.engine.delegate.TaskListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DelegateExpressionTaskListener.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
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);
    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);
    }
}
 
Example #2
Source File: TaskDefinition.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public void addTaskListener(String eventName, TaskListener taskListener) {
    if (TaskListener.EVENTNAME_ALL_EVENTS.equals(eventName)) {
        // In order to prevent having to merge the "all" tasklisteners with the ones for a specific eventName,
        // every time "getTaskListener()" is called, we add the listener explicitly to the individual lists
        this.addTaskListener(TaskListener.EVENTNAME_CREATE, taskListener);
        this.addTaskListener(TaskListener.EVENTNAME_ASSIGNMENT, taskListener);
        this.addTaskListener(TaskListener.EVENTNAME_COMPLETE, taskListener);
        this.addTaskListener(TaskListener.EVENTNAME_DELETE, taskListener);

    } else {
        List<TaskListener> taskEventListeners = taskListeners.get(eventName);
        if (taskEventListeners == null) {
            taskEventListeners = new ArrayList<>();
            taskListeners.put(eventName, taskEventListeners);
        }
        taskEventListeners.add(taskListener);
    }
}
 
Example #3
Source File: TaskEntity.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public void fireEvent(String taskEventName) {
    TaskDefinition taskDefinition = getTaskDefinition();
    if (taskDefinition != null) {
        List<TaskListener> taskEventListeners = getTaskDefinition().getTaskListener(taskEventName);
        if (taskEventListeners != null) {
            for (TaskListener taskListener : taskEventListeners) {
                ExecutionEntity execution = getExecution();
                if (execution != null) {
                    setEventName(taskEventName);
                }
                try {
                    Context.getProcessEngineConfiguration()
                            .getDelegateInterceptor()
                            .handleInvocation(new TaskListenerInvocation(taskListener, (DelegateTask) this));
                } catch (Exception e) {
                    throw new ActivitiException("Exception while invoking TaskListener: " + e.getMessage(), e);
                }
            }
        }
    }
}
 
Example #4
Source File: ReplayRunTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
private ProcessEngineConfigurationImpl getProcessEngineConfiguration() {
    ProcessEngineConfigurationImpl configuration = new org.flowable.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration();
    configuration.setHistory("full").setDatabaseSchemaUpdate("true");
    configuration.setCustomDefaultBpmnParseHandlers(
            Collections.<BpmnParseHandler>singletonList(
                    new AddListenerUserTaskParseHandler(TaskListener.EVENTNAME_CREATE,
                            new UserTaskExecutionListener(USER_TASK_COMPLETED_EVENT_TYPE, USER_TASK_COMPLETED_EVENT_TYPE, listener.getSimulationEvents()))));
    configuration.setEventListeners(Collections.<FlowableEventListener>singletonList(listener));
    return configuration;
}
 
Example #5
Source File: ClassDelegate.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected TaskListener getTaskListenerInstance() {
    Object delegateInstance = instantiateDelegate(className, fieldDeclarations);
    if (delegateInstance instanceof TaskListener) {
        return (TaskListener) delegateInstance;
    } else {
        throw new ActivitiIllegalArgumentException(delegateInstance.getClass().getName() + " doesn't implement " + TaskListener.class);
    }
}
 
Example #6
Source File: UserTaskParseHandler.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected TaskListener createTaskListener(BpmnParse bpmnParse, FlowableListener activitiListener, String taskId) {
    TaskListener taskListener = null;

    if (ImplementationType.IMPLEMENTATION_TYPE_CLASS.equalsIgnoreCase(activitiListener.getImplementationType())) {
        taskListener = bpmnParse.getListenerFactory().createClassDelegateTaskListener(activitiListener);
    } else if (ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION.equalsIgnoreCase(activitiListener.getImplementationType())) {
        taskListener = bpmnParse.getListenerFactory().createExpressionTaskListener(activitiListener);
    } else if (ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION.equalsIgnoreCase(activitiListener.getImplementationType())) {
        taskListener = bpmnParse.getListenerFactory().createDelegateExpressionTaskListener(activitiListener);
    }
    return taskListener;
}
 
Example #7
Source File: TaskEntityManager.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public void deleteTask(TaskEntity task, String deleteReason, boolean cascade) {
    if (!task.isDeleted()) {
        task.fireEvent(TaskListener.EVENTNAME_DELETE);
        task.setDeleted(true);

        CommandContext commandContext = Context.getCommandContext();
        String taskId = task.getId();

        List<Task> subTasks = findTasksByParentTaskId(taskId);
        for (Task subTask : subTasks) {
            deleteTask((TaskEntity) subTask, deleteReason, cascade);
        }

        commandContext
                .getIdentityLinkEntityManager()
                .deleteIdentityLinksByTaskId(taskId);

        commandContext
                .getVariableInstanceEntityManager()
                .deleteVariableInstanceByTask(task);

        if (cascade) {
            commandContext
                    .getHistoricTaskInstanceEntityManager()
                    .deleteHistoricTaskInstanceById(taskId);
        } else {
            commandContext
                    .getHistoryManager()
                    .recordTaskEnd(taskId, deleteReason);
        }

        getDbSqlSession().delete(task);

        if (commandContext.getEventDispatcher().isEnabled()) {
            commandContext.getEventDispatcher().dispatchEvent(
                    ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.ENTITY_DELETED, task));
        }
    }
}
 
Example #8
Source File: CustomListenerFactory.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public TaskListener createExpressionTaskListener(FlowableListener activitiListener) {
    return new TaskListener() {
        @Override
        public void notify(DelegateTask delegateTask) {
            CustomListenerFactoryTest.COUNTER.addAndGet(100);
        }
    };
}
 
Example #9
Source File: SaveTaskCmd.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected void handleAssigneeChange(CommandContext commandContext,
        ProcessEngineConfigurationImpl processEngineConfiguration) {
    processEngineConfiguration.getListenerNotificationHelper().executeTaskListeners(task, TaskListener.EVENTNAME_ASSIGNMENT);

    FlowableEventDispatcher eventDispatcher = CommandContextUtil.getEventDispatcher(commandContext);
    if (eventDispatcher != null && eventDispatcher.isEnabled()) {
        CommandContextUtil.getEventDispatcher().dispatchEvent(FlowableTaskEventBuilder.createEntityEvent(FlowableEngineEventType.TASK_ASSIGNED, task));
    }
}
 
Example #10
Source File: TaskHelper.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected static void fireAssignmentEvents(TaskEntity taskEntity) {
    CommandContextUtil.getProcessEngineConfiguration().getListenerNotificationHelper().executeTaskListeners(taskEntity, TaskListener.EVENTNAME_ASSIGNMENT);

    FlowableEventDispatcher eventDispatcher = CommandContextUtil.getEventDispatcher();
    if (eventDispatcher != null && eventDispatcher.isEnabled()) {
        eventDispatcher.dispatchEvent(
                FlowableEventBuilder.createEntityEvent(FlowableEngineEventType.TASK_ASSIGNED, taskEntity));
    }
}
 
Example #11
Source File: CustomListenerFactory.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public TaskListener createExpressionTaskListener(FlowableListener activitiListener) {
    return new TaskListener() {
        public void notify(DelegateTask delegateTask) {
            CustomListenerFactoryTest.COUNTER.addAndGet(100);
        }
    };
}
 
Example #12
Source File: TaskEntity.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
public void complete(Map variablesMap, boolean localScope, boolean fireEvents) {

    if (getDelegationState() != null && getDelegationState() == DelegationState.PENDING) {
        throw new ActivitiException("A delegated task cannot be completed, but should be resolved instead.");
    }

    if (fireEvents) {
        fireEvent(TaskListener.EVENTNAME_COMPLETE);
    }

    if (Authentication.getAuthenticatedUserId() != null && processInstanceId != null) {
        getProcessInstance().involveUser(Authentication.getAuthenticatedUserId(), IdentityLinkType.PARTICIPANT);
    }

    if (Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled() && fireEvents) {
        Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
                ActivitiEventBuilder.createEntityWithVariablesEvent(FlowableEngineEventType.TASK_COMPLETED, this, variablesMap, localScope));
    }

    Context
            .getCommandContext()
            .getTaskEntityManager()
            .deleteTask(this, TaskEntity.DELETE_REASON_COMPLETED, false);

    if (executionId != null) {
        ExecutionEntity execution = getExecution();
        execution.removeTask(this);
        execution.signal(null, null);
    }
}
 
Example #13
Source File: TaskHelper.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected static void internalDeleteTask(TaskEntity task, String deleteReason, 
        boolean cascade, boolean executeTaskDelete, boolean fireTaskListener, boolean fireEvents) {
    
    if (!task.isDeleted()) {
        
        CommandContext commandContext = CommandContextUtil.getCommandContext();
        FlowableEventDispatcher eventDispatcher = CommandContextUtil.getEventDispatcher(commandContext);
        fireEvents = fireEvents && eventDispatcher != null && eventDispatcher.isEnabled();

        if (fireTaskListener) {
            CommandContextUtil.getProcessEngineConfiguration(commandContext).getListenerNotificationHelper()
                    .executeTaskListeners(task, TaskListener.EVENTNAME_DELETE);
        }

        task.setDeleted(true);

        handleRelatedEntities(commandContext, task, deleteReason, cascade, fireTaskListener, fireEvents, eventDispatcher);
        handleTaskHistory(commandContext, task, deleteReason, cascade);

        if (executeTaskDelete) {
            executeTaskDelete(task, commandContext);
        }

        if (fireEvents) {
            fireTaskDeletedEvent(task, commandContext, eventDispatcher);
        }

    }
}
 
Example #14
Source File: DefaultListenerFactory.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public TaskListener createDelegateExpressionTaskListener(FlowableListener activitiListener) {
    return new DelegateExpressionTaskListener(expressionManager.createExpression(activitiListener.getImplementation()),
            createFieldDeclarations(activitiListener.getFieldExtensions()));
}
 
Example #15
Source File: CdiEventSupportBpmnParseHandler.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
protected void addDeleteListener(UserTask userTask) {
    addListenerToUserTask(userTask, TaskListener.EVENTNAME_DELETE, new CdiTaskListener(userTask.getId(), BusinessProcessEventType.DELETE_TASK));
}
 
Example #16
Source File: CdiEventSupportBpmnParseHandler.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
private void addCreateListener(UserTask userTask) {
    addListenerToUserTask(userTask, TaskListener.EVENTNAME_CREATE, new CdiTaskListener(userTask.getId(), BusinessProcessEventType.CREATE_TASK));
}
 
Example #17
Source File: CdiEventSupportBpmnParseHandler.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
private void addAssignListener(UserTask userTask) {
    addListenerToUserTask(userTask, TaskListener.EVENTNAME_ASSIGNMENT, new CdiTaskListener(userTask.getId(), BusinessProcessEventType.ASSIGN_TASK));
}
 
Example #18
Source File: CdiEventSupportBpmnParseHandler.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
private void addCompleteListener(UserTask userTask) {
    addListenerToUserTask(userTask, TaskListener.EVENTNAME_COMPLETE, new CdiTaskListener(userTask.getId(), BusinessProcessEventType.COMPLETE_TASK));
}
 
Example #19
Source File: UserTaskHistoryParseHandler.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
protected void executeParse(BpmnParse bpmnParse, UserTask element) {
    TaskDefinition taskDefinition = (TaskDefinition) bpmnParse.getCurrentActivity().getProperty(UserTaskParseHandler.PROPERTY_TASK_DEFINITION);
    taskDefinition.addTaskListener(TaskListener.EVENTNAME_ASSIGNMENT, USER_TASK_ASSIGNMENT_HANDLER);
    taskDefinition.addTaskListener(TaskListener.EVENTNAME_CREATE, USER_TASK_ID_HANDLER);
}
 
Example #20
Source File: AddListenerUserTaskParseHandler.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public AddListenerUserTaskParseHandler(String eventName, TaskListener taskListener) {
    this.eventName = eventName;
    this.taskListener = taskListener;
}
 
Example #21
Source File: DefaultListenerFactory.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public TaskListener createExpressionTaskListener(FlowableListener activitiListener) {
    return new ExpressionTaskListener(expressionManager.createExpression(activitiListener.getImplementation()));
}
 
Example #22
Source File: DefaultListenerFactory.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Override
public TaskListener createClassDelegateTaskListener(FlowableListener activitiListener) {
    return new ClassDelegate(activitiListener.getImplementation(), createFieldDeclarations(activitiListener.getFieldExtensions()));
}
 
Example #23
Source File: TaskDefinition.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public List<TaskListener> getTaskListener(String eventName) {
    return taskListeners.get(eventName);
}
 
Example #24
Source File: TaskDefinition.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public void setTaskListeners(Map<String, List<TaskListener>> taskListeners) {
    this.taskListeners = taskListeners;
}
 
Example #25
Source File: TaskDefinition.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public Map<String, List<TaskListener>> getTaskListeners() {
    return taskListeners;
}
 
Example #26
Source File: TaskListenerInvocation.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public TaskListenerInvocation(TaskListener executionListenerInstance, DelegateTask delegateTask) {
    this.executionListenerInstance = executionListenerInstance;
    this.delegateTask = delegateTask;
}
 
Example #27
Source File: TaskEntity.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public void setAssignee(String assignee, boolean dispatchAssignmentEvent, boolean dispatchUpdateEvent) {
    CommandContext commandContext = Context.getCommandContext();

    if (assignee == null && this.assignee == null) {

        // ACT-1923: even if assignee is unmodified and null, this should be stored in history.
        if (commandContext != null) {
            commandContext
                    .getHistoryManager()
                    .recordTaskAssigneeChange(id, assignee);
        }

        return;
    }
    this.assignee = assignee;

    // if there is no command context, then it means that the user is calling the
    // setAssignee outside a service method. E.g. while creating a new task.
    if (commandContext != null) {
        commandContext
                .getHistoryManager()
                .recordTaskAssigneeChange(id, assignee);

        if (assignee != null && processInstanceId != null) {
            getProcessInstance().involveUser(assignee, IdentityLinkType.PARTICIPANT);
        }

        if (!StringUtils.equals(initialAssignee, assignee)) {
            fireEvent(TaskListener.EVENTNAME_ASSIGNMENT);
            initialAssignee = assignee;
        }

        if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
            if (dispatchAssignmentEvent) {
                commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
                        ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.TASK_ASSIGNED, this));
            }

            if (dispatchUpdateEvent) {
                commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(
                        ActivitiEventBuilder.createEntityEvent(FlowableEngineEventType.ENTITY_UPDATED, this));
            }
        }
    }
}
 
Example #28
Source File: ListenerFactory.java    From flowable-engine with Apache License 2.0 votes vote down vote up
public abstract TaskListener createExpressionTaskListener(FlowableListener activitiListener); 
Example #29
Source File: ListenerFactory.java    From flowable-engine with Apache License 2.0 votes vote down vote up
public abstract TaskListener createDelegateExpressionTaskListener(FlowableListener activitiListener); 
Example #30
Source File: ListenerFactory.java    From flowable-engine with Apache License 2.0 votes vote down vote up
public abstract TaskListener createClassDelegateTaskListener(FlowableListener activitiListener);