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);
}
}
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);
}
}
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());
}
}
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);
}
}
}
}
}
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;
}
Aggregations