use of org.camunda.bpm.engine.delegate.TaskListener in project camunda-bpm-platform by camunda.
the class BpmnParse method parseTaskListeners.
protected void parseTaskListeners(Element userTaskElement, TaskDefinition taskDefinition) {
Element extentionsElement = userTaskElement.element("extensionElements");
if (extentionsElement != null) {
List<Element> taskListenerElements = extentionsElement.elementsNS(CAMUNDA_BPMN_EXTENSIONS_NS, "taskListener");
for (Element taskListenerElement : taskListenerElements) {
String eventName = taskListenerElement.attribute("event");
if (eventName != null) {
if (TaskListener.EVENTNAME_CREATE.equals(eventName) || TaskListener.EVENTNAME_ASSIGNMENT.equals(eventName) || TaskListener.EVENTNAME_COMPLETE.equals(eventName) || TaskListener.EVENTNAME_DELETE.equals(eventName)) {
TaskListener taskListener = parseTaskListener(taskListenerElement);
taskDefinition.addTaskListener(eventName, taskListener);
} else {
addError("Attribute 'event' must be one of {create|assignment|complete|delete}", userTaskElement);
}
} else {
addError("Attribute 'event' is mandatory on taskListener", userTaskElement);
}
}
}
}
use of org.camunda.bpm.engine.delegate.TaskListener in project camunda-bpm-platform by camunda.
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()}'
VariableScope variableScope = delegateTask.getExecution();
if (variableScope == null) {
variableScope = delegateTask.getCaseExecution();
}
Object delegate = expression.getValue(variableScope);
applyFieldDeclaration(fieldDeclarations, delegate);
if (delegate instanceof TaskListener) {
try {
Context.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(new TaskListenerInvocation((TaskListener) delegate, delegateTask));
} catch (Exception e) {
throw new ProcessEngineException("Exception while invoking TaskListener: " + e.getMessage(), e);
}
} else {
throw new ProcessEngineException("Delegate expression " + expression + " did not resolve to an implementation of " + TaskListener.class);
}
}
use of org.camunda.bpm.engine.delegate.TaskListener in project camunda-bpm-platform by camunda.
the class HumanTaskItemHandler method initializeTaskListener.
protected TaskListener initializeTaskListener(CmmnElement element, CmmnActivity activity, CmmnHandlerContext context, CamundaTaskListener listener) {
Collection<CamundaField> fields = listener.getCamundaFields();
List<FieldDeclaration> fieldDeclarations = initializeFieldDeclarations(element, activity, context, fields);
ExpressionManager expressionManager = context.getExpressionManager();
TaskListener taskListener = null;
String className = listener.getCamundaClass();
String expression = listener.getCamundaExpression();
String delegateExpression = listener.getCamundaDelegateExpression();
CamundaScript scriptElement = listener.getCamundaScript();
if (className != null) {
taskListener = new ClassDelegateTaskListener(className, fieldDeclarations);
} else if (expression != null) {
Expression expressionExp = expressionManager.createExpression(expression);
taskListener = new ExpressionTaskListener(expressionExp);
} else if (delegateExpression != null) {
Expression delegateExp = expressionManager.createExpression(delegateExpression);
taskListener = new DelegateExpressionTaskListener(delegateExp, fieldDeclarations);
} else if (scriptElement != null) {
ExecutableScript executableScript = initializeScript(element, activity, context, scriptElement);
if (executableScript != null) {
taskListener = new ScriptTaskListener(executableScript);
}
}
return taskListener;
}
use of org.camunda.bpm.engine.delegate.TaskListener in project camunda-bpm-platform by camunda.
the class HumanTaskItemHandler method initializeTaskListeners.
protected void initializeTaskListeners(CmmnElement element, CmmnActivity activity, CmmnHandlerContext context, TaskDefinition taskDefinition) {
HumanTask humanTask = getDefinition(element);
List<CamundaTaskListener> listeners = queryExtensionElementsByClass(humanTask, CamundaTaskListener.class);
for (CamundaTaskListener listener : listeners) {
TaskListener taskListener = initializeTaskListener(element, activity, context, listener);
String eventName = listener.getCamundaEvent();
if (eventName != null) {
taskDefinition.addTaskListener(eventName, taskListener);
} else {
taskDefinition.addTaskListener(TaskListener.EVENTNAME_CREATE, taskListener);
taskDefinition.addTaskListener(TaskListener.EVENTNAME_ASSIGNMENT, taskListener);
taskDefinition.addTaskListener(TaskListener.EVENTNAME_COMPLETE, taskListener);
taskDefinition.addTaskListener(TaskListener.EVENTNAME_DELETE, taskListener);
}
}
}
use of org.camunda.bpm.engine.delegate.TaskListener in project camunda-bpm-platform by camunda.
the class TaskEntity method fireEvent.
public void fireEvent(String taskEventName) {
List<TaskListener> taskEventListeners = getListenersForEvent(taskEventName);
if (taskEventListeners != null) {
for (TaskListener taskListener : taskEventListeners) {
CoreExecution execution = getExecution();
if (execution == null) {
execution = getCaseExecution();
}
if (execution != null) {
setEventName(taskEventName);
}
try {
TaskListenerInvocation listenerInvocation = new TaskListenerInvocation(taskListener, this, execution);
Context.getProcessEngineConfiguration().getDelegateInterceptor().handleInvocation(listenerInvocation);
} catch (Exception e) {
throw LOG.invokeTaskListenerException(e);
}
}
}
}
Aggregations