activiti extension用户任务的元素读/写api

时间:2016-08-09 03:02:04

标签: activiti

我有一个工作流程,我需要在用户任务中查看一些自定义信息。所以我使用了如下的extensionElement:

         <userTask id="writeReportTask" name="Write monthly financial report" activiti:assignee="${assignee}" activiti:owner="${owner}">
            <extensionElements>
                <activiti:field name="clientName" stringValue="${clientName}" />
                <activiti:field name="companyName" stringValue="${companyName}" />
            </extensionElements>
          </userTask>

         <userTask id="financeReportTask" name="review monthly financial report" activiti:assignee="${assignee}" activiti:owner="${owner}">
            <extensionElements>
                <activiti:field name="clientName" stringValue="${clientName}" />
                <activiti:field name="companyName" stringValue="${companyName}" />
            </extensionElements>
          </userTask>

在上面的工作流程中,我将存储两个自定义属性“clientName”和“dueDate” 1.如何通过API为当前激活的任务读取/写入“clientName”和“companyName”值? 2.在上面的例子中,我存储了字符串值(stringValue =“$ {clientName}”)。有没有办法存储值列表以及如何通过API存储/检索值列表?

请帮忙

1 个答案:

答案 0 :(得分:1)

<强> 1

$ {clientName} $ {companyName} 是流程变量。您可以从当前执行中读/写:

读:

Task task = taskService.createTaskQuery().processInstanceId(String.valueOf(processInstanceId)).active().singleResult();
Map<String, Object> variablesMap = runtimeService.getVariables(task.getExecutionId());
String clientName = variablesMap.get("clientName");
String companyName = variablesMap.get("companyName");

写:

Task task = taskService.createTaskQuery().processInstanceId(String.valueOf(processInstanceId)).active().singleResult();
runtimeService.setVariable(task.getExecutionId(), "clientName", clientName);
runtimeService.setVariable(task.getExecutionId(), "companyName", companyName);

或者您可以将变量存储到您自己的数据库中并从中读取/写入。

<userTask id="writeReportTask" name="Write monthly financial report" activiti:assignee="${assignee}" activiti:owner="${owner}">
    <extensionElements>
        <activiti:taskListener event="create" delegateExpression="${myTaskListenerBean}">
            <activiti:field name="clientName" stringValue="${clientName}" />
            <activiti:field name="companyName" stringValue="${companyName}" />
        </activiti:taskListener>
    </extensionElements>
</userTask>

public class MyTaskCreateListener implements TaskListener {

    private String clientName;
    private String companyName;

    @Autowired
    private AdditionalTaskDataDao additionalTaskDataDao;

    public void notify(DelegateTask delegateTask) {
        AdditionalTaskData taskData = new AdditionalTaskData();
        taskData.setClientName(clientName);
        taskData.setCompanyName(companyName);
        taskData.setTaskId(delegateTask.getId());

        myDataDao.save(taskData);
    }
}

<强> 2

读:

Task task = taskService.createTaskQuery().processInstanceId(String.valueOf(processInstanceId)).active().singleResult();
Map<String, Object> variablesMap = runtimeService.getVariables(task.getExecutionId());

写:

Task task = taskService.createTaskQuery().processInstanceId(String.valueOf(processInstanceId)).active().singleResult();
runtimeService.setVariables(task.getExecutionId(), variablesMap);