<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Karina Macedo Varela</title>
    <description>The latest articles on DEV Community by Karina Macedo Varela (@kmacedovarela).</description>
    <link>https://dev.to/kmacedovarela</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F424052%2F654017c9-39e4-4337-ad08-1e5b27416933.jpeg</url>
      <title>DEV Community: Karina Macedo Varela</title>
      <link>https://dev.to/kmacedovarela</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kmacedovarela"/>
    <language>en</language>
    <item>
      <title>Delivering domain logic with Custom Tasks</title>
      <dc:creator>Karina Macedo Varela</dc:creator>
      <pubDate>Sun, 05 Jul 2020 23:02:07 +0000</pubDate>
      <link>https://dev.to/kmacedovarela/delivering-domain-logic-with-custom-tasks-32d7</link>
      <guid>https://dev.to/kmacedovarela/delivering-domain-logic-with-custom-tasks-32d7</guid>
      <description>&lt;p&gt;Custom Tasks, a.k.a. custom Work Items are used when the natively provided components are not clear enough to demonstrate the required domain demands. See examples of domain-specific tasks that a business user would find useful to have available in the process designer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Enhance customer data;&lt;/li&gt;
&lt;li&gt;Validate Personal ID against Official State Service;&lt;/li&gt;
&lt;li&gt;Check customer health plan;&lt;/li&gt;
&lt;li&gt;Calculate tax over an acquisition;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Creation of custom work item handler demands the involvement of a developer which knows Java. Once developed and deployed, the custom WIH will be displayed in the process designer components tab, along with the other bpmn2 tasks. In this way the business automation specialists can drag and drop it into the flow, and care only about the parameters, and not about the logic execution itself.&lt;/p&gt;

&lt;p&gt;Let’s separate the Custom WIH in four topics:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Development: Creation of the project and development of the core logic.&lt;/li&gt;
&lt;li&gt;Deployment: Provision of the custom tasks in a service repository.&lt;/li&gt;
&lt;li&gt;Installation: Act of choosing available tasks from the service repository and installing into a Business Central.&lt;/li&gt;
&lt;li&gt;Usage: Using the new custom task in process design.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once developed, deployed and installed, the custom task is displayed in the process designer pallet, under the service tasks option ready to be used during the authoring phase.&lt;/p&gt;

&lt;h2&gt;
  
  
  Development
&lt;/h2&gt;

&lt;p&gt;To develop a custom WI, a new Java project needs to be created. This project can be created from scratch or from an official jBPM maven archetype.&lt;/p&gt;

&lt;p&gt;Here is some important information the developer should know:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Creating the project that will hold the WI, based on the archetype will provide all the necessary structure including test samples; It will also provide generation, deployment and installing features.&lt;/li&gt;
&lt;li&gt;To use the archetype it is necessary to clone the project &lt;a href="https://github.com/kiegroup/jbpm-work-items"&gt;jbpm-work-item&lt;/a&gt;to the local environment. This will eliminate a lot of manual work and save dev time.&lt;/li&gt;
&lt;li&gt;The archetype is &lt;a href="https://github.com/kiegroup/jbpm/tree/master/jbpm-workitems/jbpm-workitems-archetype"&gt;org.jbpm.jbpm-workitems-archetype&lt;/a&gt;, and it is available in the project &lt;a href="https://github.com/kiegroup/jbpm/tree/master/jbpm-workitems/jbpm-workitems-archetype"&gt;https:/​/​github.​com/​kiegroup/​jbpm/​tree/​master/​jbpm-​workitems/jbpm-​workitems-​archetype&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;The project is Maven based and can be edited in your favorite IDE;  The project core is consisted initially by one class: CustomWorkItemHandler.java (&lt;em&gt;it may have a different prefix other than&lt;/em&gt; &lt;em&gt;“Custom”&lt;/em&gt;) &lt;/li&gt;
&lt;li&gt;In this class is the method where the developer should code the domain specific custom logic, &lt;strong&gt;executeWorkItem&lt;/strong&gt;. This method is executed when your task is activated;&lt;/li&gt;
&lt;li&gt;Then, if the task finishes successfully, the engine will trigger the method &lt;strong&gt;completeWorkItem&lt;/strong&gt; ;&lt;/li&gt;
&lt;li&gt;If the task gets aborted, the &lt;strong&gt;abortWorkItem&lt;/strong&gt; method will be triggered.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Creating a custom task
&lt;/h3&gt;

&lt;p&gt;Let’s see how to create it using a maven archetype org.jbpm.jbpm-workitems-archetype which provides all the basic starters already set and ready to use.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;[INFO]&lt;/strong&gt; For versions prior to jBPM 7.40.0 , it is &lt;strong&gt;required&lt;/strong&gt; to use JDK 8. You can confirm you Java version by running the “java -version” command on your terminal. Check details here:&lt;/em&gt; &lt;a href="https://issues.redhat.com/browse/JBPM-9204"&gt;https://issues.redhat.com/browse/JBPM-9204&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first step is to download the project which contains the official work item archetype:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mkdir ~/projects/jbpm-getting-started-lab/ &amp;amp;&amp;amp; cd ~/projects/jbpm-getting-started-lab/$ git clone https://github.com/kiegroup/jbpm-work-items$ cd jbpm-work-items$ mvn clean install
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It might take a while until the dependencies are downloaded. Then, it is possible to create a new project using the archetype:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mvn archetype:generate -DarchetypeGroupId=org.jbpm -DarchetypeArtifactId=jbpm-workitems-archetype -DarchetypeVersion= **7.40.0-SNAPSHOT** -DgroupId= **org.kie.learning** -DartifactId= **hello-workitem** -DclassPrefix= **Custom** -Dversion= **7.40.0-SNAPSHOT** -DarchetypeCatalog=local
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The following parameters can be changed according to your environment and needs.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;artifactId&lt;/strong&gt; : name of your project&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;groupId&lt;/strong&gt; : group id used in your project&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;classPrefix&lt;/strong&gt; : will be appended to the work item files;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;archetypeVersion&lt;/strong&gt; : Should be set according to the version of jBPM you just cloned. You can check that on the &lt;code&gt;pom.xml&lt;/code&gt; using the command
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ head -10 ~/projects/jbpm-getting-started-lab/jbpm-work-items/pom.xml
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;After executing the archetype generation command, Maven will download all the required libs to build the project. You will be asked to confirm if the data is correct. If it is correct, input Y and press enter.&lt;/p&gt;

&lt;p&gt;A new project will be created in the current directory with the name of your artifactId, in this example, hello-workitem. The developer can import the project to eclipse, check its structure, created classes, annotations, tests and implement the custom logic.&lt;/p&gt;

&lt;p&gt;Once the development is done, compile the project with &lt;code&gt;mvn clean install&lt;/code&gt;. The file jar file is created inside the target folder.&lt;/p&gt;

&lt;p&gt;Now, it is ready to be deployed to jBPM and configured in BA Projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Deployment&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Once the coding phase is done, the project should be compiled and installed in a maven repository which is visible for Business Central (during authoring) and for Kie Server (for execution).&lt;/p&gt;

&lt;p&gt;Compile the project using the command below and the jar will be available inside target folder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cd hello-workitem/$ mvn clean package
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Install it into the maven repository or do this using business central UI.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Access Business Central settings (right up corner settings icon), and access Service Tasks Administration menu.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HQ-beYFp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/07/screen-shot-2020-07-05-at-19.36.37.png%3Fw%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HQ-beYFp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/07/screen-shot-2020-07-05-at-19.36.37.png%3Fw%3D1024" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click on “Add Service Task” button and upload the jar generated inside your project target folder i.e. &lt;code&gt;~/projects/labs/hello-workitem/target/hello-workitem-7.40.0-SNAPSHOT.jar&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PIX7e7Dv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/07/screen-shot-2020-07-05-at-19.37.55.png%3Fw%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PIX7e7Dv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/07/screen-shot-2020-07-05-at-19.37.55.png%3Fw%3D1024" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--O7o7-CdH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/07/screen-shot-2020-07-05-at-19.39.21.png%3Fw%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--O7o7-CdH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/07/screen-shot-2020-07-05-at-19.39.21.png%3Fw%3D1024" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;After deploying it, look for it in the task list and enable it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--P7VHiZxp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/07/screen-shot-2020-07-05-at-19.47.27.png%3Fw%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--P7VHiZxp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/07/screen-shot-2020-07-05-at-19.47.27.png%3Fw%3D1024" alt=""&gt;&lt;/a&gt;If you open the class &lt;code&gt;src/main/java/org/kie/learning/CustomWorkItemHandler.java,&lt;/code&gt; you will see the class-level annotation defining this WIH name as “CustomDefinitions”.&lt;/p&gt;

&lt;p&gt;The custom WIH will now be available to be installed in any project. Let’s proceed.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Installation&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Now that your Business Central and Kie Server have access to your custom task (the jar is in the maven repository), the business application can be configured.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Access the project, and open the project settings;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CJ9MbKKG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/07/screen-shot-2020-07-05-at-19.50.08.png%3Fw%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CJ9MbKKG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/07/screen-shot-2020-07-05-at-19.50.08.png%3Fw%3D1024" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Select the “Service Tasks” menu&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Locate your custom task in the list and click on the “Install” button.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eJRkxGGO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/07/screen-shot-2020-07-05-at-19.51.00.png%3Fw%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eJRkxGGO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/07/screen-shot-2020-07-05-at-19.51.00.png%3Fw%3D1024" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Check if it is properly configured under Deployment, Work Item Handler, if the WIH with the name you configured and class are present, for example: &lt;code&gt;CustomDefinitions&lt;/code&gt;, &lt;code&gt;new org.kie.learning.CustomWorkItemHandler()&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Hit the save button.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you open a new business process and check the tasks, you will be able to see your custom task:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tKK489xS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/07/screen-shot-2020-07-05-at-19.56.19.png%3Fw%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tKK489xS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/07/screen-shot-2020-07-05-at-19.56.19.png%3Fw%3D1024" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That’s it, you can now create custom tasks with so that the user who is authoring business process can re-use domain logic in a more customize and visible way.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This blog post is part of the fourth section of the &lt;a href="https://karinavarela.me/jbpm-getting-started/"&gt;jBPM Getting started&lt;/a&gt; series&lt;/em&gt;:&lt;br&gt;&lt;br&gt;
&lt;a href="https://karinavarela.me/effective-modeling-integration-and-delivery/"&gt;Effective modeling, Integration and Delivery&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>processes</category>
      <category>customtask</category>
      <category>jbpm</category>
      <category>rhpam</category>
    </item>
    <item>
      <title>jBPM: Consuming business assets via REST</title>
      <dc:creator>Karina Macedo Varela</dc:creator>
      <pubDate>Wed, 01 Jul 2020 01:09:25 +0000</pubDate>
      <link>https://dev.to/kmacedovarela/jbpm-consuming-business-assets-via-rest-3cb</link>
      <guid>https://dev.to/kmacedovarela/jbpm-consuming-business-assets-via-rest-3cb</guid>
      <description>&lt;p&gt;As expected as default over any REST communication, when the integration via client and Kie Server is done via REST, there is no guarantee on the delivery or retry of this message.&lt;/p&gt;

&lt;p&gt;The initialization of &lt;code&gt;Kie Services Client&lt;/code&gt; requires an instance of &lt;code&gt;org.kie.server.client.KieServicesConfiguration&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;When using the REST approach, we should create the instance of &lt;code&gt;KieServicesConfiguration&lt;/code&gt; with the method &lt;code&gt;KieServicesFactory.newRestConfiguration&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To create a new Rest Configuration, it’s required to inform the auth data, URL where the Kie Server is located. Optionally it is possible to set the timeout in milliseconds for this connection attempt.&lt;/p&gt;

