Initiating execution of workflow from Java Code

I have gone through getting started, where a workflow is called from main() method where deployment of process definition is done using XML(which is not my requirement in this case).

Apart from that I have also gone through Instant gratification

As per my understanding, I can use Flowable-Designer to create Flowable Diagrams in my IDE, another way to create workflow is using flowable-modeler endpoint.

I will be working in spring-boot(latest version) application and requirement is to create a service class which has the knowledge to initiate the execution of required workflow.
And in turn use this in other implementations accordingly.

I can also see here lots of spring-boot-starter projects avaialble, but again not sure which one suites my requirement.

Since, I am new to flowable and not very sure which way is possible to do, using flowable-modeler or flowable-designer in IDE, so pretty much in the dark at this point.

You should start with flowable-spring-boot-starter it contains and auto-configures all of the engines.

The Spring Boot starters auto-configure Flowable using a standard datasource and creates beans for most of the flowable services you’ll need to interact with. Instead of getting the RuntimeService from the ProcessEngine, you can simply autowire it in your service. As for deploying your models you can:

  • place the model in resources/processes
  • add the flowable-rest dependency and deploy it via the rest API (flowable-modeler does this)
  • create your own endpoint that takes the model and deploys it using the RepositoryService

This blog post may be helpful if you need a little more guidance.

1 Like

Thanks @wwitt
I will explore the options you gave and get back again if I need any help :slight_smile:

What’s the way to deploy the process that I have build using flowable-modeler?

I used this blog to get started, in addition to it I just created a method in controller to deploy the process-definition which I have created in flowable-modeler.
I downloaded the process as .bpmn20.xml file and saved it in processes folder and it got deployed.
I got the name of processdefinition deployed using the startService method of controller.

Below are the relevant parts of code:

Controller:

@Autowired
private DeployService mDeployService;

@GetMapping("/start-service")
public String startService() {
	ProcessInstance lProcessInstance = mDeployService.deploy("gigplan");
	return lProcessInstance.getProcessDefinitionName();
}

DeployService:

@Service
public class DeployService {

@Autowired
private RuntimeService mRuntimeService;

public ProcessInstance deploy(String processInstanceKey) {
	return mRuntimeService.startProcessInstanceByKey(processInstanceKey);
    }
}

Also, after going through the blog that you mentioned, what should be the URLs for accessing the process-api, idm-api and other APIs mentioned in blog.
My application is running on localhost:8080/ with no context path.
So, localhost:8080/actuator/health is working

Now, I only want the process created in flowable-modeler to be started…!!
I’m not sure what configuration I am missing, some user configuration or what!!!

Note: there is no Swagger documentation deployed by default.

If you’ve added flowable-spring-boot-starter-rest to your dependencies, you’ll have the rest endpoints enabled at:

  • /process-api for the Process Engine
  • /cmmn-api for the CMMN Engine
  • /dmn-api for the DMN Engine
  • /idm-api for the IDM Engine
  • /form-api for the Form Engine
  • /content-api for the Content Engine
  • /app-api the App API

The Modeler has a property flowable.modeler.app.deployment-api-url that points to the /app-api endpoint, but if you are simply deploying one process, you can post it to /process-api/repository/deployments:

image

Once the process is deployed, you can start the process by:

  • Using the REST api and POSTing to /process-api/runtime/process-instances
  • Using the Java API, in this example, I have an endpoint that takes a POST to /print and starts the process asyncDataReceiptProcess. It then completes the first human task, collectBookInfo, and returns the process instance ID:
@RestController
@Log4j2
public class PrintRequestController {
    private final RuntimeService runtimeService;
    private final TaskService taskService;

    public PrintRequestController(RuntimeService runtimeService, TaskService taskService) {
        this.runtimeService = runtimeService;
        this.taskService = taskService;
    }

    @PostMapping("/print")
    public String postRequest() {
        ProcessInstance asyncDataReceiptProcess = runtimeService.startProcessInstanceByKey("asyncDataReceiptProcess");

        Task collectBookInfo = taskService.createTaskQuery().processInstanceId(asyncDataReceiptProcess.getId()).taskDefinitionKey("collectBookInfo").singleResult();

        taskService.complete(collectBookInfo.getId());

        log.info("Starting the task");

        return asyncDataReceiptProcess.getProcessInstanceId();
    }

}

Note @Log4j2 is a Lombok annotation.

1 Like