Search code examples
javabpmncamunda

On Camunda-Spring Integration TaskDefinition is null for active task


I have integrated Camunda Engine with Spring in our application. I want to find properties assigned to each active task for the running process instance. I am able to get the task instances with following code

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

but if i cast task object into TaskEntity and then use getTaskDefinition() , I get null. Other way to get task details is through ProcessDefinitionEntity.getTaskDefinitions() but it also returns null.

How should I get the task detail?


Solution

  • Above answer gave me a hint but didn't solve the problem completely so here is my code which is serving the purpose. My usertask in .bpmn file looks like:

     <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>
    

    I have analysed the .bpmn file and then just rendered its elements with help of below code

     // 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());
            }
        }
     }
    }