&lt;p&gt;Recommendation about the &lt;strong&gt;URL&lt;/strong&gt; : If the architecture contains &lt;em&gt;only one&lt;/em&gt; Kie Server, point the client URL configuration to the Kie Server domain: “/kie-server/services/rest/server”. If the architecture contains &lt;em&gt;multiple&lt;/em&gt; kie servers, you might need to add a &lt;a href="https://karinavarela.me/2019/08/27/intro-jbpm-smart-router/"&gt;kie smart router&lt;/a&gt; component. The kie smart router is especially useful in auto-scalable cloud environments when it is hard to maintain the clients’ code that interacts via dynamic addresses. In this case, the URL should point to the smart-router root URL.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TIP:&lt;/strong&gt; When using smart-router, the kie server url path “kie-server/services/rest/server/” is omitted. In kie-server a new process can be created with a URL like: &lt;a href="http://localhost:8080/kie-server/services/rest/server/containers/"&gt;http://localhost:8080/kie-server/services/rest/server/containers/&lt;/a&gt;{containerId}/processes/{processId}/instances. In smart router, the same action is available via: &lt;a href="http://localhost:9000/containers/"&gt;http://localhost:9000/containers/&lt;/a&gt;{containerId}/processes/{processId}/instances.&lt;/p&gt;

&lt;p&gt;The default &lt;strong&gt;timeout&lt;/strong&gt; is 5000ms, and the default &lt;strong&gt;Marshaling Format&lt;/strong&gt; is JAXB (XML). Consider we have an up and running instance of Kie Server on a WildFly serving on localhost:8080, where we are connecting with user “kieserver”, password “kieserver1!” and setting a timeout of 6 seconds. The Kie Client Configuration could be created like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private static final String KIESERVER\_URL = "http://localhost:8080/kie-server/services/rest/server";
private static final String KIESERVER\_USER = "kieserver";
private static final String KIESERVER\_PASSWORD = "kieserver1!";private static final long KIESERVER\_CONNECTION\_TIMEOUT = 6000l;
private static final MarshallingFormat KIESERVER\_MARSHALLING = MarshallingFormat.JSON;final KieServicesConfiguration connectionConfig = KieServicesFactory.newRestConfiguration( KIESERVER\_URL, KIESERVER\_USER, KIESERVER\_PASSWORD, KIESERVER\_CONNECTION\_TIMEOUT);
connectionConfig.setMarshallingFormat(KIESERVER\_MARSHALLING);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;When using a client application, developers generally use custom domain objects to interact with business processes, tasks, or rules. For example, if starting a medical attendance, probably, the patient information is an input for this process. All these information are modeled into data objects. Kie Server has the capability to automatically marshal and unmarshal objects that are sent and retrieved by it. This being said, if you are starting a process using a client application, you could just say &lt;em&gt;“Kie Server, start a new process with this&lt;/em&gt; &lt;em&gt;instance of Patient object”&lt;/em&gt;. When properly configured, the client automatically creates a rest request where these parameters are sent using a format (the Marshalling Format), in this case, a JSON format.&lt;/p&gt;

&lt;p&gt;When the request reaches Kie Server, it is able to parse this object and associate it to the respective process variable. But when we are using objects other than the basic ones (String, Boolean, Long, Integer, Object, …), we need to inform to the Configuration, which are these custom classes we are transmitting via requests.&lt;/p&gt;

&lt;p&gt;The following example, adds a “Patient” custom data object class to the Kie Configuration so that Kie Server knows how to marshall and unmarshall it. The extra classes configuration looks like below, where :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Set&amp;lt;Class&amp;lt;?&amp;gt;&amp;gt; customClassesList = new HashSet&amp;lt;Class&amp;lt;?&amp;gt;&amp;gt;(); customClassesList.add(Patient.class); connectionConfig.addExtraClasses(extraClassList);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;TIP: Currently, the Marshalling Format options are XTREAM, XML and JSON. Check more details on &lt;a href="https://github.com/kiegroup/droolsjbpm-integration/blob/master/kie-server-parent/kie-server-api/src/main/java/org/kie/server/api/marshalling/MarshallingFormat.java"&gt;org.kie.server.api.marshalling.MarshallingFormat&lt;/a&gt;class.&lt;/p&gt;

&lt;p&gt;Once configured, the developer is now ready to create an instance of the client and consume the assets. Let’s check this step by step on practice.&lt;/p&gt;

&lt;h3&gt;
  
  
  Integrating a Quarkus Application with Kie Server
&lt;/h3&gt;

&lt;p&gt;In order to create a client application to consume a business project deployed in a Kie Container, inside Kie Server, let’s use Quarkus.&lt;/p&gt;

&lt;h4&gt;
  
  
  Creating the Quarkus Project – the client app
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Create the folder below or choose a folder where we will create a new project.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mkdir -p ~/projects/labs
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Inside &lt;code&gt;$HOME/projects/labs/&lt;/code&gt;, create a new Quarkus project using the maven archetype below. A pre-configured project will be created with the REST class pointed in the command below.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mvn io.quarkus:quarkus-maven-plugin:1.5.2.Final:create -DprojectGroupId=org.kvarela -DprojectArtifactId=kie-client-lab -DclassName="org.kvarela.rest.client.HelloKieServerResource" -Dpath="/hello-kieserver" -Dextensions="resteasy-jsonb"$ cd kie-client-lab/
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Run it using &lt;code&gt;mvn compile quarkus:dev -Dquarkus.http.port=8081&lt;/code&gt; . In the first time, Maven will download the required libraries and start the application in sequence&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open Eclipse or any other preferred IDE, and import this maven project. You have a new Java application with rest capabilities ready to go. If you want to confirm, point your browser to &lt;a href="https://dev.tohttp:/%E2%80%8B/%E2%80%8Blocalhost:8081/%E2%80%8Bhello-%E2%80%8Bkieserver"&gt;http:/​/​localhost:8081/​hello-​kieserver&lt;/a&gt; and check the output “hello” printed.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now let’s configure this project, enabling it to consume business assets from jBPM engine, Kie Server.&lt;/p&gt;

&lt;h4&gt;
  
  
  The Kie Service – Configuring Kie Client API and testing the client application
&lt;/h4&gt;

