Bonita Learning Tree: A Comprehensive Tutorial
Bonita Open Solution is a highly customizable and efficient tool for business process modeling, allowing for the creation of delightful web-based applications backed by complex business logic and intricate workflows. This tutorial aims to provide a comprehensive guide to leveraging Bonita, from understanding variable types to deploying processes within a Spring Boot application.
Introduction to Bonita Open Solution
Bonita Open Solution stands out as a pragmatic tool for developing complex applications. It empowers developers to model business processes intuitively in a workflow, complete with various conditions and transitions. With Bonita, you can design business application workflows with ease, taking advantage of its powerful backend engine. The drag-and-drop, widget-based modular design of Bonita Studio further enhances its ease of use.
This article will guide you through the entire development cycle of an application created using Bonita Open Solution, from designing web forms to integrating business logic and finally deploying the application on a server.
Understanding Variable Types and Scope in Bonita Studio
Variables are essential in creating processes within Bonita Studio. Bonita provides options for creating two kinds of variables with regard to scope: pool variables and step variables.
Pool Variables vs. Step Variables
Pool variables are akin to global variables in any programming language, while step variables correspond to the local variables of a function. The types of variables, such as integers or text, are the same for both pool and step variables; only their scope differs.
Read also: High School Valedictorian Requirements
For example, an ID number required in all steps of a workflow would be defined as a pool variable to ensure accessibility across all steps. Conversely, a field like "name" required only at a specific step would be defined as a step variable, accessible only by that step.
To define a pool variable, select the pool and click on the Data tab in the details panel. Variables can be added by clicking the "Add…" button.
Variable Types in Detail
Bonita Studio offers a variety of variable types to accommodate different data storage needs:
- Text Variable: This variable is used to hold text of all kinds in Bonita. It is of the Java type String (java.lang.String). The Multiplicity option is used to select whether the variable is a single string variable or an array of strings. The default value that this variable will take can also be stated. If left blank, the variable will be initialized to null, the way Java Strings are initialized. This variable is used to store any kind of text value in Bonita. The variable List of Options… contains a list of text variables that can be used in drop-down boxes or radio buttons. When we select the List of Options… as the data type, a box appears where we define the list that we want to populate. Let's name this list Smartphones. Options such as Apple, Samsung, HTC, and Nokia can be added, and their order rearranged using the Up and Down tabs.
- Boolean Variable: The Boolean variable holds Boolean values, that is, true or false, and is of the type Boolean of Java, found in the package java.lang.Boolean. Its multiplicity can be single or it can be an array of Boolean values.
- Integer Variable: Bonita Studio offers integer variables, but they are of the Java type Long (java.lang.Long).
- Float Variable: In addition to the Integer variable, if we want to deal with decimal points and large numbers, Bonita offers the float variable, which is of the Java type Double (java.lang.Double).
- Date Variable: The date variable is used to store date values, for example, the date that the date-picker widget is in the Web application stores. It is of the Java type Date (java.util.Date). In addition, while defining the default value of this variable, we are given the option to choose it from a date picker that displays the date and time in a grid fashion. Also, the default value can be set to Now, which takes the date and time at execution.
- Attachment Variable: The attachment variable is used to store any file attachment in Bonita. As the attachment is internally stored in the database as Binary Large Object (BLOB), this gives the flexibility to store any kind of file attachment, regardless of the extension. The maximum size of the attachment can be 15 MB. The attachment variable is primarily used in the file widget while creating web forms. Whenever the user clicks on any file object from his system, it is uploaded into the Bonita database and stored as an attachment variable.
- XML Variable: Another way data can be represented in Bonita Studio is to use an XML variable to store data in the XML format. Relevant data can be represented in a concise way using XML. For creating this variable in Bonita, simply select the data type as XML. Here, we have to choose the XML namespace and element for the data.
- Java Variable: This variable is the most useful custom variable that Bonita provides. We have the ability to create Java classes and export them into a jar file from any IDE or Java command line. This jar file can be added to the classpath of Bonita. Thereafter, we can create a new Java object of the type of the class that we have created. To do this, open up an IDE, such as IntelliJIdea or Eclipse. Create a new Java project and a package inside src. Here, we will name it com.rohitbhat.examplepackage. Inside this package, create a new class named TestClass.
Initializing Variables
Understanding how to initialize these different kinds of variables is crucial, as is knowing which variable to use in a particular context. Any kind of information that has to be saved in the workflow can be saved in different kinds of variables.
Integrating Bonita Engine with Spring Boot
This section outlines how to embed the Bonita Engine (BPM workflow engine) in a Spring Boot application.
Read also: Understanding PLCs
Use Case: Loan Request Application
Consider an application based on a process that allows someone to request a loan from their bank. This request will be reviewed, approved, or rejected by the bank, which will provide explanations for its decision.
Scope
In this section, you will learn how to write an application, using the Spring Boot framework, that integrates the Bonita Execution Engine to run processes. You will learn how to configure the Bonita Engine to point to the database of your choice and tune the connection pool. You will learn how to build processes programmatically, deploy, and execute them. You will also learn how to deploy processes generated with Bonita Studio.
Setting up the Environment
To begin, ensure you have the necessary dependencies in your build.gradle file if using Gradle:
val bonitaEngineVersion = "7.9.0"// adding dependency on bonita-engine-spring-boot-starter automatically provides// and starts a Bonita Engine when used in a Spring Boot application:implementation("org.bonitasoft.engine:bonita-engine-spring-boot-starter:$bonitaEngineVersion")// use bonita-client to be able to interact with the running Engine// to deploy and run instances of processes:implementation("org.bonitasoft.engine:bonita-client:$bonitaEngineVersion")// Add the database driver we want Bonita to use:runtime("com.h2database:h2:1.4.199")The bonita-engine-spring-boot-starter dependency automatically starts a Bonita Engine when used in a Spring Boot application. The bonita-client dependency allows interaction with the running Engine to deploy and run process instances. Add the database driver you want Bonita to use.
Engine Startup
When the application starts, a Bonita Engine is automatically started. Engine startup logs can be seen in the console:
Read also: Learning Resources Near You
|09:44:15.601|main|INFO |o.b.p.s.ScriptExecutor| configuration for Database vendor: h2|09:44:15.989|main|INFO |o.b.p.s.PlatformSetup| Connected to 'h2' database with url: 'jdbc:h2:file:./build/h2_database/bonita' with user: 'BONITA'|09:44:16.341|main|INFO |o.b.e.a.i.PlatformAPIImpl| THREAD_ID=1 | HOSTNAME=manu-laptop | Start service of platform : org.bonitasoft.engine.classloader.ClassLoaderServiceImpl|09:44:26.438|main|INFO |o.b.e.a.i.PlatformAPIImpl| THREAD_ID=1 | HOSTNAME=manu-laptop | Start service of platform : org.bonitasoft.engine.cache.ehcache.PlatformEhCacheCacheService|09:44:26.490|main|INFO |o.b.e.a.i.PlatformAPIImpl| THREAD_ID=1 | HOSTNAME=manu-laptop | Start service of platform : org.bonitasoft.engine.service.BonitaTaskExecutor|09:44:26.708|main|INFO |o.b.e.a.i.t.SetServiceState| THREAD_ID=1 | HOSTNAME=manu-laptop | TENANT_ID=1 | start tenant-level service org.bonitasoft.engine.cache.ehcache.EhCacheCacheService on tenant with ID 1|09:44:26.718|main|INFO |o.b.e.a.i.t.SetServiceState| THREAD_ID=1 | HOSTNAME=manu-laptop | TENANT_ID=1 | start tenant-level service org.bonitasoft.engine.business.data.impl.JPABusinessDataRepositoryImpl on tenant with ID 1Coding the First Process
With the platform running, you can now create a LoanRequestProcessBuilder class that builds a Bonita process and returns a DesignProcessDefinition. The process must then be deployed and enabled.
Deploying a Process Designed with Bonita Studio
If a process has been designed using Bonita Studio (graphical tool), the generated .bar file can be deployed through the APIs. Place the .bar file somewhere in the classpath of the application and load it:
class ProcessLoader { fun loadProcessFromBar(barFilePath: String): BusinessArchive { this.javaClass.getResourceAsStream(barFilePath).use { resourceAsStream -> return BusinessArchiveFactory.readBusinessArchive(resourceAsStream) } }}val processFromBar = ProcessLoader().loadProcessFromBar("/SimpleProcess--1.0.bar")ProcessDeployer().deployAndEnableBusinessArchiveWithoutAnyActor(processFromBar)The process named SimpleProcess is now deployed.
Warning: A .bar file generated by a specific Studio version is compatible only with the same version of Bonita.
tags: #bonita #learning #tree #tutorial

