2017-03-09 4 views
1

CamundaエンジンとSpringをアプリケーションに統合しました。実行中のプロセスインスタンスに対して、それぞれのアクティブなタスクに割り当てられたプロパティーを探したい。私は、次のコードCamunda-Springの統合についてTaskDefinitionがアクティブなタスクのためにヌルです

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

でタスクインスタンスを取得することができるが、私はTaskEntityにタスクオブジェクトをキャストしてgetTaskDefinition()を使用している場合、私はnullを取得します。 タスクの詳細を取得するその他の方法はProcessDefinitionEntity.getTaskDefinitions()ですが、nullも返します。

タスクの詳細はどのように取得する必要がありますか?

+1

あなたの目標は何であるの助けを借りて、その要素をレンダリング? – jklee

+0

@jklee ワークフローのモデリング中(.bpmnファイル内)、各タスクにいくつかのプロパティを追加しました。これらのプロパティと、現在アクティブなタスクのドキュメント属性にもアクセスしたいと思います。 – Tejas

答えて

1

上記の回答は私にヒントをもたらしましたが、問題を完全には解決しなかったので、目的に役立つコードがここにあります。 .bpmnファイル内のマイusertaskは、次のようになります。

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

読み取りプロパティとドキュメントの属性には、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(); 
関連する問題