&lt;p&gt;To configure the KIE client API and use it, you can follow the step-by-step below. &lt;em&gt;If you want to check the complete application you can check it here: &lt;a href="https://github.com/kmacedovarela/kie-client-lab"&gt;https://github.com/kmacedovarela/kie-client-lab&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In &lt;code&gt;pom.xml&lt;/code&gt;, add the maven dependency for the &lt;code&gt;kie-server-client&lt;/code&gt;according to your jBPM version. In this example, &lt;code&gt;jbpm.version&lt;/code&gt; is a property configured with value &lt;code&gt;7.38.0.Final&lt;/code&gt;.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;dependency&amp;gt; &amp;lt;groupId&amp;gt;org.kie.server&amp;lt;/groupId&amp;gt; &amp;lt;artifactId&amp;gt;kie-server-client&amp;lt;/artifactId&amp;gt; &amp;lt;version&amp;gt;${jbpm.version}&amp;lt;/version&amp;gt; &amp;lt;/dependency&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;IMPORTANT:&lt;/strong&gt; In versions &lt;strong&gt;prior&lt;/strong&gt; to 7.39.0.Final, there is a conflict in between imported Jackson libraries (details in &lt;a href="https://issues.redhat.com/browse/JBPM-8937"&gt;JBPM-8937&lt;/a&gt; ). Due to that, &lt;a href="https://github.com/kmacedovarela/kie-client-lab/blob/4facb4cdba8ee65bc9154e824f05182a027cf811/pom.xml#L55-L97"&gt;a little trick is necessary to exclude jackson dependencies from kie-server-client, and import the proper libraries versions&lt;/a&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Now, add a class that is responsible for connecting the client application to the Kie Server, during the application startup. Name it &lt;code&gt;KieClientInitializer&lt;/code&gt; (or any another preferred name);
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class KieClientInitializer implements java.io.Serializable {
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Annotate it with &lt;code&gt;@javax.enterprise.context.ApplicationScoped&lt;/code&gt;, and add a new method &lt;code&gt;onStart&lt;/code&gt;. Let’s also add some logging to test our app. This method will be invoked during the application start up. It should look like this:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@ApplicationScopedpublic class KieClientInitializer implements java.io.Serializable {

private static final Logger LOGGER = LoggerFactory.getLogger("KieClientInitializer"); 

void onStart(@Observes StartupEvent ev) { 
    // LOGGER.info("The 
    application is starting..."); 
}}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Validate your configuration by restarting quarkus, and checking if your logs are outputted. Something similar to the bold logs below.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;**2020-06-28 21:16:54,879 INFO [KieClientInitializer] (Quarkus Main Thread) The application is starting…**2020-06-28 21:16:54,990 INFO [io.quarkus] (Quarkus Main Thread) kie-client-lab 1.0-SNAPSHOT on JVM (powered by Quarkus 1.5.2.Final) started in 1.185s. Listening on: http://0.0.0.0:80812020-06-28 21:16:54,993 INFO [io.quarkus] (Quarkus Main Thread) Profile dev activated. Live Coding activated.2020-06-28 21:16:54,993 INFO [io.quarkus] (Quarkus Main Thread) Installed features: [cdi, resteasy, resteasy-jsonb]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;INFO:&lt;/strong&gt; Java EE EJB provides the annotation &lt;code&gt;@javax.ejb.Startup&lt;/code&gt; to create a startup service. In a Quarkus application, we are going to use start event to initialize our connection. More information can be found at: &lt;a href="https://quarkus.io/guides/application-lifecycle-events-guide"&gt;https:/​/​quarkus.​io/​guides/​application-​lifecycle-​events-​guide&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Following the variable examples presented in the previous explanations, create the REST connection settings, and initialize your REST connection.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;5.1. Add the &lt;code&gt;KieServicesClient&lt;/code&gt; variable. We will use this client to list all the deployed kie containers. There is a client for each need as mentioned in &lt;a href="https://karinavarela.me/2020/06/28/getting-started-with-the-kie-server-java-api/"&gt;this post&lt;/a&gt;, like, interacting with processes, rules, etc…&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private static KieServicesClient kieServicesClient;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;5.2. Declare the class variables containing the connection settings:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private static final String KIESERVER\_URL = "http://localhost:8080/kie-server/services/rest/server";private static final String KIESERVER\_USER = "kieserver";private static final String KIESERVER\_PASSWORD = "kieserver1!";private static final MarshallingFormat KIESERVER\_MARSHALLING = MarshallingFormat.JSON;private static final long KIESERVER\_CONNECTION\_TIMEOUT = 6000l;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;5.3. Add a method that builds the Kie Services Client based on the rest configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private void buildKieServicesClient(){final KieServicesConfiguration connectionConfig = KieServicesFactory.newRestConfiguration( KIESERVER\_URL, KIESERVER\_USER, KIESERVER\_PASSWORD, KIESERVER\_CONNECTION\_TIMEOUT); connectionConfig.setMarshallingFormat(KIESERVER\_MARSHALLING); // addExtraClasses(connectionConfig); setKieServicesClient(KieServicesFactory.newKieServicesClient(connectionConfig));}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;5.4. Invoke this method on the &lt;code&gt;onStart&lt;/code&gt; method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void onStart(@Observes StartupEvent ev) { LOGGER.info("The application is starting..."); buildKieClient();}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Open the terminal and restart your quarkus application, so that it invokes this method during the initialization.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;TIP:&lt;/strong&gt; Since this is an example, you can use the user &lt;code&gt;kieserver&lt;/code&gt; and password &lt;code&gt;kieserver1!&lt;/code&gt;. In a real-world project, use a new user for the service. Also, make sure you have your jBPM instance up and running in another terminal tab. Our jBPM is running on localhost:8080. Our client service is running on 8081.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In your endpoint named &lt;code&gt;HelloKieServerResource&lt;/code&gt;, inside the method&lt;code&gt;hello&lt;/code&gt;, delete the &lt;code&gt;return "hello";&lt;/code&gt; code. Let’s add some code that can list the existing KIE containers:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public String hello() { ServiceResponse&amp;lt;KieContainerResourceList&amp;gt; kieContainers = KieClientInitializer.getKieServicesClient().listContainers(); StringBuffer containersString = new StringBuffer(); containersString.append("Existing containers: \n"); for (KieContainerResource kieContainer : kieContainers.getResult().getContainers()) { containersString.append("\n " + kieContainer.toString()); } return containersString.toString();}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Save your files.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;INFO:&lt;/strong&gt; If you try to start your client and jBPM is not up and running on the socket you configured, you’ll get this error: &lt;code&gt;Caused by: org.kie.server.common.rest.NoEndpointFoundException: No available endpoints found&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;That’s it! You have a java client application ready to consume whatever business assets deployed on your Kie Containers. Open your browser, point to h&lt;a href="https://dev.to8081/%20hello-%E2%80%8Bkieserver"&gt;ttp:/​/​localhost:8081/ hello-​kieserver&lt;/a&gt; and you will see a list of all the Kie Containers from the Kie Server. Validate your deployed projects and try to write an endpoint which starts a process and interacts with business tasks. This will make you feel familiar with the API which is intuitive and easy to use.&lt;/p&gt;

&lt;p&gt;Last two important tips:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The full application is available here for you to clone and run on your environment: &lt;em&gt;&lt;a href="https://github.com/kmacedovarela/kie-client-lab"&gt;https://github.com/kmacedovarela/kie-client-lab&lt;/a&gt;&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;The official jBPM documentation shows an implementation sample with all the clients. Make sure you check the implementation and explanations available on the class implementation section named: &lt;a href="https://docs.jboss.org/jbpm/release/7.38.0.Final/jbpm-docs/html_single/#kie-server-java-api-con_kie-apis"&gt;&lt;em&gt;Advanced client configuration example with additional client services&lt;/em&gt;&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;This blog post is part of the sixth section of the &lt;a href="https://karinavarela.me/jbpm-getting-started/"&gt;jBPM Getting started&lt;/a&gt; series&lt;/em&gt;:&lt;br&gt;&lt;br&gt;
&lt;a href="https://karinavarela.me/jbpm-getting-started/6-consuming-business-assets/"&gt;Consuming Business Assets&lt;/a&gt;&lt;/p&gt;

</description>
      <category>processes</category>
    </item>
    <item>
      <title>Getting Started with the Kie Server Java API</title>
      <dc:creator>Karina Macedo Varela</dc:creator>
      <pubDate>Sun, 28 Jun 2020 23:53:09 +0000</pubDate>
      <link>https://dev.to/kmacedovarela/getting-started-with-the-kie-server-java-api-5d63</link>
      <guid>https://dev.to/kmacedovarela/getting-started-with-the-kie-server-java-api-5d63</guid>
      <description>&lt;p&gt;Kie Server Java client API is used when it’s necessary to create a Java service to interact with a remote Kie Server (not an embedded engine). Consider that you have an architecture with a Kie Server running your business projects and you want to consume them using a Java service running in another application server (&lt;em&gt;deploying applications in different JVMs is a recommended practice&lt;/em&gt;). To allow this service to interact with deployed Kie Containers, it first needs to be authenticated and authorized to execute operations inside Kie Server. Once the service is authorized, it is now possible to create and manipulate &lt;code&gt;Kie Deployments&lt;/code&gt;, &lt;code&gt;Containers&lt;/code&gt;, interact with business assets and query data.&lt;/p&gt;

&lt;p&gt;Kie Server Java client API has core services that can be used in your Java classes to authenticate, manage and consume the assets. These services facilitate the development and interaction with business assets since it is not required to create and parse each detail of the requests (this is a need, for example, in front-end applications which connect directly to Kie Server).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TIP:&lt;/strong&gt; Instead of presenting details of each available method in the services, the author opted to present the documentation and source code, which is the best origin of reliable knowledge. All the classes presented in this section are in the source code in the jBPM repository: &lt;a href="https://github.com/kiegroup/droolsjbpm-integration/blob/master/kie-server-parent/kie-server-remote/kie-server-client/src/main/java/org/kie/server/client/"&gt;https:/​/​github.com/​kiegroup/​droolsjbpm-​integration/​blob/​master/​kie-​server-parent/​kie-​server-​remote/​kie-​server-​client/​src/​main/​java/​org/kie/​server/​client/&lt;/a&gt;​&lt;/p&gt;

&lt;p&gt;The available services that can be used to interact with Kie Server and business projects are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Kie Management Related: &lt;code&gt;org.kie.server.client.KieServicesClientorg.kie.server.client.KieServicesConfigurationorg.kie.server.client.KieServicesFactory&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;Cases Related &lt;code&gt;org.kie.server.client.CaseServicesClient;org.kie.server.client.DocumentServicesClient&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;Rules Related &lt;code&gt;org.kie.server.client.DMNServicesClientorg.kie.server.client.RuleServicesClient&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Solver Related 
&lt;code&gt;org.kie.server.client.SolverServicesClient&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;Process Related &lt;code&gt;org.kie.server.client.ProcessServicesClientorg.kie.server.client.QueryServicesClientorg.kie.server.client.JobServicesClient&lt;/code&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Every client application needs to be authenticated and authorized to interact with Kie Server. The necessary role to authorize this interaction is kie-server role. The user containing this role should be configured in the application server where Kie Server is running, or, it should exist in the external IDP (i.e. &lt;a href="http://keycloak.org"&gt;Keycloak&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;The following guideline provides overall steps on how to configure the Kie Client Java API in any Java application. Details on REST and JMS integration configuration are provided in sequence. To allow an application to interact with business assets:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Add the kie server client library as a dependency in the client application project:

&lt;ul&gt;
&lt;li&gt;To consume remote kie servers, add &lt;code&gt;org.kie.server:kie-server-client&lt;/code&gt; dependency in the &lt;code&gt;pom.xml&lt;/code&gt; file.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Create a configuration class (extending &lt;code&gt;KieServicesConfiguration&lt;/code&gt;) . This class indicates whether this is a JMS or a REST client. Additionally, it contains the connection settings used to integrate with the Kie Server. Let’s see more details on each respective topic in a while.&lt;/li&gt;
&lt;li&gt;Once the configuration is set, use &lt;code&gt;KieServicesFactory&lt;/code&gt; to create a new&lt;code&gt;Kie Services Client&lt;/code&gt;. &lt;em&gt;It’s recommended that this is done only once, for example&lt;/em&gt; &lt;em&gt;during the application startup&lt;/em&gt;. All the client services presented in the previous services table are accessible from &lt;code&gt;KieServicesClient&lt;/code&gt; instance. Use the configuration created on step 2, as to create this object:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kieServicesClient = KieServicesFactory.newKieServicesClient(conf);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Choose the services you need in this client, and initialize them. Example:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ProcessServicesClient processService = kieServicesClient.getServicesClient(ProcessServicesClient.class);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Use the services as you wish. For example, to start a new process instance:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;processService.startProcess("container:id", "processId");
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;After following these steps this application is now a client ready to interact with any deployed business application inside the configured remote Kie Server. The developer can now do all kinds of integration: fire rules, manage and interact with processes, cases, and resource planning assets.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This blog post is part of the sixth section of the &lt;a href="https://karinavarela.me/jbpm-getting-started/"&gt;jBPM Getting started&lt;/a&gt; series&lt;/em&gt;:&lt;br&gt;&lt;br&gt;
&lt;a href="https://karinavarela.me/jbpm-getting-started/6-consuming-business-assets/"&gt;Consuming Business Assets&lt;/a&gt;&lt;/p&gt;

</description>
      <category>processes</category>
    </item>
    <item>
      <title>jBPM: Mastering Transaction Boundaries</title>
      <dc:creator>Karina Macedo Varela</dc:creator>
      <pubDate>Sun, 28 Jun 2020 23:33:14 +0000</pubDate>
      <link>https://dev.to/kmacedovarela/jbpm-mastering-transaction-boundaries-2bp0</link>
      <guid>https://dev.to/kmacedovarela/jbpm-mastering-transaction-boundaries-2bp0</guid>
      <description>&lt;p&gt;When planning usage of processes that are complex, long-running, and with possible points of failures like custom work item handlers, asynchronous tasks, timers, signals, and service tasks, it is crucial to understand how jBPM deals with transactions.&lt;/p&gt;

&lt;p&gt;This knowledge might save some troubleshooting hours if you have persistent processes. “&lt;em&gt;Why?&lt;/em&gt;“, you might ask: if the process is not properly designed and an unhandled error occurs, you may end-up with tasks being triggered more times than you planned.&lt;/p&gt;

&lt;p&gt;Let’s drill down.&lt;/p&gt;

&lt;p&gt;During the following process execution, jBPM will execute all these tasks in a &lt;strong&gt;single&lt;/strong&gt; transaction:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vOUMuGdq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/06/stprocess.png%3Fw%3D918" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vOUMuGdq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/06/stprocess.png%3Fw%3D918" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Therefore, if the process reaches Service B, and it throws an exception, Service A won’t be rolled back. This process will not be persisted on the database, it is like it was never executed. This would happen because there is no &lt;strong&gt;wait state&lt;/strong&gt; point in this process.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lP-SFWqS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/06/transactionboundary1.png%3Fw%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lP-SFWqS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/06/transactionboundary1.png%3Fw%3D1024" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To the engine, a &lt;strong&gt;wait state&lt;/strong&gt; is any point during the process execution which it might need to wait for some external intervention. When this occurs, the engine persists the process state in the database. These are the possible wait states of a process:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Human Tasks&lt;/li&gt;
&lt;li&gt;Catch events (signals, timers)&lt;/li&gt;
&lt;li&gt;Async Tasks (marked with Async flag)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, if we consider the following process, what will happen if &lt;em&gt;Service B&lt;/em&gt; throws an exception?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hL8oQH5Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/06/humantask-1.png%3Fw%3D905" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hL8oQH5Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/06/humantask-1.png%3Fw%3D905" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If &lt;em&gt;service B&lt;/em&gt; with an unrecoverable error and throwing exception, &lt;em&gt;Service A&lt;/em&gt; would be triggered three times. (worrying, right?)&lt;/p&gt;

&lt;p&gt;In this case, the process was persisted when the human task was completed. So, when &lt;em&gt;Service B&lt;/em&gt; threw an exception, the transaction will roll back and return to the &lt;em&gt;Human Task&lt;/em&gt; again. &lt;em&gt;Gateway&lt;/em&gt; is validated, &lt;em&gt;Service A&lt;/em&gt; is triggered the second time, and then, &lt;em&gt;Service B&lt;/em&gt; is triggered. If &lt;em&gt;B&lt;/em&gt; throws an exception, the execution again returns to the &lt;em&gt;Human Task&lt;/em&gt;. This will happen as many times as configured in the engine retry count, which by default is three.&lt;/p&gt;

&lt;p&gt;In cases like the one represented below, by simply configuring Rest Task 2 as Async you can make the engine persist the process state, and in case of an error on REST Task 3, Rest Task 1 and 2 would not be executed again.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ooJFSBeO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/06/transactionboundary.png%3Fw%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ooJFSBeO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/06/transactionboundary.png%3Fw%3D1024" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To avoid situations like this, during the process authoring, have the transaction boundaries clear in your mind. Choose wisely which task should be async, which are the wait states, and if you need to create any wait state or handle errors with compensation events to avoid unexpected businesses outcomes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;Understanding how the engine works will help business automation specialists and developers to deliver fine-tuned projects that perform better on the jBPM engine. The business automation specialist should be able to absorb the business requirements and be able to reflect this on the project not only by authoring the assets but by improving the execution of these assets adjusting every configuration to best perform in each scenario and by being able to understand the impacts of the transaction boundaries in each delivered process.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This blog post is part of the fifth section of the &lt;a href="https://karinavarela.me/jbpm-getting-started/"&gt;jBPM Getting started&lt;/a&gt; series&lt;/em&gt;:&lt;br&gt;&lt;br&gt;
&lt;a href="https://karinavarela.me/2020/06/15/techniques-to-boost-a-ba-project/"&gt;Techniques to boost a BA Project&lt;/a&gt;&lt;/p&gt;

</description>
      <category>processes</category>
    </item>
    <item>
      <title>jBPM: Persisting domain data in a custom database </title>
      <dc:creator>Karina Macedo Varela</dc:creator>
      <pubDate>Wed, 17 Jun 2020 10:00:00 +0000</pubDate>
      <link>https://dev.to/kmacedovarela/jbpm-persisting-domain-data-in-a-custom-database-46m0</link>
      <guid>https://dev.to/kmacedovarela/jbpm-persisting-domain-data-in-a-custom-database-46m0</guid>
      <description>&lt;p&gt;When working with business processes, it is expected to work with persistent process data scenarios. Considering this situation, it is common for users to use a different database to store process data, apart from the database where the domain information is stored.&lt;/p&gt;

&lt;p&gt;As an example, storing critical information from customers apart from the engine database is an expected data architecture. In this way, the user can maintain the data consistent and isolated. But what if these objects, stored in a different database, needs to be used in one of the business automation projects?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;[INFO]&lt;/strong&gt; Many of the concepts here applied are valid for any application which involves distributed transactions (XA Transactions), this means, any application which might possibly have a transaction which spawns through two or more different databases. An overview of how application deployed in Java EE application servers, communicates with a database can be found at this blog post:&lt;a href="https://karinavarela.me/2019/06/11/xa-datasources-concept/"&gt;Datasources, what, why, how?&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s understand how to configure and access different databases within the same project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pluggable Variable Persistence (PVP)
&lt;/h2&gt;

&lt;p&gt;Here are the steps required to make a business automation process store process variables (domain information) in a different database:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Configure the app server datasource pointing the database where you want to store the custom data;&lt;/li&gt;
&lt;li&gt;Make sure custom POJOs (the object to be persisted) are a JPA object

&lt;ol&gt;
&lt;li&gt;Data Object must implement Serializable interface;&lt;/li&gt;
&lt;li&gt;Must be a JPA Entity;&lt;/li&gt;
&lt;li&gt;Must have a unique id, a primary key;&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;li&gt;Configure business automation project

&lt;ol&gt;
&lt;li&gt;Configure a JPA Marshalling Strategy;&lt;/li&gt;
&lt;li&gt;Configure the persistence unit (pointing to the datasource mentioned on the first step);&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Once this is done, every time this object gets created or updated during the process execution, it will be properly persisted on the database. Let’s check this with a hands-on exercise.&lt;/p&gt;

&lt;h3&gt;
  
  
  Persisting custom objects using PVP
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Bootstrap a database
&lt;/h4&gt;

&lt;p&gt;To run this example, using docker to start a database is the easiest way to get a database up and running. Make sure you have docker running in your environment. Let’s create a directory to store the database information.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mkdir -p ~/projects/jbpm-getting-started-lab/postgresql
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Make sure you have Docker up and running. Then you can start a Postgres container:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ docker run --name jbpm-postgres-container -e POSTGRES\_PASSWORD=psqlpass -d -p 6543:5432 -v $HOME/projects/jbpm-getting-started-lab/postgres:/var/lib/postgresql postgres:9.4
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This command will download the image (if you don’t have it locally), start a container named &lt;em&gt;postgres&lt;/em&gt;, based on the latest PostgreSQL image. expose the internal port 5432 opened by PostgreSQL, to be accessed externally also in 6543.&lt;/p&gt;

&lt;p&gt;Let’s enter in this SQL Server to create a new database for our jBPM tables. Run the command below to get the Container ID of this psql container:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES620350186bbe postgres:9.4 "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:6543-&amp;gt;5432/tcp jbpm-postgres-container
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Use the whole ID, or simply the first two numbers, to enter the container. Then, we will start the psql client:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ docker exec -it jbpm-postgres-container /bin/bash $ psql -h localhost -U postgres -d postgres
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now, let’s create a database to be used by jBPM, with a new a user and password. This user needs permision on this new database. The tables will be created automatically by jBPM on startup.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;[TIP]&lt;/strong&gt; You might want to create additional indexes on some tables and columns in your production environment&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE DATABASE jbpmdb;CREATE USER jbpmdb WITH ENCRYPTED PASSWORD 'jbpmdb';GRANT ALL PRIVILEGES ON DATABASE jbpmdb TO jbpmdb;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And create another database, to store the specific domain data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CREATE DATABASE labpvp;CREATE USER labuser WITH ENCRYPTED PASSWORD 'labuser';GRANT ALL PRIVILEGES ON DATABASE labpvp TO labuser;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;When done, type &lt;code&gt;\q&lt;/code&gt; and press enter, to quit psql client, and then exit to exit the container.&lt;/p&gt;

&lt;h4&gt;
  
  
  Configuring the Application Server
&lt;/h4&gt;

&lt;p&gt;Now, let’s configure WildFly: we will create two datasources one connecting to &lt;code&gt;jbpmdb&lt;/code&gt; and other to &lt;code&gt;labpvp&lt;/code&gt; . Once the datasources are configured, applications can start connecting to these databases.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;In this example we expect that you have downloaded jBPM and have it available in your &lt;code&gt;~/projects&lt;/code&gt; directory. If you want to use the commands here, you can optionally create a symbolic link for the folder with the command below:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ln -s ~/projects/jbpm-server-7.38.0.Final-dist ~/projects/jbpm
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Configuring WildFly basically requires two steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Adding a JDBC driver (the responsible for teaching WildFly how to talk the specific database language);&lt;/li&gt;
&lt;li&gt;Adding a datasource with the credentials, connection URL, and driver information.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The simplest way to add a JDBC driver to WildFly is deploying it. &lt;a href="https://jdbc.postgresql.org/download/postgresql-42.2.12.jar"&gt;Download &lt;code&gt;postgresql-42.2.2.jar&lt;/code&gt;&lt;/a&gt;and place it into &lt;code&gt;~/projects/jbpm/standalone/deployments&lt;/code&gt;. WildFly will immediately tell you the driver is deployed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;16:11:07,515 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-4) WFLYJCA0005: Deploying non-JDBC-compliant driver class org.postgresql.Driver (version 42.2)16:11:07,540 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-5) WFLYJCA0018: Started Driver service with driver-name = postgresql-42.2.12.jar16:13:33,885 INFO [org.jboss.as.server] (ServerService Thread Pool -- 45) WFLYSRV0010: Deployed "postgresql-42.2.12.jar" (runtime-name : "postgresql-42.2.12.jar")
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Let’s use the JBoss CLI script, which is less error-prone, to do the configuration. Start your WildFly in one terminal tab, and open another terminal tab so you can connect to it using CLI.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ~/projects/jbpm/bin/jboss-cli.sh -c
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Add a new datasource, informing the connection data, and your deployed driver name:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[standalone@localhost:9990 /] xa-data-source add --name=psqljBPMXA --jndi-name=" **java:/jboss/datasources/psqljBPMXADS**" --user-name= **jbpmdb** --password= **jbpmdb** --driver-name= **postgresql-42.2.2.jar** --xa-datasource-class=org.postgresql.xa.PGXADataSource --xa-datasource-properties=[{ServerName= **localhost** ,PortNumber= **6543** ,DatabaseName= **jbpmdb** }]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now, let’s add a datasource to connect to our domain-specific database, &lt;code&gt;labpvp&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[standalone@localhost:9990 /] xa-data-source add --name=psqlLabPVP --jndi-name=" **java:/jboss/datasources/psqlLabPVP**" --user-name= **labuser** --password= **labuser** --driver-name= **postgresql-42.2.2.jar** --xa-datasource-class=org.postgresql.xa.PGXADataSource --xa-datasource-properties=[{ServerName= **localhost** ,PortNumber= **6543** ,DatabaseName= **labpvp** }]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The following test commands validate both datasource configurations:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[standalone@localhost:9990 /] /subsystem=datasources/xa-data-source=psqljBPMXA:test-connection-in-pool{"outcome" =&amp;gt; "success","result" =&amp;gt; [true]}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Finally, we need to tell jBPM to stop using the H2 database and start using Postgres by connecting through the datasource with JNDI name: &lt;code&gt;java:/jboss/datasources/psqljBPMXADS&lt;/code&gt; .&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[standalone@localhost:9990 /] /system-property=org.kie.server.persistence.ds:write-attribute(value=java:/jboss/datasources/psqljBPMXADS, name=value)[standalone@localhost:9990 /] /system-property=org.kie.server.persistence.dialect:add(value=org.hibernate.dialect.PostgreSQLDialect)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Restart jBPM&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;It will bootstrap creating its tables inside the Postgres in your docker container. You can confirm this by getting into your Postgres container and listing the tables:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ docker exec -it jbpm-postgres-container /bin/bashroot@620350186bbe:/# psql -h localhost -U jbpmdb -d jbpmdbpsql (9.4.22)Type "help" for help.jbpmdb=&amp;gt; **\d**
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Creating persistent objects with Business Central
&lt;/h3&gt;

