gpt4 book ai didi

java - 如何从 ProcessInstance 检索执行

转载 作者:行者123 更新时间:2023-12-01 06:03:17 25 4
gpt4 key购买 nike

刚刚开始在 camunda 中创建流程并使用流程变量。我可以成功创建这些流程变量,然后在服务任务中读取它们,然后使用输入/输出参数输出它们。但我正在努力再次检索实际启动此流程的程序中这些参数的更新值。以下是片段:

//测试用例

RuntimeService rs = processEngine().getRuntimeService();
Map<String, Object> variables = new HashMap<>();
variables.put("percentageCompletion", "11");
ProcessInstance processInstance = rs.startProcessInstanceByKey(PROCESS_DEFINITION_KEY, variables);

可以通过执行以下操作在服务任务中访问此percentageCompletion

Object pc = execution.getVariable("percentageCompletion");// Update and set its new value

现在如何再次获取测试用例中 percentageCompletion 的更新值?我已经关注了类似的问题Process Variables in Camunda-BPM

最佳答案

这就是我如何在 junit 中获取它们

 @Test
@Deployment(resources = "process.bpmn")
public void testParsingAndDeployment() {
}

@Test
@Deployment(resources = "process.bpmn")
public void testHappyPath() {
RuntimeService rs = processEngine().getRuntimeService();
Map<String, Object> variables = new HashMap<>();
variables.put("percentageCompletion", "11");
ProcessInstance processInstance = rs.startProcessInstanceByKey(PROCESS_DEFINITION_KEY, variables);
System.out.println(processInstance.isEnded() + ", " + processInstance.isSuspended());
VariableInstance vi = processEngine().getRuntimeService().createVariableInstanceQuery().processInstanceIdIn(processInstance.getId()).variableName("percentageCompletion").singleResult();
System.out.println(processInstance.isEnded() + ", " + processInstance.isSuspended());
System.out.println("********* " + processEngine().getHistoryService().createHistoricDetailQuery().processInstanceId(processInstance.getProcessInstanceId()).count());

String executionId = processEngine().getHistoryService().createHistoricDetailQuery().processInstanceId(processInstance.getProcessInstanceId()).list().get(0).getExecutionId();
System.out.println("executionId " + executionId);

List<HistoricVariableInstance> hvis = processEngine().getHistoryService().createHistoricVariableInstanceQuery().executionIdIn(executionId).list();
System.out.println("------------ " + hvis.size());

for (HistoricVariableInstance hi : hvis) {
System.out.println(hi.getName() + " : "+ hi.getValue());
}
}

关于java - 如何从 ProcessInstance 检索执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51931206/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com