0

我有以下代码,并且喜欢保存在文件和 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();
    }
4

1 回答 1

1

setSourcePath不会将进程保存到文件中,您可以使用FileOutputStream或任何其他方式从字符串或字节写入文件:

FileOutputStream outputStream = new FileOutputStream("your-file-name");
outputStream.write(XmlBPMNProcessDumper.INSTANCE.dump(process).getBytes());

您能否详细说明第二个问题?

于 2022-02-03T23:15:40.480 回答