&lt;p&gt;Scenario: You joined a team which has on-going project, hello-jbpm. In this project, the final user does a question, complain or suggestion and gets an automatic or a manual answer. You noticed that the data architecture can be improved by storing the reported issue and person details, into a separate database. apart from the one used by the engine.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Import project 02-customer-service-jbpm if you don’t have it in your business central yet.&lt;/em&gt; You should see it in your space:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OXpkXIdF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/06/screen-shot-2020-06-16-at-16.34.52.png%3Fw%3D873" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OXpkXIdF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/06/screen-shot-2020-06-16-at-16.34.52.png%3Fw%3D873" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In order to persist a POJO into a database, we need will make use of JPA benefits and to convert it into a JPA Entity.&lt;/p&gt;

&lt;p&gt;Open hello-jbpm project, and notice both data object named &lt;code&gt;Issue&lt;/code&gt; and the &lt;code&gt;Person&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IoUbhO0K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/06/screen-shot-2020-06-16-at-16.36.01.png%3Fw%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IoUbhO0K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/06/screen-shot-2020-06-16-at-16.36.01.png%3Fw%3D1024" alt=""&gt;&lt;/a&gt;You can use the filter to see only specific types of assets. In this example the list is filtered to show only Model assets.&lt;/p&gt;

&lt;p&gt;Let’s start by configuring Person. By clicking on the “Source” tab you can view it’s code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;[TIP]&lt;/strong&gt; In order to be persisted, classes should implement &lt;code&gt;java.io.Serializable&lt;/code&gt; interface. By default, Business Central creates the Data Objects implementing &lt;code&gt;Serializable&lt;/code&gt; interface.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Transform it into an entity by adding &lt;code&gt;@javax.persistence.Entity&lt;/code&gt; annotation;&lt;/li&gt;
&lt;li&gt;Inform the name of the table you want to store this Data Object with the annotation &lt;code&gt;@javax.persistence.Table(name = "Person")&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;This class does not have a primary key yet. Add an id, with type &lt;code&gt;Long&lt;/code&gt; to &lt;code&gt;Person.java&lt;/code&gt;. Don’t forget the attribute should have the get and set method and be annotated with &lt;code&gt;@javax.persistence.Id&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;Person.java&lt;/code&gt; should look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Wib4bJiY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/06/screen-shot-2020-06-16-at-16.37.33.png%3Fw%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Wib4bJiY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/06/screen-shot-2020-06-16-at-16.37.33.png%3Fw%3D1024" alt=""&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@javax.persistence.Entity @javax.persistence.Table(name = "Person")public class Person implements java.io.Serializable { @javax.persistence.Id @javax.persistence.SequenceGenerator(name = "ID\_GENERATOR", sequenceName = "PERSON\_ID\_SEQUENCE") private java.lang.Long id;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Click on the save button.&lt;/p&gt;

