use of org.camunda.bpm.engine.impl.task.TaskDefinition in project camunda-bpm-platform by camunda.
the class HumanTaskPlanItemHandlerTest method testCompleteTaskListenerByExpression.
@Test
public void testCompleteTaskListenerByExpression() {
// given:
ExtensionElements extensionElements = addExtensionElements(humanTask);
CamundaTaskListener taskListener = createElement(extensionElements, null, CamundaTaskListener.class);
String expression = "${myExpression}";
String event = TaskListener.EVENTNAME_COMPLETE;
taskListener.setCamundaEvent(event);
taskListener.setCamundaExpression(expression);
// when
CmmnActivity activity = handler.handleElement(planItem, context);
// then
assertEquals(0, activity.getListeners().size());
HumanTaskActivityBehavior behavior = (HumanTaskActivityBehavior) activity.getActivityBehavior();
TaskDefinition taskDefinition = behavior.getTaskDefinition();
assertNotNull(taskDefinition);
assertEquals(1, taskDefinition.getTaskListeners().size());
List<TaskListener> createListeners = taskDefinition.getTaskListeners(event);
assertEquals(1, createListeners.size());
TaskListener listener = createListeners.get(0);
assertTrue(listener instanceof ExpressionTaskListener);
ExpressionTaskListener expressionListener = (ExpressionTaskListener) listener;
assertEquals(expression, expressionListener.getExpressionText());
}
use of org.camunda.bpm.engine.impl.task.TaskDefinition in project camunda-bpm-platform by camunda.
the class BpmnParse method parseProcess.
/**
* Parses one process (ie anything inside a <process> element).
*
* @param processElement
* The 'process' element.
* @return The parsed version of the XML: a {@link ProcessDefinitionImpl}
* object.
*/
public ProcessDefinitionEntity parseProcess(Element processElement) {
// reset all mappings that are related to one process definition
sequenceFlows = new HashMap<String, TransitionImpl>();
ProcessDefinitionEntity processDefinition = new ProcessDefinitionEntity();
/*
* Mapping object model - bpmn xml: processDefinition.id -> generated by
* processDefinition.key -> bpmn id (required) processDefinition.name ->
* bpmn name (optional)
*/
processDefinition.setKey(processElement.attribute("id"));
processDefinition.setName(processElement.attribute("name"));
processDefinition.setCategory(rootElement.attribute("targetNamespace"));
processDefinition.setProperty(PROPERTYNAME_DOCUMENTATION, parseDocumentation(processElement));
processDefinition.setTaskDefinitions(new HashMap<String, TaskDefinition>());
processDefinition.setDeploymentId(deployment.getId());
processDefinition.setProperty(PROPERTYNAME_JOB_PRIORITY, parsePriority(processElement, PROPERTYNAME_JOB_PRIORITY));
processDefinition.setProperty(PROPERTYNAME_TASK_PRIORITY, parsePriority(processElement, PROPERTYNAME_TASK_PRIORITY));
processDefinition.setVersionTag(processElement.attributeNS(CAMUNDA_BPMN_EXTENSIONS_NS, "versionTag"));
try {
String historyTimeToLive = processElement.attributeNS(CAMUNDA_BPMN_EXTENSIONS_NS, "historyTimeToLive");
processDefinition.setHistoryTimeToLive(ParseUtil.parseHistoryTimeToLive(historyTimeToLive));
} catch (Exception e) {
addError(new BpmnParseException(e.getMessage(), processElement, e));
}
LOG.parsingElement("process", processDefinition.getKey());
parseScope(processElement, processDefinition);
// Parse any laneSets defined for this process
parseLaneSets(processElement, processDefinition);
for (BpmnParseListener parseListener : parseListeners) {
parseListener.parseProcess(processElement, processDefinition);
}
// now we have parsed anything we can validate some stuff
validateActivities(processDefinition.getActivities());
// unregister delegates
for (ActivityImpl activity : processDefinition.getActivities()) {
activity.setDelegateAsyncAfterUpdate(null);
activity.setDelegateAsyncBeforeUpdate(null);
}
return processDefinition;
}
use of org.camunda.bpm.engine.impl.task.TaskDefinition in project camunda-bpm-platform by camunda.
the class HumanTaskItemHandler method initializeActivity.
@Override
protected void initializeActivity(CmmnElement element, CmmnActivity activity, CmmnHandlerContext context) {
// execute standard initialization
super.initializeActivity(element, activity, context);
// create a taskDefinition
TaskDefinition taskDefinition = createTaskDefinition(element, context);
// get the caseDefinition...
CaseDefinitionEntity caseDefinition = (CaseDefinitionEntity) context.getCaseDefinition();
// ... and taskDefinition to caseDefinition
caseDefinition.getTaskDefinitions().put(taskDefinition.getKey(), taskDefinition);
ExpressionManager expressionManager = context.getExpressionManager();
// create decorator
TaskDecorator taskDecorator = new TaskDecorator(taskDefinition, expressionManager);
// set taskDecorator on behavior
HumanTaskActivityBehavior behavior = (HumanTaskActivityBehavior) activity.getActivityBehavior();
behavior.setTaskDecorator(taskDecorator);
// task listeners
initializeTaskListeners(element, activity, context, taskDefinition);
}
use of org.camunda.bpm.engine.impl.task.TaskDefinition in project camunda-bpm-platform by camunda.
the class BpmnParse method parseTaskDefinition.
public TaskDefinition parseTaskDefinition(Element taskElement, String taskDefinitionKey, ProcessDefinitionEntity processDefinition) {
TaskFormHandler taskFormHandler;
String taskFormHandlerClassName = taskElement.attributeNS(CAMUNDA_BPMN_EXTENSIONS_NS, "formHandlerClass");
if (taskFormHandlerClassName != null) {
taskFormHandler = (TaskFormHandler) ReflectUtil.instantiate(taskFormHandlerClassName);
} else {
taskFormHandler = new DefaultTaskFormHandler();
}
taskFormHandler.parseConfiguration(taskElement, deployment, processDefinition, this);
TaskDefinition taskDefinition = new TaskDefinition(new DelegateTaskFormHandler(taskFormHandler, deployment));
taskDefinition.setKey(taskDefinitionKey);
processDefinition.getTaskDefinitions().put(taskDefinitionKey, taskDefinition);
String formKeyAttribute = taskElement.attributeNS(CAMUNDA_BPMN_EXTENSIONS_NS, "formKey");
if (formKeyAttribute != null) {
taskDefinition.setFormKey(expressionManager.createExpression(formKeyAttribute));
}
String name = taskElement.attribute("name");
if (name != null) {
taskDefinition.setNameExpression(expressionManager.createExpression(name));
}
String descriptionStr = parseDocumentation(taskElement);
if (descriptionStr != null) {
taskDefinition.setDescriptionExpression(expressionManager.createExpression(descriptionStr));
}
parseHumanPerformer(taskElement, taskDefinition);
parsePotentialOwner(taskElement, taskDefinition);
// Activiti custom extension
parseUserTaskCustomExtensions(taskElement, taskDefinition);
return taskDefinition;
}
Aggregations