org.activiti.engine.delegate.TaskListener Java Examples
The following examples show how to use
org.activiti.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: TaskEntity.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
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 #2
Source File: ListenerNotificationHelper.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
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); } } } } }
Example #3
Source File: ProxyUserTaskBpmnParseHandler.java From lemon with Apache License 2.0 | 6 votes |
public void parse(BpmnParse bpmnParse, BaseElement baseElement) { if (!(baseElement instanceof UserTask)) { return; } if (useDefaultUserTaskParser) { new UserTaskParseHandler().parse(bpmnParse, baseElement); } UserTask userTask = (UserTask) baseElement; logger.debug("bpmnParse : {}, userTask : {}", bpmnParse, userTask); TaskDefinition taskDefinition = (TaskDefinition) bpmnParse .getCurrentActivity().getProperty( UserTaskParseHandler.PROPERTY_TASK_DEFINITION); this.configEvent(taskDefinition, bpmnParse, TaskListener.EVENTNAME_CREATE); this.configEvent(taskDefinition, bpmnParse, TaskListener.EVENTNAME_ASSIGNMENT); this.configEvent(taskDefinition, bpmnParse, TaskListener.EVENTNAME_COMPLETE); this.configEvent(taskDefinition, bpmnParse, TaskListener.EVENTNAME_DELETE); }
Example #4
Source File: TaskDefinition.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
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 explicitally 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<TaskListener>(); taskListeners.put(eventName, taskEventListeners); } taskEventListeners.add(taskListener); } }
Example #5
Source File: DelegateExpressionTaskListener.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
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 ); } }
Example #6
Source File: ClassDelegate.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
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 #7
Source File: DelegateExpressionTaskListener.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public void notify(DelegateTask delegateTask) { Object delegate = DelegateExpressionUtil.resolveDelegateExpression(expression, delegateTask, fieldDeclarations); 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 #8
Source File: ClassDelegate.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
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 #9
Source File: CustomListenerFactory.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
@Override public TaskListener createExpressionTaskListener(ActivitiListener activitiListener) { return new TaskListener() { public void notify(DelegateTask delegateTask) { CustomListenerFactoryTest.COUNTER.addAndGet(100); } }; }
Example #10
Source File: TaskEntity.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
@SuppressWarnings("rawtypes") public void complete(Map variablesMap, boolean localScope) { if (getDelegationState() != null && getDelegationState().equals(DelegationState.PENDING)) { throw new ActivitiException("A delegated task cannot be completed, but should be resolved instead."); } fireEvent(TaskListener.EVENTNAME_COMPLETE); if (Authentication.getAuthenticatedUserId() != null && processInstanceId != null) { getProcessInstance().involveUser(Authentication.getAuthenticatedUserId(), IdentityLinkType.PARTICIPANT); } if(Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) { Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent( ActivitiEventBuilder.createEntityWithVariablesEvent(ActivitiEventType.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 #11
Source File: AbstractCompleteTaskCmd.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
protected void executeTaskComplete(CommandContext commandContext, TaskEntity taskEntity, Map<String, Object> variables, boolean localScope) { // Task complete logic if (taskEntity.getDelegationState() != null && taskEntity.getDelegationState().equals(DelegationState.PENDING)) { throw new ActivitiException("A delegated task cannot be completed, but should be resolved instead."); } commandContext.getProcessEngineConfiguration().getListenerNotificationHelper().executeTaskListeners(taskEntity, TaskListener.EVENTNAME_COMPLETE); if (Authentication.getAuthenticatedUserId() != null && taskEntity.getProcessInstanceId() != null) { ExecutionEntity processInstanceEntity = commandContext.getExecutionEntityManager().findById(taskEntity.getProcessInstanceId()); commandContext.getIdentityLinkEntityManager().involveUser(processInstanceEntity, Authentication.getAuthenticatedUserId(),IdentityLinkType.PARTICIPANT); } ActivitiEventDispatcher eventDispatcher = Context.getProcessEngineConfiguration().getEventDispatcher(); if (eventDispatcher.isEnabled()) { if (variables != null) { eventDispatcher.dispatchEvent(ActivitiEventBuilder.createEntityWithVariablesEvent(ActivitiEventType.TASK_COMPLETED, taskEntity, variables, localScope)); } else { eventDispatcher.dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.TASK_COMPLETED, taskEntity)); } } commandContext.getTaskEntityManager().deleteTask(taskEntity, null, false, false); // Continue process (if not a standalone task) if (taskEntity.getExecutionId() != null) { ExecutionEntity executionEntity = commandContext.getExecutionEntityManager().findById(taskEntity.getExecutionId()); Context.getAgenda().planTriggerExecutionOperation(executionEntity); } }
Example #12
Source File: ReplayRunTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
private ProcessEngineConfigurationImpl getProcessEngineConfiguration() { ProcessEngineConfigurationImpl configuration = new org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration(); configuration. setHistory("full"). setDatabaseSchemaUpdate("drop-create"); configuration.setCustomDefaultBpmnParseHandlers( Arrays.<BpmnParseHandler>asList( new AddListenerUserTaskParseHandler(TaskListener.EVENTNAME_CREATE, new UserTaskExecutionListener(USER_TASK_COMPLETED_EVENT_TYPE, USER_TASK_COMPLETED_EVENT_TYPE, listener.getSimulationEvents())) )); configuration.setEventListeners(Arrays.<ActivitiEventListener>asList(listener)); return configuration; }
Example #13
Source File: TaskEntityManagerImpl.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
protected void fireAssignmentEvents(TaskEntity taskEntity) { getProcessEngineConfiguration().getListenerNotificationHelper() .executeTaskListeners(taskEntity, TaskListener.EVENTNAME_ASSIGNMENT); getHistoryManager().recordTaskAssignment(taskEntity); if (getEventDispatcher().isEnabled()) { getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.TASK_ASSIGNED, taskEntity)); } }
Example #14
Source File: CustomListenerFactory.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
@Override public TaskListener createExpressionTaskListener(ActivitiListener activitiListener) { return new TaskListener() { public void notify(DelegateTask delegateTask) { CustomListenerFactoryTest.COUNTER.addAndGet(100); } }; }
Example #15
Source File: UserTaskParseHandler.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
protected TaskListener createTaskListener(BpmnParse bpmnParse, ActivitiListener 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 #16
Source File: TaskEntityManager.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
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(ActivitiEventType.ENTITY_DELETED, task)); } } }
Example #17
Source File: AlfrescoUserTaskBpmnParseHandler.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
protected List<TaskListener> getOrCreateListenerList(String eventName, UserTaskActivityBehavior userTask) { List<TaskListener> taskEventListeners = userTask.getTaskDefinition().getTaskListeners().get(eventName); if (taskEventListeners == null) { taskEventListeners = new ArrayList<TaskListener>(); userTask.getTaskDefinition().getTaskListeners().put(eventName, taskEventListeners); } return taskEventListeners; }
Example #18
Source File: AlfrescoUserTaskBpmnParseHandler.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
protected void addListeners(UserTaskActivityBehavior activityBehavior) { if (createTaskListener != null) { addTaskListenerAsFirst(createTaskListener, TaskListener.EVENTNAME_CREATE, activityBehavior); } if (completeTaskListener != null) { addTaskListenerAsFirst(completeTaskListener, TaskListener.EVENTNAME_COMPLETE, activityBehavior); } if(notificationTaskListener != null) { addTaskListenerAsLast(notificationTaskListener, TaskListener.EVENTNAME_CREATE, activityBehavior); } }
Example #19
Source File: CdiEventSupportBpmnParseHandler.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
protected void addDeleteListener(UserTask userTask) { addActivitiListenerToUserTask(userTask, TaskListener.EVENTNAME_DELETE, new CdiTaskListener(userTask.getId(), BusinessProcessEventType.DELETE_TASK)); }
Example #20
Source File: CompleteTaskWithCommentCmd.java From lemon with Apache License 2.0 | 4 votes |
public Object execute(CommandContext commandContext) { TaskEntity taskEntity = commandContext.getTaskEntityManager() .findTaskById(taskId); if (variables != null) { taskEntity.setExecutionVariables(variables); } boolean localScope = false; if ((taskEntity.getDelegationState() != null) && taskEntity.getDelegationState().equals( DelegationState.PENDING)) { throw new ActivitiException( "A delegated task cannot be completed, but should be resolved instead."); } taskEntity.fireEvent(TaskListener.EVENTNAME_COMPLETE); if ((Authentication.getAuthenticatedUserId() != null) && (taskEntity.getProcessInstanceId() != null)) { taskEntity.getProcessInstance().involveUser( Authentication.getAuthenticatedUserId(), IdentityLinkType.PARTICIPANT); } if (Context.getProcessEngineConfiguration().getEventDispatcher() .isEnabled()) { Context.getProcessEngineConfiguration() .getEventDispatcher() .dispatchEvent( ActivitiEventBuilder .createEntityWithVariablesEvent( ActivitiEventType.TASK_COMPLETED, taskEntity, variables, localScope)); } Context.getCommandContext().getTaskEntityManager() .deleteTask(taskEntity, comment, false); if (taskEntity.getExecutionId() != null) { ExecutionEntity execution = taskEntity.getExecution(); execution.removeTask(taskEntity); try { Context.setExecutionContext(execution); execution.signal(null, null); } finally { Context.removeExecutionContext(); } } return null; }
Example #21
Source File: ProxyTaskListener.java From lemon with Apache License 2.0 | 4 votes |
public void setTaskListeners(List<TaskListener> taskListeners) { this.taskListeners = taskListeners; }
Example #22
Source File: ProxyTaskListener.java From lemon with Apache License 2.0 | 4 votes |
public void notify(DelegateTask delegateTask) { for (TaskListener taskListener : taskListeners) { taskListener.notify(delegateTask); } }
Example #23
Source File: CdiEventSupportBpmnParseHandler.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
private void addCompleteListener(UserTask userTask) { addActivitiListenerToUserTask(userTask, TaskListener.EVENTNAME_COMPLETE, new CdiTaskListener(userTask.getId(), BusinessProcessEventType.COMPLETE_TASK)); }
Example #24
Source File: CdiEventSupportBpmnParseHandler.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
private void addAssignListener(UserTask userTask) { addActivitiListenerToUserTask(userTask, TaskListener.EVENTNAME_ASSIGNMENT, new CdiTaskListener(userTask.getId(), BusinessProcessEventType.ASSIGN_TASK)); }
Example #25
Source File: CdiEventSupportBpmnParseHandler.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
private void addCreateListener(UserTask userTask) { addActivitiListenerToUserTask(userTask, TaskListener.EVENTNAME_CREATE, new CdiTaskListener(userTask.getId(), BusinessProcessEventType.CREATE_TASK)); }
Example #26
Source File: AlfrescoUserTaskBpmnParseHandler.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
protected void addTaskListenerAsLast(TaskListener taskListener, String eventName, UserTaskActivityBehavior userTask) { getOrCreateListenerList(eventName, userTask).add(taskListener); }
Example #27
Source File: AddListenerUserTaskParseHandler.java From activiti6-boot2 with Apache License 2.0 | 4 votes |
public AddListenerUserTaskParseHandler(String eventName, TaskListener taskListener) { this.eventName = eventName; this.taskListener = taskListener; }
Example #28
Source File: AlfrescoUserTaskBpmnParseHandler.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
protected void addTaskListenerAsFirst(TaskListener taskListener, String eventName, UserTaskActivityBehavior userTask) { getOrCreateListenerList(eventName, userTask).add(0, taskListener); }
Example #29
Source File: AlfrescoUserTaskBpmnParseHandler.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
public void setNotificationTaskListener(TaskListener notificationTaskListener) { this.notificationTaskListener = notificationTaskListener; }
Example #30
Source File: AlfrescoUserTaskBpmnParseHandler.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
public void setCreateTaskListener(TaskListener createTaskListener) { this.createTaskListener = createTaskListener; }