&lt;h4&gt;
  
  
  Configuring business application persistence unit with Business Central
&lt;/h4&gt;

&lt;p&gt;The persistence unit, if the configuration which tells a Java EE application which datasource it must use to connect to the database. To configure a business application to persist process variables in a custom database, inform the datasource details in the persistence unit, and create a Marshaller configuration. This Marshaller configuration allows the engine to convert the variables data to/from process and database.&lt;/p&gt;

&lt;p&gt;When the JPA Marshaller is configured, every JPA Entity used as a process variable, is automatically persisted in the database pointed by the application used datasource.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To configure the persistence unit details, access the project &lt;em&gt;Settings&lt;/em&gt;, and select the &lt;em&gt;Persistence&lt;/em&gt; option.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wpUcXEcB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/06/screen-shot-2020-06-16-at-16.41.22.png%3Fw%3D1013" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wpUcXEcB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/06/screen-shot-2020-06-16-at-16.41.22.png%3Fw%3D1013" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Considering we are using PostgreSQL and the datasource configured in the last step, use the following values in the form:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Persistence Unit: &lt;code&gt;customer-service-jbpm-pu&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Data Source &lt;code&gt;java:/jboss/datasources/psqlLabPVP&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;hibernate.dialect: &lt;code&gt;org.hibernate.dialect.PostgreSQLDialect&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;hibernate.show_sql: &lt;code&gt;true&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8JEOvgso--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/06/screen-shot-2020-06-16-at-16.43.45.png%3Fw%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8JEOvgso--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/06/screen-shot-2020-06-16-at-16.43.45.png%3Fw%3D1024" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Set the &lt;code&gt;show_sql&lt;/code&gt; attribute to &lt;code&gt;true&lt;/code&gt;, to enable logs and permit checking in the server logs if the entity is being manipulated as expected. Save the configuration.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Make sure you scroll down and add the persistable class, &lt;code&gt;Person&lt;/code&gt;:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ezNsf6Ma--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/06/screen-shot-2020-06-16-at-17.42.28.png%3Fw%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ezNsf6Ma--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/06/screen-shot-2020-06-16-at-17.42.28.png%3Fw%3D1024" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Still in the project &lt;em&gt;Settings&lt;/em&gt;, configure the JPA Marshaller. Access the &lt;em&gt;Deployments&lt;/em&gt; option, and select &lt;em&gt;Marshalling Strategies&lt;/em&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vkZWwjTx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/06/screen-shot-2020-06-16-at-16.47.49.png%3Fw%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vkZWwjTx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/06/screen-shot-2020-06-16-at-16.47.49.png%3Fw%3D1024" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Click on “&lt;em&gt;Add Marshalling Strategy&lt;/em&gt;“, insert the following value and hit save:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;new org.drools.persistence.jpa.marshaller.JPAPlaceholderResolverStrategy("customer-service-jbpm-pu", classLoader)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now you have JPA Classes ready to be used as process variables, and to be automatically persisted in a different database!&lt;/p&gt;

&lt;p&gt;You can check the result of this work by clicking on the Deploy button. If everything is properly set, you should see something similar in the server log:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;17:41:12,801 INFO [stdout] (default task-20) Hibernate: create table Person (id int8 not null, birthDate timestamp, name varchar(255), primary key (id))
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Start a new process instance, and validate if the object was persisted in the database table you specified.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This blog post is part of the fifth section of the &lt;a href="https://karinavarela.me/jbpm-getting-started/"&gt;jBPM Getting started&lt;/a&gt; series&lt;/em&gt;:&lt;br&gt;&lt;br&gt;
&lt;a href="https://karinavarela.me/2020/06/15/techniques-to-boost-a-ba-project/"&gt;Techniques to boost a BA Project&lt;/a&gt;&lt;/p&gt;

</description>
      <category>processes</category>
    </item>
    <item>
      <title>jBPM: Runtime Strategy: Choose wisely</title>
      <dc:creator>Karina Macedo Varela</dc:creator>
      <pubDate>Tue, 16 Jun 2020 17:50:37 +0000</pubDate>
      <link>https://dev.to/kmacedovarela/jbpm-runtime-strategy-choose-wisely-4e5n</link>
      <guid>https://dev.to/kmacedovarela/jbpm-runtime-strategy-choose-wisely-4e5n</guid>
      <description>&lt;p&gt;Kie Server can be configured to deal differently with the requests it receives and the objects it stores in memory or in the database. Properly configuring how the engine deals with the objects in memory, ensures a project with fewer resource consumption and avoids unexpected behaviors.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Runtime Strategy configuration affects directly how the engine deals with the lifecycle of the Kie Sessions and objects loaded in memory.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You have to choose between four options, for each new project deployment you create:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Singleton Runtime Strategy
&lt;/li&gt;
&lt;li&gt;Per Process Runtime Strategy&lt;/li&gt;
&lt;li&gt;Per Request Runtime Strategy&lt;/li&gt;
&lt;li&gt;Per Case&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Choosing a strategy&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Understand the key concepts of each strategy to guide your decision of when you should use each of them:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Singleton Runtime Strategy:&lt;/strong&gt; If you create and deploy a project, this runtime strategy configuration is used. It’s the default configuration. This strategy uses a single Kie Session. This makes things easier for beginners since every inserted object is available in the same Kie Session. Also, jBPM persists the Kie Session, and it is reused if the server restarts.&lt;/p&gt;

&lt;p&gt;Rule execution within processes can be impacted. Consider that: if process instance &lt;em&gt;A&lt;/em&gt; inserts person &lt;em&gt;John&lt;/em&gt; to be evaluated by business rules. Process instance &lt;em&gt;B&lt;/em&gt;, inserts &lt;em&gt;Maria&lt;/em&gt;. Later, when process &lt;em&gt;C&lt;/em&gt; fires rules for its own person, &lt;em&gt;John&lt;/em&gt; and &lt;em&gt;Maria&lt;/em&gt; will &lt;strong&gt;still&lt;/strong&gt; be in memory and will be evaluated by process C rules improperly!&lt;/p&gt;

&lt;p&gt;When using this configuration, process execution happens within a synchronized &lt;code&gt;Runtime Engine&lt;/code&gt;: it is thread-safe. Consequently, this characteristic can affect and bring consequences on performance. If you expect a high workload, or if the project use timers or signals in the process definitions, you may want to consider a diﬀerent strategy for your production environment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Per Request Strategy:&lt;/strong&gt; defines a stateless behavior. The engine will create one Kie Session per request and destroy it at the end. The Kie Session will not be persisted. This is a good choice for high workload environments.&lt;/p&gt;

&lt;p&gt;The following situation can occur: Consider two requests executed simultaneously to interact with the same process instance. One of the two requests might lock a database row to update it, and the other request might try to update it as well. This will lead to an &lt;code&gt;OptimisticLockException&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This strategy might do the implementation more challenging if your project uses timers events or if the process involves business rule tasks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Per Process Instance Strategy:&lt;/strong&gt; recommended when your process uses timers and businessrule tasks. The Kie Session is created when the process instance starts, and it dies, when the process instance ends. This is usually adequate for most use cases.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Keep in mind: creating Kie Bases is an expensive operation. Creating new Kie Sessions is cheap.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The engine stores the Kie Session in the database, and always use the same Kie Session for the same process instances.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Per Case:&lt;/strong&gt; this strategy should be used if you are using a Case Management project. If you create a new “Case Project”, this strategy is selected by default. The Kie Session will last while the case is still opened (active).&lt;/p&gt;

&lt;p&gt;Now, let’s check the possible places to configure Runtime Strategies, and when should each one be used.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Choosing where to configure the strategy&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Container Level&lt;/strong&gt; : Affects the deployed kjar. Configuration can be made in kie containers using Business Central via the &lt;em&gt;Execution Servers&lt;/em&gt; page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3ZSYo7V8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/06/screen-shot-2020-06-16-at-14.45.26.png%3Fw%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3ZSYo7V8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/06/screen-shot-2020-06-16-at-14.45.26.png%3Fw%3D1024" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Project level&lt;/strong&gt; : The configuration will affect only this project. Configuration can be done via Business Central in the XML file or via. Inside the file &lt;code&gt;src/main/resources/META-INF/kie-deployment-descriptor.xml&lt;/code&gt; the following configuration is present: SINGLETON&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YXtqtPy7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/06/screen-shot-2020-06-16-at-14.45.42.png%3Fw%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YXtqtPy7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/06/screen-shot-2020-06-16-at-14.45.42.png%3Fw%3D1024" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Server level&lt;/strong&gt; : No UI Available. A new system property needs to be configured pointing to the new file.&lt;/p&gt;

&lt;p&gt;This change will impact all projects from this server. A new &lt;code&gt;deployment-descriptor.xml&lt;/code&gt; needs to be provided with &lt;strong&gt;all&lt;/strong&gt; the tags and components (not only the ones which you want to customize). The system property is &lt;code&gt;org.kie.deployment.desc.location&lt;/code&gt; and its value must point to a valid accessible file: “&lt;code&gt;file:/path/to/file/deployment-descriptor.xml&lt;/code&gt;“&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;[INFO]&lt;/strong&gt; If using the server level configuration, make sure to provide a valid XML file. See more details about the configuration in the official documentation, topic “ &lt;strong&gt;Default deployment descriptor”&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://docs.jboss.org/jbpm/release/latest/jbpm-docs/html_single/#_deployment_descriptors"&gt;https://docs.jboss.org/jbpm/release/latest/jbpm-docs/html_single/#_deployment_descriptors&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Finally, considering that we can configure the runtime strategy in three different places, this is how the precedence works by default: &lt;em&gt;Container configuration overrides KJar and Server configs.&lt;/em&gt; &lt;em&gt;KJar configuration overrides Server configs.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This blog post is part of the fifth section of the &lt;a href="https://karinavarela.me/jbpm-getting-started/"&gt;jBPM Getting started&lt;/a&gt; series&lt;/em&gt;:&lt;br&gt;&lt;br&gt;
&lt;a href="https://karinavarela.me/2020/06/15/techniques-to-boost-a-ba-project/"&gt;Techniques to boost a BA Project&lt;/a&gt;&lt;/p&gt;

