在 Camunda-Spring Integration TaskDefinition 对于活动任务为空

On Camunda-Spring Integration TaskDefinition is null for active task

我在我们的应用程序中集成了 Camunda Engine 和 Spring。我想查找分配给 运行 流程实例的每个活动任务的属性。我可以使用以下代码获取任务实例

List<Task> tasks = this.taskService.createTaskQuery().processInstanceId("12").list() 

但是如果我将任务对象转换为 TaskEntity 然后使用 getTaskDefinition() ,我会得到 null。 获取任务详细信息的其他方法是通过 ProcessDefinitionEntity.getTaskDefinitions() 但它也 returns null.

如何获取任务详情?

对于读取属性和文档属性,请使用 BPMN Model API

此示例使用 elementId 读取两者。

String processDefinitionId = repositoryService.createProcessDefinitionQuery()
.processDefinitionKey(DEFINITON_KEY).singleResult().getId();

BpmnModelInstance bpmnModelInstance = repositoryService.getBpmnModelInstance(processDefinitionId);
ServiceTask serviceTask = (ServiceTask) bpmnModelInstance.getModelElementById(ELEMENT_ID);

// Documentation, is a collection, but the modeler supports only one attribute
Collection<Documentation> documentations = serviceTask.getDocumentations();

// Properties
Collection<Property> properties = serviceTask.getProperties();

上面的答案给了我一个提示,但没有完全解决问题,所以这是我的代码,可以达到目的。 我在 .bpmn 文件中的用户任务如下所示:

 <bpmn:userTask id="Task_063x95d" name="Tech Task">
  <bpmn:documentation>SUCCESS,FAIL</bpmn:documentation>
  <bpmn:extensionElements>
    <camunda:inputOutput>
      <camunda:inputParameter name="language">Java</camunda:inputParameter>
      <camunda:outputParameter name="Platform">Linux</camunda:outputParameter>
    </camunda:inputOutput>
    <camunda:properties>
      <camunda:property name="user" value="Test_User" />
    </camunda:properties>
  </bpmn:extensionElements>
  <bpmn:incoming>SequenceFlow_1xjoyjq</bpmn:incoming>
  <bpmn:outgoing>SequenceFlow_028pkxo</bpmn:outgoing>
</bpmn:userTask>

我已经分析了 .bpmn 文件,然后在下面的代码的帮助下渲染了它的元素

 // Active tasks for currently running instanceId(input to below code)
 List<Task> tasks = this.taskService.createTaskQuery().processInstanceId(instanceId).list();

 String documentation= null;

for (Task task : tasks)
{
//This gives [documentation][1] field.
documentation = task.getDescription();

UserTaskImpl modelElementById = (UserTaskImpl) bpmnModelInstance.getModelElementById(tasks.get(0)
    .getTaskDefinitionKey());
ExtensionElements childElementsByType2 = modelElementById.getExtensionElements();
Collection<ModelElementInstance> elements = childElementsByType2.getElements();
for (ModelElementInstance elem : elements)
{
    //To access all properties.
    if (elem instanceof CamundaPropertiesImpl)
    {
        CamundaPropertiesImpl camundaPropertiesImpl = (CamundaPropertiesImpl) elem;
        Collection<CamundaProperty> camundaProperties = camundaPropertiesImpl.getCamundaProperties();
        for (CamundaProperty test : camundaProperties)
        {
            System.out.println("camunda property name :" + test.getCamundaName() + " $ " + test.getCamundaValue());
        }

    }
    else if (elem instanceof CamundaInputOutputImpl)
    {
        // To access input/output param
        CamundaInputOutputImpl camundaInputOutputImpl = (CamundaInputOutputImpl) elem;
        for (CamundaInputParameter test : camundaInputOutputImpl.getCamundaInputParameters())
        {
            log.info("camunda input params name :" + test.getCamundaName() + " $ " + test.getTextContent());
        }
        for (CamundaOutputParameter test : camundaInputOutputImpl.getCamundaOutputParameters())
        {
            log.info("camunda output params name :" + test.getCamundaName() + " $ " + test.getTextContent());
        }
    }
 }
}