Use Flowable programatically without xml

Hi Flowable,

I am trying to put in place a system that will run some processes. All of them will have to respect an order that will be defined dynamically. Some of the processes will have to run in parallel also during the sequence flow.

From my understanding, flowable could help me to have a complete solution for the present but even for the future (be able to stop at a step of the sequence flow in case of failure and restart from that step).

To have a better view I tried to do the get started part and I understood easily how to use it with the XML. From that point I tried to configure everything without xml doing like this

    ProcessEngineConfiguration cfg = new StandaloneProcessEngineConfiguration()
            .setJdbcUrl("jdbc:h2:mem:flowable;DB_CLOSE_DELAY=-1")
            .setJdbcUsername("sa")
            .setJdbcPassword("")
            .setJdbcDriver("org.h2.Driver")
            .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);

    ProcessEngine processEngine = cfg.buildProcessEngine();

    BpmnModel bpmnModel = new BpmnModel();
    Process process = new Process();
    bpmnModel.addProcess(process);
    process.setId("holidayRequest");

    StartEvent startEvent = new StartEvent();
    startEvent.setId("startEvent");

    SequenceFlow sequenceFlow = new SequenceFlow("startEvent","approveTask");

    ExclusiveGateway exclusiveGateway = new ExclusiveGateway();
    exclusiveGateway.setId("decision");

    SequenceFlow sequenceFlow2 = new SequenceFlow("decision","externalSystemCall");
    SequenceFlow sequenceFlow3 = new SequenceFlow("decision","sendRejectionMail");

    SequenceFlow sequenceFlow4 = new SequenceFlow("externalSystemCall","holidayApprovedTask");

    SequenceFlow sequenceFlow5 = new SequenceFlow("holidayApprovedTask","approveEnd");

    EndEvent endEvent = new EndEvent();
    endEvent.setId("approveEnd");


    process.addFlowElement(startEvent);
    process.addFlowElement(sequenceFlow);
    process.addFlowElement(exclusiveGateway);
    process.addFlowElement(sequenceFlow2);
    process.addFlowElement(sequenceFlow3);
    process.addFlowElement(sequenceFlow4);
    process.addFlowElement(sequenceFlow5);
    process.addFlowElement(endEvent);

    RepositoryService repositoryService = processEngine.getRepositoryService();
    Deployment deployment = repositoryService.createDeployment().addBpmnModel("holidayRequest", bpmnModel).deploy();

    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
            .deploymentId(deployment.getId())
            .singleResult();
    System.out.println("Found process definition : " + processDefinition.getName());

    RuntimeService runtimeService = processEngine.getRuntimeService();
    ProcessInstance processInstance =
            runtimeService.startProcessInstanceByKey("holidayRequest");

I think it is not the good way to do that and I have some errors the processDefinition seems not to be well defined.

Thanks in advance if someone could help me.

1 Like

Not sure what you’re looking for? Yes, the api you’re currently using is the low-level one that can be used to generate the XML or deploy directly to the engine.

Thanks for your reply. I think after more analysis that flowable will not fit with my needs so I ll try a less document oriented solution like JBPM.