</description>
      <category>processes</category>
    </item>
    <item>
      <title>5. Techniques to boost a Business Automation Project</title>
      <dc:creator>Karina Macedo Varela</dc:creator>
      <pubDate>Tue, 16 Jun 2020 01:26:27 +0000</pubDate>
      <link>https://dev.to/kmacedovarela/5-techniques-to-boost-a-business-automation-project-3ko4</link>
      <guid>https://dev.to/kmacedovarela/5-techniques-to-boost-a-business-automation-project-3ko4</guid>
      <description>&lt;p&gt;&lt;em&gt;Previous posts of the&lt;a href="https://karinavarela.me/jbpm-getting-started/"&gt;jBPM Getting Started Series&lt;/a&gt; should provide a good base for the understanding of this chapter. Also, basic knowledge about application transactions should provide a better understanding of the chapter.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The engine can be tuned for business automation projects to achieve better performance results are achieved. Mainly when involving business rules validation, there are important decisions that need to be taken about the process execution runtime.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;And this is not about how to tune your JVM or operational system&lt;/em&gt;. This is about using the engine in the best possible way for each project you deliver.&lt;/p&gt;

&lt;p&gt;To create high-performance business automation projects, there are some topics in which the business automation specialist needs to worry:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Is your project lightweight and easily scalable?&lt;/li&gt;
&lt;li&gt;What is the best way, in each scenario, for the engine to deal with objects in-memory?&lt;/li&gt;
&lt;li&gt;Are you properly storing the domain data – do you need to store data in a different data store?&lt;/li&gt;
&lt;li&gt;What will happen in cases of failure – make sure no service is called twice unexpectedly!&lt;/li&gt;
&lt;li&gt;How can you extend the engine API to better attend to your domain needs?&lt;/li&gt;
&lt;li&gt;Do you need special auditing or some type of listener?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s understand a little bit more about how you can improve and adapt your project and the engine in the blog posts of this section:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://karinavarela.me/2020/06/16/runtime-strategy-choose-wisely/"&gt;Runtime Strategy: Choose wisely&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://karinavarela.me/2020/06/17/persisting-custom-data-configuring-external-persistence/"&gt;Persisting custom data: Configuring external persistence&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://karinavarela.me/2020/06/28/mastering-transaction-boundaries/"&gt;Mastering Transaction Boundaries&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;This section is part of the &lt;a href="https://karinavarela.me/jbpm-getting-started/"&gt;jBPM Getting Started&lt;/a&gt; series&lt;/p&gt;

</description>
      <category>uncategorized</category>
    </item>
    <item>
      <title>Dealing with Unexpected Errors in Business Processes </title>
      <dc:creator>Karina Macedo Varela</dc:creator>
      <pubDate>Mon, 01 Jun 2020 20:12:17 +0000</pubDate>
      <link>https://dev.to/kmacedovarela/dealing-with-unexpected-errors-in-business-processes-1lj9</link>
      <guid>https://dev.to/kmacedovarela/dealing-with-unexpected-errors-in-business-processes-1lj9</guid>
      <description>&lt;p&gt;During the development phase, it is expected that developers deal and treat unexpected behaviors, predictable and unpredicted errors that might happen during the execution of code. Consider the following situation:&lt;/p&gt;




&lt;p&gt;&lt;em&gt;An online traveling company named MaTrip.com sells a whole trip experience with a discount for a single package buying: flight + hotel. But each of these services is independent as they are provided by external specialized companies. In this way, MaTrip orders need to interact with the services via services integration.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The customer has bought a trip package and the flight has already been successfully booked. What should happen if the hotel application services go offline for two days? Should the flight be canceled? Should it be automatically reassigned? Should the user be contacted in order to schedule a new trip?&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;There are several business outcomes to solve this scenario, all it takes is that the developer properly handles this incidents. There are cases where only the main biz scenarios are described by the biz team, and the development team does not have enough information to implement the exception handling. In these cases, the &lt;em&gt;&lt;a href="https://karinavarela.me/2020/04/15/personas-involved-in-a-business-automation-project/"&gt;Business Analyst&lt;/a&gt;&lt;/em&gt; of the project should be involved in order to define the outcomes of these scenarios.&lt;/p&gt;

&lt;p&gt;When handling errors like this, for example, in a Java or Javascript code, the developer directly implement exception handling with try and catch; When considering the endpoint layers, developers likely uses HTTP codes to transmit a proper message to the consumer; but, how to deal with exceptions and errors when working with a &lt;strong&gt;business&lt;/strong&gt;  &lt;strong&gt;flow&lt;/strong&gt;?&lt;/p&gt;

&lt;h2&gt;
  
  
  Treating exceptions the right way
&lt;/h2&gt;

&lt;p&gt;Give a look at the following situation, considering it is at an initial development phase. The “happy path” for this trip schedule flow is:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--O5N_ZeQf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/06/error1.png%3Fw%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--O5N_ZeQf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/06/error1.png%3Fw%3D1024" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The user selects a trip (User Task); &lt;/li&gt;
&lt;li&gt;An embedded subprocess starts to handle pre-reservation; &lt;/li&gt;
&lt;li&gt;Both hotel and flight tasks are parallelized for quicker processing ( Divergent Parallel Gateway); Flight and hotel availabilities are checked (RestTask);&lt;/li&gt;
&lt;li&gt;Flight and hotel are pre-reserved (Rest Task);&lt;/li&gt;
&lt;li&gt;The process only ends steps are completed for &lt;em&gt;both&lt;/em&gt; flight and hotel( Convergent Parallel Gateway);&lt;/li&gt;
&lt;li&gt;Finally, the user confirms the trip(User Task).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There are two gaps in this process that can lead to instances aborted or failed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First uncovered scenario: The selected option (flight or hotel) is not available ( &lt;strong&gt;business exception&lt;/strong&gt; );&lt;/li&gt;
&lt;li&gt;Second uncovered scenario: One or more rest services are unavailable ( &lt;strong&gt;runtime&lt;/strong&gt;  &lt;strong&gt;exception&lt;/strong&gt; );&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Treating Business Exceptions
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Business Exceptions&lt;/strong&gt; are errors that are not technical. They are not thrown by unexpectederrors in the code itself. See some examples of business exceptions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sell a product that does not exist in the inventory;&lt;/li&gt;
&lt;li&gt;Reserve a seat in a full theater movie;&lt;/li&gt;
&lt;li&gt;Register a monthly payment twice in the same month;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These exceptions are examples of behaviors directly related to each domain exception. The recommended way to handle business exceptions would be to catch the error&lt;/p&gt;

&lt;p&gt;using error events, and then, triggering following actions to handle the error according to the business logic. By using this approach, the whole process – including the treatment of the errors – is clear for all the personas involved in the project. This will facilitate validation by the business users and further maintenance, and enhancements.&lt;/p&gt;

&lt;p&gt;Look at this process of a store which opted to follow digital transformation. They allow their customer to select products in a rich multi-channel online store; once payment is confirmed, a personal shopper manually chooses the items; finally, the delivery team takes the order to the customer address:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kEeawSvK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/06/errorhandling.png%3Fw%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kEeawSvK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/06/errorhandling.png%3Fw%3D1024" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Both tasks &lt;em&gt;Charge from credit card service&lt;/em&gt; and &lt;em&gt;reserve products from stock&lt;/em&gt; are rest tasks. Eventually, the store can run out of available products in the stock when the task &lt;em&gt;reserve&lt;/em&gt; &lt;em&gt;products from stock&lt;/em&gt; is triggered. Does this look like a business exception to you?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; Reserve product from stock when the number of available products is zero.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We just identified a business exception: NoAvailableProductException. Let’s consider that this Java REST Service treats this error like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (!product.isAvailable()){ log.error("Product is not available, throwing exception."); throw new NoAvailableProductException(Response.Status.CONFLICT);}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In this example, you can consider that NoAvailableProductException extends WebApplicationException.&lt;/p&gt;

&lt;p&gt;Now, the author of the process design knows which error the service will throw in case of a NoAvailableProductException: HTTP 409 code.&lt;/p&gt;

&lt;p&gt;javax.ws.rs.core.Response.Status.CONFLICT relates to HTTP 409.&lt;br&gt;&lt;br&gt;
As per RFC specification, this code should be used in situations where the user might be able to try the same request and possibly get a different response. The server should include information about the error in the payload for the consumers.&lt;br&gt;&lt;br&gt;
See more details in: &lt;a href="https://tools.ietf.org/html/rfc7231#section-6.5.8"&gt;https:/​/​tools.​ietf.​org/​html/​rfc7231#section-​6.5.​8&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The business automation specialist also receives the updates from the business team, and the new exception flow business scope is also defined: if the product is not available, the personal shopper should call the consumer and switch missing item for a similar one or remove it from the order. The order price will change and the new value should be charged.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scenario 1:&lt;/strong&gt; The BA specialist increments his process to deal with the business exception thrown in a specific task: He/She added a boundary intermediate catch event to the REST Task. The error code is configured on the error events properties.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1KgRG6La--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/06/errorevent.png%3Fw%3D881" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1KgRG6La--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/06/errorevent.png%3Fw%3D881" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this way, the business analyst can capture business exceptions thrown in specific tasks and provide proper handling for each scenario. But when there are too many possible errors, this approach can make the process too verbose and might affect the clarity of the flow.&lt;/p&gt;

&lt;p&gt;Considering that the same business exception can be thrown by more than one task, the author can choose to group the tasks in a subprocess and catch the exception in the parent process definition. See the following scenario.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scenario 2:&lt;/strong&gt; Tasks inside a subprocess throw an error end event, which will be catch and handled by the parent process.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6vVry6Po--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/06/erroronsubprocess.png%3Fw%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6vVry6Po--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/06/erroronsubprocess.png%3Fw%3D1024" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Another possible approach is to store the output of the processing in a process variable instead of throwing an exception. Based on the variable value, a gateway can lead to an end error event which will be handled by an event subprocess.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scenario 3:&lt;/strong&gt; Process throws an error endevent, which will be handled by an event subprocess with a starting error event.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7EnRyUgc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/06/erroreventprocess.png%3Fw%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7EnRyUgc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/06/erroreventprocess.png%3Fw%3D1024" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The author of the process should choose the proper option which better suits the business needs, worrying about the variable scopes and with the understanding and maintainability of the process. On scenario 2 for example, the variables contained inside the subprocess, will not be available during the handling of the exception in the parent process.&lt;/p&gt;

&lt;p&gt;Treating business exceptions inside a business process is considered an advanced process modeling technique, and is crucial for proper implementation of successful projects. The Business Exceptions also matters for the organization improvement and the modeling of it can also lead to the creation of business monitoring dashboards.&lt;/p&gt;

&lt;h2&gt;
  
  
  Treating Technical Exceptions
&lt;/h2&gt;

&lt;p&gt;Technical exceptions are raised within the code implementation itself and are not related to the domain flow. It can happen on script tasks, on custom code implemented on “On Entry” an “On Exit” properties of tasks and custom Work Item Handlers. See some examples of technical exception:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Can’t unmarshall an object into a specific class;&lt;/li&gt;
&lt;li&gt;Try to execute an operation in a null object;&lt;/li&gt;
&lt;li&gt;Try to cast an object which cannot be cast;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Integration with external components should be handled by external services and not by treated by the process design itself&lt;/p&gt;

