Add proces flow in kjar

In order to create and test a simple script I created two projects by copying the respective original-business-application-* projects.

  • first-business-application-kjar:
  • first-business-application-service:

The first step building a business process service will be to make a process flow. There are two obvious ways to do this. The first is to use the Business Central Process Designer and the second is to use the Eclipse BPMN 2.0 Modeler.

Using the eclipse plugin would be very simple at this point but it has to be installed in Spring Tool Suite 4. The modeler can be found in the Eclipse Market place under Eclipse BPMN2 Modeler and so is easy to install.

Once installed a simple process flow is created by selecting src/main/resources in the first-business-application-kjar project and then file->new->other->BPMN->BPMN2 Model. In the dialog I selected the name of simple-process.bpmn2 and for Model Object I selected process. Unfortunately this created the process in the business-application main directory and I had to move it to the first-business-process-kjar/src/main/resources directory. I think right clicking on the resources directory would have created the simple process in the correct location.

The BPMN2 modeler should give a visual interface for process creation. Add a start event, a script task, and an end event, and connected them with arrows. When I first tried to open the process properties by opening the properties view and selecting the simple-process background I was not able to see all of the properties of a process that should be there. After closing and reopening the simple-process.bpmn2 file in Eclipse with the Bpmn2 Diagram Editor I was able to see all of the properties. Under the Process tab in the properties view I changed the process name to SimpleProcess. I then selected the script task and under the Script Task tab of the properties view I entered the script System.out.println("Hello, World\n");.

As of version 1.5.0 of the Eclipse BPMN2 Modeler there was no way to change the process ID under the Process Tab of properties. Open the simple-script.bpmn2 file in a text editor and change the processId by hand. The default was <bpmn2:process id="Process_1" and I changed it to <bpmn2:process id="SimpleProcess". Process_1 was also found in another location in the file that needed to be changed as well.

Compile the kjar in maven by selecting the first-business-application-kjar project and then run->run as->maven test. That workd with a few parser errors that I was not concerned about. I then updated the kjar in the local maven repository with run->run as->maven install. Be sure to remember that any change you make to the kjar needs to be followed with maven install because the kjar is loaded from the local repository.

Next is to invoke the process-flow from within the spring-boot service project. The service project is already configured to load the kjar and since the GAV value of com.company:business-application-kjar:1.0-SNAPSHOT has not changed the new business process with the SimpleProcess flow should still be loaded. The com.company.service.Application.java file is modified as follows:

@SpringBootApplication
public class Application implements CommandLineRunner {

    @Autowired
    private ProcessService processService;

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        processService.startProcess("business-application-kjar-1_0-SNAPSHOT", "SimpleProcess");
    }
}

Notice that the org.jbpm.services.api.ProcessService is injected into the application and used by the run method to start the process. Note also that the deploymentId argument is "business-application-kjar-1_0-SNAPSHOT". This is set in the business-application-service.xml configuration file in the root of the service project.

Published by Karl

Software Developer

Leave a comment

Design a site like this with WordPress.com
Get started