javaautomationjbpmbpmnkie-server

jbpm persist process in file and kieserver


I have following code, and like to save in file and also on kie server, Taken refrence from https://github.com/kiegroup/jbpm/blob/84c98129de79b5dcd38a3fd6645b3807ef0cce3e/jbpm-bpmn2/src/test/java/org/jbpm/bpmn2/ProcessFactoryTest.java#L228 and to save locally change to filesystem C://dev//processFactory.bpmn2 but it is not working . Also how to persist in kie server which is running at http://localhost:8080/kie-server/docs/ for jbpm

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

Solution

  • setSourcePath is not saving the process into a file, you can do it with FileOutputStream or any other way to write a file from String or bytes:

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

    Could you elaborate more on the second question?