&lt;p&gt;This recommendation is based on the fact that processes that fail with technical exceptions are unrecoverable. To know more about technical error exception handling, refer to the official documentation:  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.jboss.org/jbpm/release/7.21.0.Final/jbpm-docs/html_single/#_technical_exceptions"&gt;https:/​/​docs.​jboss.​org/​jbpm/​release/latest/​jbpm-​docs/​html_&lt;/a&gt; &lt;a href="https://docs.jboss.org/jbpm/release/7.21.0.Final/jbpm-docs/html_single/#_technical_exceptions"&gt;single/​#_​technical_​exceptions&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;These kinds of errors can and should be avoided by leveraging the usage of custom code to necessary scenarios, and by increasing the usage of the provided native features. Exceptions raised on script tasks, cannot be caught and handled by the error events demonstrated on the “Business Exceptions” examples.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This blog post is part of the fourth section of the &lt;a href="https://karinavarela.me/jbpm-getting-started/"&gt;jBPM Getting started&lt;/a&gt; series&lt;/em&gt;:&lt;br&gt;&lt;br&gt;
&lt;a href="https://karinavarela.me/effective-modeling-integration-and-delivery/"&gt;Effective modeling, Integration and Delivery&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>processes</category>
    </item>
    <item>
      <title>How to configure notification for Human Task in jBPM</title>
      <dc:creator>Karina Macedo Varela</dc:creator>
      <pubDate>Sat, 30 May 2020 14:24:14 +0000</pubDate>
      <link>https://dev.to/kmacedovarela/how-to-configure-notification-for-human-task-in-jbpm-4gfg</link>
      <guid>https://dev.to/kmacedovarela/how-to-configure-notification-for-human-task-in-jbpm-4gfg</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Great post from Sudhish Nair, an expert on process and rules automation.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iyMH1i1Z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://2.gravatar.com/avatar/b1fac0ee1137de69c5d8164e792d782f%3Fs%3D32%26d%3Didenticon%26r%3DG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iyMH1i1Z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://2.gravatar.com/avatar/b1fac0ee1137de69c5d8164e792d782f%3Fs%3D32%26d%3Didenticon%26r%3DG" alt=""&gt;&lt;/a&gt;&lt;a href="https://techblogtoprogram.wordpress.com/2020/05/29/how-to-configure-notification-for-human-task-in-jbpm/"&gt;TechBlogs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;jBPM&lt;/strong&gt; provides options to configure notification emails to be send to any user if the human task is not started or not completed.&lt;/p&gt;

&lt;p&gt;We will start with configuring &lt;em&gt;JavaMail&lt;/em&gt; sessions via &lt;em&gt;JNDI&lt;/em&gt; so that infrastructure for mail is handled.&lt;/p&gt;

&lt;p&gt;We would be using “ &lt;strong&gt;jbpm-server-7.37.0.Final-dist&lt;/strong&gt; ” version for this example.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configure Mail Session in wildfly
&lt;/h2&gt;

&lt;p&gt;In the standalone configuration for &lt;em&gt;jBPM&lt;/em&gt; we need add below configurations.&lt;/p&gt;

&lt;h4&gt;
  
  
  Configure Socket binding for smtp-port
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        &amp;lt;outbound-socket-binding name="mail-notification-smtp"&amp;gt;
            &amp;lt;remote-destination host="smtp.gmail.com" port="465"/&amp;gt;
        &amp;lt;/outbound-socket-binding&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;host&lt;/strong&gt; -: host name of SMTP server&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;port&lt;/strong&gt; -: port no of SMTP server.&lt;/p&gt;

&lt;h4&gt;
  
  
  Configure Mail-Session in Mail subsystem
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;            &amp;lt;mail-session name="notification" jndi-name="java:/notificationMailSession" from="youremailid@gmail.com"&amp;gt;
                &amp;lt;smtp-server outbound-socket-binding-ref="mail-notification-smtp" ssl="true" username="youremailid@gmail.com" password="yourPassw0rd"/&amp;gt;
            &amp;lt;/mail-session&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;from&lt;/strong&gt; -: From address for your emails (Valid email account on SMTP server).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;username&lt;/strong&gt; -: username for the email account&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;password&lt;/strong&gt; -: password for the email account.&lt;/p&gt;

&lt;p&gt;Add below system property to standalone.xml file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    &amp;lt;system-properties&amp;gt;      
       &amp;lt;property name="org.kie.mail.session" value="java:/notificationMailSession"/&amp;gt;
    &amp;lt;/system-properties&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Configure user info for Human…
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://techblogtoprogram.wordpress.com/2020/05/29/how-to-configure-notification-for-human-task-in-jbpm/"&gt;View original post&lt;/a&gt; 423 more words&lt;/p&gt;

</description>
      <category>uncategorized</category>
    </item>
    <item>
      <title>jBPM: Asynchronous Execution</title>
      <dc:creator>Karina Macedo Varela</dc:creator>
      <pubDate>Sat, 23 May 2020 02:43:58 +0000</pubDate>
      <link>https://dev.to/kmacedovarela/jbpm-asynchronous-execution-1d55</link>
      <guid>https://dev.to/kmacedovarela/jbpm-asynchronous-execution-1d55</guid>
      <description>&lt;p&gt;By default, the flow of tasks is executed in a synchronous way: all tasks will be treated one after the other, by a single thread. This being said, if a process contains, for example, four service calls – where each call lasts around 30 seconds – this process execution will run – and allocate JVM, CPU, etc.. – for long two minutes. And worse, the caller of this instance has to wait for two minutes until getting a response. In scenarios using default configurations, this situation results in a timeout exception.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;“But my process is quite simple and it should be faster. The problem is the legacy services we have to interact with. How can we improve this process design to achieve better performance, execution and resource consumption&lt;/em&gt;?&lt;em&gt;“&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The answer is: &lt;em&gt;Use asynchronous capabilities when you have long-running tasks or when you want&lt;/em&gt; &lt;em&gt;to define transaction boundaries (Transction Boundaries will be explained in upcoming posts).&lt;/em&gt; In this way, you can delegate the processing of this work unit to a different thread, while the process goes on with the execution.&lt;/p&gt;

&lt;p&gt;Here are some possible ways to use asynchronous execution: async tasks, jobs, timers events. The timer and the async tasks can be included in a process diagram. The jobs, differently, are scheduled – registered – within Kie Server to be executed recurrently or not, based on the determined agenda.&lt;/p&gt;

&lt;p&gt;Additional Information about timer events and its possible configuration can be found at &lt;a href="https://karinavarela.me/?p=342"&gt;https://karinavarela.me/2019/06/07/jbpm7-quicktips-timers/&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The tasks (WI) provided by jBPM have a configurable “Async” property. When a task is marked async:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The task will create a wait-state on the process;&lt;/li&gt;
&lt;li&gt;The engine does not wait until this task finishes to trigger the next task;&lt;/li&gt;
&lt;li&gt;This task execution will be handled in a different thread;&lt;/li&gt;
&lt;li&gt;This task will be automatically retried by the Executor in case of failure (read the Jobs section for more details).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s understand the Job feature available in jBPM which also allows asynchronous execution.&lt;/p&gt;

&lt;p&gt;A &lt;em&gt;job&lt;/em&gt;, simply saying, is an independent code unit that is called based on a schedule and is executed asynchronously, in background. jBPM has a generic environment for the execution of these Commands, where the Job Executor is responsible for triggering the timer events, async tasks and executing scheduled jobs.&lt;/p&gt;

&lt;p&gt;The job executor is an out-of-the-box jBPM component responsible for resuming process executions asynchronously. It can be configured to attend custom needs from each environment. Possible configuration about job executor and details about native jobs can be found at the official documentation and additional information is available at.&lt;/p&gt;

&lt;p&gt;The job executor is an out-of-the-box jBPM component responsible for resuming process executions asynchronously. It can be configured to attend custom needs from each environment. Possible configuration about job executor and details about native jobs can be found at the official documentation and additional information is available at &lt;a href="https://karinavarela.me/?p=347"&gt;https://karinavarela.me/2019/06/07/jbpm7-quicktips-jobs&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;The Job Executor can properly manage jobs in a clustered environment and guarantee jobs are triggered only once, even if Kie Server runs in a multiple servers architecture. Jobs are persisted and maintained in the database.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jI0MoE_Z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/05/job-lifecycle.png%3Fw%3D582" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jI0MoE_Z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/05/job-lifecycle.png%3Fw%3D582" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On executor start, all jobs are always loaded, regardless if there are one or more instances in the environment. That makes sure all jobs will be executed, even in cases where their fire time has already passed or was scheduled by other executor instance.&lt;/p&gt;

&lt;p&gt;Jobs are always stored in DB, no matter what trigger mechanism is used to execute the job (JMS or thread pool). The table RequestInfo stores the jobs that need to be executed. In the expected cycle jobs should be queued, run, and completed. Additionally, it can go through the statuses represented in this diagram.&lt;/p&gt;

&lt;p&gt;By default, a single thread pool is used, and services will be retried three times in case of failures. When the executor starts, the following log is displayed in the application server with the current configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;23:56:58,050 INFO [org.jbpm.executor.impl.ExecutorImpl] (EJB default - 1) Starting jBPM Executor Component ...- Thread Pool Size: 1-  Retries per Request: 3 -  Load from storage interval: 0 SECONDS (if less or equal 0 only initial sync with storage)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Native jobs, custom jobs, and async tasks execution are performed by the Executor which has the characteristics above. A good example of jobs usage in jBPM is to schedule jobs to maintain a good environment health by constantly cleaning the old database audit data.&lt;/p&gt;

&lt;p&gt;Besides supporting the ops team by keeping a healthy environment, making good use of the async behavior and its capabilities lead the dev and BA team to perform a better process design. Additionally, it supports the lifecycle of running processes by providing good visibility of the errors that happened during process execution and allows the possibility of solving the unexpected happenings.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This blog post is part of the fourth section of the &lt;a href="https://karinavarela.me/jbpm-getting-started/"&gt;jBPM Getting started&lt;/a&gt; series&lt;/em&gt;:&lt;br&gt;&lt;br&gt;
&lt;a href="https://karinavarela.me/effective-modeling-integration-and-delivery/"&gt;Effective modeling, Integration and Delivery&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>general</category>
      <category>processes</category>
      <category>async</category>
      <category>jobs</category>
    </item>
    <item>
      <title>jBPM: User Tasks and Forms</title>
      <dc:creator>Karina Macedo Varela</dc:creator>
      <pubDate>Sat, 23 May 2020 02:37:10 +0000</pubDate>
      <link>https://dev.to/kmacedovarela/jbpm-user-tasks-and-forms-229m</link>
      <guid>https://dev.to/kmacedovarela/jbpm-user-tasks-and-forms-229m</guid>
      <description>&lt;p&gt;User Tasks allow the interaction of humans with a set of automated tasks. In this way, a series of automatic tasks can be triggered before – providing input for – human decisions, and the output of the user task can then be used to define further actions of a flow.&lt;/p&gt;

