jbpm 在文件和 kieserver 中持久化进程
jbpm persist process in file and kieserver
我有以下代码,喜欢保存在文件和 kie 服务器上,引用自 https://github.com/kiegroup/jbpm/blob/84c98129de79b5dcd38a3fd6645b3807ef0cce3e/jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/ProcessFactoryTest.java#L228 并在本地保存对文件系统 C://dev//processFactory.bpmn2 的更改,但它是不工作。还有如何在 http://localhost:8080/kie-server/docs/ 的 运行 中为 jbpm
保留 kie 服务器
@Test(timeout = 10000)
public void testBoundaryTimerTimeDuration() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("BoundaryTimerEvent",
1);
RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("org.jbpm.process");
factory
// header
.name("My process").packageName("org.jbpm")
// nodes
.startNode(1).name("Start").done()
.humanTaskNode(2).name("Task").actorId("john").taskName("MyTask").done()
.endNode(3).name("End1").terminate(false).done()
.boundaryEventNode(4).name("BoundaryTimerEvent").attachedTo(2).timeDuration("1s").cancelActivity(false).done()
.endNode(5).name("End2").terminate(false).done()
// connections
.connection(1,
2)
.connection(2,
3)
.connection(4,
5);
RuleFlowProcess process = factory.validate().getProcess();
Resource res = ResourceFactory.newByteArrayResource(XmlBPMNProcessDumper.INSTANCE.dump(process).getBytes());
// res.setSourcePath("/tmp/processFactory.bpmn2"); // source path or target path must be set to be added into kbase
res.setSourcePath("C://dev//processFactory.bpmn2");
KieBase kbase = createKnowledgeBaseFromResources(res);
StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
TestWorkItemHandler testHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task",
testHandler);
ksession.addEventListener(countDownListener);
ProcessInstance pi = ksession.startProcess("org.jbpm.process");
assertProcessInstanceActive(pi);
countDownListener.waitTillCompleted(); // wait for boundary timer firing
assertNodeTriggered(pi.getId(),
"End2");
assertProcessInstanceActive(pi); // still active because CancelActivity = false
ksession.getWorkItemManager().completeWorkItem(testHandler.getWorkItem().getId(),
null);
assertProcessInstanceCompleted(pi);
ksession.dispose();
}
setSourcePath
不会将过程保存到文件中,您可以使用 FileOutputStream
或任何其他方式从字符串或字节写入文件:
FileOutputStream outputStream = new FileOutputStream("your-file-name");
outputStream.write(XmlBPMNProcessDumper.INSTANCE.dump(process).getBytes());
第二个问题你能详细说说吗?
我有以下代码,喜欢保存在文件和 kie 服务器上,引用自 https://github.com/kiegroup/jbpm/blob/84c98129de79b5dcd38a3fd6645b3807ef0cce3e/jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/ProcessFactoryTest.java#L228 并在本地保存对文件系统 C://dev//processFactory.bpmn2 的更改,但它是不工作。还有如何在 http://localhost:8080/kie-server/docs/ 的 运行 中为 jbpm
保留 kie 服务器@Test(timeout = 10000)
public void testBoundaryTimerTimeDuration() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("BoundaryTimerEvent",
1);
RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("org.jbpm.process");
factory
// header
.name("My process").packageName("org.jbpm")
// nodes
.startNode(1).name("Start").done()
.humanTaskNode(2).name("Task").actorId("john").taskName("MyTask").done()
.endNode(3).name("End1").terminate(false).done()
.boundaryEventNode(4).name("BoundaryTimerEvent").attachedTo(2).timeDuration("1s").cancelActivity(false).done()
.endNode(5).name("End2").terminate(false).done()
// connections
.connection(1,
2)
.connection(2,
3)
.connection(4,
5);
RuleFlowProcess process = factory.validate().getProcess();
Resource res = ResourceFactory.newByteArrayResource(XmlBPMNProcessDumper.INSTANCE.dump(process).getBytes());
// res.setSourcePath("/tmp/processFactory.bpmn2"); // source path or target path must be set to be added into kbase
res.setSourcePath("C://dev//processFactory.bpmn2");
KieBase kbase = createKnowledgeBaseFromResources(res);
StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
TestWorkItemHandler testHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task",
testHandler);
ksession.addEventListener(countDownListener);
ProcessInstance pi = ksession.startProcess("org.jbpm.process");
assertProcessInstanceActive(pi);
countDownListener.waitTillCompleted(); // wait for boundary timer firing
assertNodeTriggered(pi.getId(),
"End2");
assertProcessInstanceActive(pi); // still active because CancelActivity = false
ksession.getWorkItemManager().completeWorkItem(testHandler.getWorkItem().getId(),
null);
assertProcessInstanceCompleted(pi);
ksession.dispose();
}
setSourcePath
不会将过程保存到文件中,您可以使用 FileOutputStream
或任何其他方式从字符串或字节写入文件:
FileOutputStream outputStream = new FileOutputStream("your-file-name");
outputStream.write(XmlBPMNProcessDumper.INSTANCE.dump(process).getBytes());
第二个问题你能详细说说吗?