Search in sources :

Example 36 with TaskDefinition

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());
}
Also used : ExtensionElements(org.camunda.bpm.model.cmmn.instance.ExtensionElements) TaskDefinition(org.camunda.bpm.engine.impl.task.TaskDefinition) CamundaTaskListener(org.camunda.bpm.model.cmmn.instance.camunda.CamundaTaskListener) ExpressionTaskListener(org.camunda.bpm.engine.impl.task.listener.ExpressionTaskListener) DelegateExpressionTaskListener(org.camunda.bpm.engine.impl.task.listener.DelegateExpressionTaskListener) CamundaTaskListener(org.camunda.bpm.model.cmmn.instance.camunda.CamundaTaskListener) ExpressionTaskListener(org.camunda.bpm.engine.impl.task.listener.ExpressionTaskListener) ClassDelegateTaskListener(org.camunda.bpm.engine.impl.task.listener.ClassDelegateTaskListener) TaskListener(org.camunda.bpm.engine.delegate.TaskListener) DelegateExpressionTaskListener(org.camunda.bpm.engine.impl.task.listener.DelegateExpressionTaskListener) HumanTaskActivityBehavior(org.camunda.bpm.engine.impl.cmmn.behavior.HumanTaskActivityBehavior) CmmnActivity(org.camunda.bpm.engine.impl.cmmn.model.CmmnActivity) Test(org.junit.Test)

Example 37 with TaskDefinition

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 &lt;process&gt; 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;
}
Also used : TaskDefinition(org.camunda.bpm.engine.impl.task.TaskDefinition) BpmnParseException(org.camunda.bpm.engine.BpmnParseException) ProcessDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) BpmnParseException(org.camunda.bpm.engine.BpmnParseException)

Example 38 with TaskDefinition

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);
}
Also used : ExpressionManager(org.camunda.bpm.engine.impl.el.ExpressionManager) TaskDecorator(org.camunda.bpm.engine.impl.task.TaskDecorator) TaskDefinition(org.camunda.bpm.engine.impl.task.TaskDefinition) CaseDefinitionEntity(org.camunda.bpm.engine.impl.cmmn.entity.repository.CaseDefinitionEntity) HumanTaskActivityBehavior(org.camunda.bpm.engine.impl.cmmn.behavior.HumanTaskActivityBehavior)

Example 39 with 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;
}
Also used : TaskDefinition(org.camunda.bpm.engine.impl.task.TaskDefinition)

Aggregations

TaskDefinition (org.camunda.bpm.engine.impl.task.TaskDefinition)39 HumanTaskActivityBehavior (org.camunda.bpm.engine.impl.cmmn.behavior.HumanTaskActivityBehavior)24 CmmnActivity (org.camunda.bpm.engine.impl.cmmn.model.CmmnActivity)23 Test (org.junit.Test)23 Expression (org.camunda.bpm.engine.delegate.Expression)12 TaskListener (org.camunda.bpm.engine.delegate.TaskListener)12 ClassDelegateTaskListener (org.camunda.bpm.engine.impl.task.listener.ClassDelegateTaskListener)12 DelegateExpressionTaskListener (org.camunda.bpm.engine.impl.task.listener.DelegateExpressionTaskListener)12 ExpressionTaskListener (org.camunda.bpm.engine.impl.task.listener.ExpressionTaskListener)12 ExtensionElements (org.camunda.bpm.model.cmmn.instance.ExtensionElements)12 CamundaTaskListener (org.camunda.bpm.model.cmmn.instance.camunda.CamundaTaskListener)12 ConditionExpression (org.camunda.bpm.model.cmmn.instance.ConditionExpression)11 CaseDefinitionEntity (org.camunda.bpm.engine.impl.cmmn.entity.repository.CaseDefinitionEntity)4 UserTaskActivityBehavior (org.camunda.bpm.engine.impl.bpmn.behavior.UserTaskActivityBehavior)3 TaskEntity (org.camunda.bpm.engine.impl.persistence.entity.TaskEntity)3 TaskDecorator (org.camunda.bpm.engine.impl.task.TaskDecorator)3 CommandChecker (org.camunda.bpm.engine.impl.cfg.CommandChecker)2 ExpressionManager (org.camunda.bpm.engine.impl.el.ExpressionManager)2 TaskFormHandler (org.camunda.bpm.engine.impl.form.handler.TaskFormHandler)2 ProcessDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)2