&lt;p&gt;User tasks have a more elaborate lifecycle than other activity tasks. The lifecycle of a Human Task involves &lt;strong&gt;states&lt;/strong&gt; and &lt;strong&gt;actions&lt;/strong&gt;. The &lt;strong&gt;actions&lt;/strong&gt; that can be used to interact with the human task and change its &lt;strong&gt;state&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The same actions can be easily identified in both Kie Rest API (detailed in the /kie-server/docs URL), as in Java Kie API. &lt;a href="https://github.com/kiegroup/jbpm/blob/master/jbpm-services/jbpm-services-api/src/main/java/org/jbpm/services/api/admin/ProcessInstanceAdminService.java"&gt;https://github.com/kiegroup/jbpm/blob/master/jbpm-services/jbpm-services-api/src/main/java/org/jbpm/services/api/admin/ProcessInstanceAdminService.java&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Considering the lifecycle of a human task, let’s talk about some possibilities that can be achieved out-of-the-box by using a user task. Here is hiring process an example of a process that has a different ending based on a human decision:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zOcr4wDk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/05/humantaskprocess.png%3Fw%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zOcr4wDk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/05/humantaskprocess.png%3Fw%3D1024" alt=""&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;Once started, the candidate should send his curriculum vitae (first user task). The next step is that someone from the &lt;strong&gt;Human Resource team&lt;/strong&gt; picks this task and do an analysis over the candidate curriculum. Based on this analysis, this person should decide whether this is or not an appropriate candidate for the role. This decision is stored in a &lt;strong&gt;process&lt;/strong&gt; &lt;strong&gt;variable&lt;/strong&gt;, that will be evaluated by the exclusive gateway, defining if the candidate was reproved (send an email) or approved (start hiring processes).&lt;/p&gt;

&lt;p&gt;Let’s analyze some important concepts based on this example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The process definition says that the Validate Candidate Profile should be done by someone from the “Human Resources” team. &lt;em&gt;This task is assigned to a&lt;/em&gt; &lt;em&gt;group.&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;This task has an &lt;strong&gt;SLA&lt;/strong&gt; , which determines 5 days as maximum expected duration to the &lt;strong&gt;HR group –&lt;/strong&gt; team – to finish this task. &lt;em&gt;The SLA can also be an expression which&lt;/em&gt; &lt;em&gt;holds a process variable like&lt;/em&gt; #{determinedDueDate} &lt;em&gt;.&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;User task variables can be manipulated by the human that owns the task. This is how the process variables are updated by humans involved in this execution:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--y5zzqJY7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/05/humantaskvariables.png%3Fw%3D584" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--y5zzqJY7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/05/humantaskvariables.png%3Fw%3D584" alt=""&gt;&lt;/a&gt;The process contains two variables named CV and hr_approval. The user that interacts with this task, has access to the variables specified in “&lt;em&gt;Data Inputs and&lt;/em&gt; &lt;em&gt;Assignments&lt;/em&gt;“, in this case, in_CV. The user can interact with this task in many ways – a form in a web application, mobile app, business central, google home, etc – in whichever way, in the end, this interaction will be converted into a request submitted to the engine.&lt;/p&gt;

&lt;p&gt;When the user completes this task, his outputs with the answer are stored into &lt;em&gt;“Data&lt;/em&gt; &lt;em&gt;Outputs and Assignments&lt;/em&gt;” fields, in this case,out_approval_._ This simple &lt;strong&gt;boolean&lt;/strong&gt; which tells if the candidate was approved or not, will be automatically assigned to the process variable hr_approval in order to be used in other steps of this hiring flow.&lt;/p&gt;

&lt;h3&gt;
  
  
  Interacting with User Tasks via Business Central
&lt;/h3&gt;

&lt;p&gt;A client application with a customized layout can interact with human tasks via the available APIs, but for now, let’s see how to interact with this task using business central. Business Central provides a Task Inbox, accessible via the menu.&lt;/p&gt;

&lt;p&gt;It is required that the &lt;strong&gt;user belongs&lt;/strong&gt; to the HR &lt;strong&gt;group&lt;/strong&gt; , otherwise, he is not a potential owner and won’t be able to visualize the tasks. When the user opens the inbox, he/she will see the list of tasks which he/she is a potential owner:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RWL2t_3P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/05/taskinbox.png%3Fw%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RWL2t_3P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/05/taskinbox.png%3Fw%3D1024" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are two tasks in this list, because two candidates applied and we have two running process instances. One of the tasks is currently in progress and being executed by a user named &lt;em&gt;karina&lt;/em&gt;. Another task is “Ready” to be executed and has no owner. Notice the possible actions for this task: &lt;em&gt;Claim&lt;/em&gt; and &lt;em&gt;Claim and Work.&lt;/em&gt; But what exactly does this mean?&lt;/p&gt;

&lt;p&gt;In order to understand this, we should go back to the _ &lt;strong&gt;WS-HT specification&lt;/strong&gt; _ and the lifecycle of a human task.&lt;/p&gt;

&lt;h3&gt;
  
  
  Human Task Lifecycle
&lt;/h3&gt;

&lt;p&gt;According to the WS-HT specification, human tasks can be in the following &lt;strong&gt;states&lt;/strong&gt; :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Created, Ready, Reserved, In Progress, Suspended, Completed, Failed, Error, Exited or Obsolete. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And, they can the possible &lt;strong&gt;actions&lt;/strong&gt; can be used upon the human task:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;suspend, resume, forward, revoke, claim, start, stop, delegate, complete, exit, skip, nominate, release. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;jBPM provides Java client API and REST API available to interact with the task and move it through states. Check these &lt;strong&gt;states&lt;/strong&gt; and &lt;strong&gt;actions&lt;/strong&gt; represented on the following diagram:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--j7lPoQLv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/05/wsht-diagram.png%3Fw%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--j7lPoQLv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/05/wsht-diagram.png%3Fw%3D1024" alt=""&gt;&lt;/a&gt;jBPM implements an easy and comprehensible flow based on Web Services Human Task specification (a.k.a WS-HT Spec). &lt;br&gt;&lt;a href="http://download.boulder.ibm.com/ibmdl/pub/software/dw/specs/ws-bpel4people/WS-HumanTask_v1.pdf" rel="noreferrer noopener"&gt;http:/​/​download.​boulder.​ibm.​com/​ibmdl/​pub/​software/​dw/​specs/​ws-bpel4people/​WS-​HumanTask_​v1.​pdf&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But how is this translated into a real example? Let’s get back to our hiring process, in the point when the candidate finishes the first task, and the second task is activated:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The engine &lt;strong&gt;creates&lt;/strong&gt; the second human task “Validate Candidate Profile”;&lt;/li&gt;
&lt;li&gt;Once the engine finishes this creation, the task will be &lt;strong&gt;ready&lt;/strong&gt; for users of this group;&lt;/li&gt;
&lt;li&gt;All the members from this group (HR) are &lt;strong&gt;potential owners&lt;/strong&gt; and consequently, can see this task, but only one at a time can &lt;strong&gt;claim&lt;/strong&gt; it, be the owner of it.&lt;/li&gt;
&lt;li&gt;Once &lt;strong&gt;claimed&lt;/strong&gt; , this task will be &lt;strong&gt;reserved&lt;/strong&gt; for this user, and will no longer be part of the list presented to the group.&lt;/li&gt;
&lt;li&gt;The user now has the option to &lt;strong&gt;start&lt;/strong&gt; actually working in this task;&lt;/li&gt;
&lt;li&gt;The user finishes the analysis and can &lt;strong&gt;complete&lt;/strong&gt; the task, providing the required data.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As showed above, a whole lifecycle of management of user interactions is already provided out-of-the-box by jBPM. The user role also matters. It is directly related to the actions that can be executed over a task.&lt;/p&gt;

&lt;h3&gt;
  
  
  Form Modeler
&lt;/h3&gt;

&lt;p&gt;We are now going to enhance the human interaction by using &lt;strong&gt;forms.&lt;/strong&gt; The Form Modeler is a component from Business Central which allows the Business Automation Specialist to create forms in a low-code manner. It significantly shortens the time spent into forms creation.&lt;/p&gt;

&lt;p&gt;These forms are .frm files delivered as part of the kjar and can be also consumed via rest and embedded into custom client applications. This makes it easy to consume the whole process from a single point, without propagating changes to other services and impacting their functioning.&lt;/p&gt;

&lt;p&gt;See how simple it is to create a form for the hiring process: once all the input and output variables are properly defined for user tasks, look for the option &lt;em&gt;Generate all forms in&lt;/em&gt; the process designer toolbar.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--r7NR0vCv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/05/generateallforms.png%3Fw%3D207" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--r7NR0vCv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/05/generateallforms.png%3Fw%3D207" alt=""&gt;&lt;/a&gt;&lt;br&gt;This option will automatically create one form for each human task present in this process definition with all the fields configured as input/output assignment variables.&lt;/p&gt;

&lt;p&gt;All the forms are made available and are accessible via the project lateral toolbar, or in the project main page. The lateral toolbar shows the assets categorized by type.&lt;/p&gt;

&lt;p&gt;By clicking on one of the forms, in this example, “ValidateCV-taskform”, the form modeler will open with the generated form. This generated form has a proper field for every variable configured on the input/output assignment variables of the human task. It takes in consideration the variable class type, so for example, for the document it provided a file upload component. For the boolean field, it provided a checkbox.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--L-5wn0Jt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/05/generatedform.png%3Fw%3D1024" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--L-5wn0Jt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/05/generatedform.png%3Fw%3D1024" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All the BA specialist needs to do is adjust the form according to the domain knowledge and requirements. By clicking on the three dots on the right corner, of each field, options for editing and removing are available. To reorganize items, simply drag and drop them. See the edition of the checkbox for a more appropriate label:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--R_DG-HCq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/05/formedit.png%3Fw%3D622" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--R_DG-HCq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/05/formedit.png%3Fw%3D622" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The HTML field type editor is a rich text editor to give more flexibility to the user. There is a whole set of components to be used into the form creation. Also, if the user adds new variables or wants to remove them, they will be displayed in the “&lt;em&gt;Model&lt;/em&gt; &lt;em&gt;Fields&lt;/em&gt;” tab to be used dragged into the form is necessary.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MeWyhzH6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/05/screen-shot-2019-05-16-at-00.33.27.png%3Fw%3D390" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MeWyhzH6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/05/screen-shot-2019-05-16-at-00.33.27.png%3Fw%3D390" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And this is how, after three minutes, a whole new reusable form got created without much coding:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--P2MmQUSu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/05/form-1.png%3Fw%3D809" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--P2MmQUSu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://karinavarelame.files.wordpress.com/2020/05/form-1.png%3Fw%3D809" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In order to test it, the project needs to be deployed to kie server. Once deployed, when the task is activated, the results can be visualized via business central when clicking on the task. The same form could be embedded into a custom client application.&lt;/p&gt;

&lt;p&gt;If you want more information about the form modeler, including a running sample, please refer to this blog post: &lt;a href="https://karinavarela.me/2020/02/05/jbpm-form-modeler/"&gt;https://karinavarela.me/2020/02/05/jbpm-form-modeler/&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;The form can be obtained in two ways:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; XML format with plain details:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;For process form: GET /server/containers/{containerId}/forms/processes/{processId}&lt;/li&gt;
&lt;li&gt;For task form: GET /server/containers/{containerId}/forms/tasks/{taskInstanceId}&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;Rendered format&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;For process forms: GET /server/containers/{containerId}/forms/processes/{processId}/content&lt;/li&gt;
&lt;li&gt;For case forms: GET /server/containers/{containerId}/forms/cases/{caseDefId}/content&lt;/li&gt;
&lt;li&gt;For task forms: GET /server/containers/{containerId}/forms/tasks/{taskInstanceId}/content&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;This blog post is part of the fourth section of the &lt;a href="https://karinavarela.me/jbpm-getting-started/"&gt;jBPM Getting started&lt;/a&gt; series&lt;/em&gt;:&lt;br&gt;&lt;br&gt;
&lt;a href="https://karinavarela.me/effective-modeling-integration-and-delivery/"&gt;Effective modeling, Integration and Delivery&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>processes</category>
      <category>tools</category>
      <category>forms</category>
      <category>jbpm</category>
    </item>
  </channel>
</rss>
