我是 camunda 和 java 的新手。我的要求是,我想通过 java 从每个任务、事件、网关…等的所有节点获取所有属性 value 并在单独的工作表中传输到 excel 文件。
我尝试使用 Read a model document 进行编码,但无法获得准确的输出。
public class Main {
public static void main (String[] args) {
File file = new File("My file path/My_model.bpmn");
BpmnModelInstance modelInstance = Bpmn.readModelFromFile(file);
// find all elements of the type task
ModelElementType taskType = modelInstance.getModel().getType(Task.class);
Collection<ModelElementInstance> taskInstances = modelInstance.getModelElementsByType(taskType);
System.out.println(taskType.getByName());
}
}
我知道它什么都没有。请从头开始指导我,我该如何实现我的代码。
回答1
根据您要访问的属性,可能有不同的访问方式。这个例子应该有帮助:https://github.com/rob2universe/bpmn-creator/blob/master/src/main/java/DataMappings.java
例如
modelInst.getModelElementsByType(FlowNode.class).forEach(e ->
{
log.info("{} : {} : {}", e.getName(), e.getId(), e.getElementType().getTypeName());
log.info("Attribute completionQuantity: {}", e.getAttributeValue("completionQuantity"));
});
modelInst.getModelElementsByType(CamundaInputParameter.class).forEach(e ->
{
// may need to guard this more
UserTask userTask = (UserTask) e.getParentElement().getParentElement().getParentElement();
log.info("Parent {} has input {} with value {}", userTask.getId(), e.getCamundaName(), e.getTextContent());
});
modelInst.getModelElementsByType(CamundaOutputParameter.class).forEach(e ->
{
// may need to guard this more
UserTask userTask = (UserTask) e.getParentElement().getParentElement().getParentElement();
log.info("Parent {} has input {} with value {}", userTask.getId(), e.getCamundaName(), e.getTextContent());
});