Sunday, May 9, 2021

How to load data dynamically in ListBox of Task Form or Process Form in jBPM

 jBPM provides an option to populate ListBox dynamically in Task Form or Process Form.


We would be using "jBPM-7.33.0.Final" version for this example.

We can achieve this using Data Providers. Specifically, we need to create a class that implements 
"org.kie.workbench.common.forms.dynamic.model.config.SelectorDataProvider" Interface.

When the Field type attribute for the form field is configured as ListBox we have to implement a custom data provider class that implements SelectorDataProvider Interface.

The implementation class of SelectorDataProvider needs to implement below two methods from the SelectorDataProvider.

1.  public String getProviderName()
      - It returns the Provider name of the implementation class which will be used in the attribute "Data Provider" of the ListBox Form field.

2. public SelectorData getSelectorData(FormRenderingContext context)
      - Using this method we can add the values which we need to load or display in the ListBox form field of Task Form or Process Form.

Implementation Class for SelectorDataProvider


package org.jbpm.formModeler.examples.providers;
import java.util.HashMap;
import java.util.Map;

import javax.enterprise.context.Dependent;

import org.kie.workbench.common.forms.dynamic.model.config.SelectorData;
import org.kie.workbench.common.forms.dynamic.model.config.SelectorDataProvider;
import org.kie.workbench.common.forms.dynamic.service.shared.FormRenderingContext;

@Dependent
public class MyDataSelectorProvider implements SelectorDataProvider {

    public String getProviderName() {
        return "myProvider";
    }

    public SelectorData getSelectorData(FormRenderingContext arg0) {
        SelectorData<String> selectorData = new SelectorData<String>();

        Map<String, String> states = new HashMap<String, String>();

        states.put("Delhi", "Delhi");
states.put("Maharashtra", "Maharashtra");
states.put("Gujrat", "Gujrat");
selectorData.setValues(states);
return selectorData; } }
We have to create an empty jBPM maven project in IDE of your choice and need to put this class inside that project.

Here is the screenshot of the project structure.



Create a file "ErraiAPP.properties" inside the META-INF directory of the project and add below property inside this file without quotes.

"errai.marshalling.mappingAliases=org.jboss.errai.databinding.client.MapBindableProxy->java.util.Map"

Create an empty beans.xml file inside META-INF Directory.

Once above steps finished building the project using command "mvn clean install" and it should generate the .jar file inside the target directory.

Copy-paste the generated jar from target directory to location "business-central.war/WEB-INF/lib" directory. 

We also need errai data binding jar in the lib directory so place the "errai-data-binding-${VERSION}.Final.jar" to location "business-central.war/WEB-INF/lib"

Create a project if not created in the business central and add the form asset and drag the ListBox on the created form.



 

Add the properties for the ListBox like name, Label, and most importantly the Field Binding and map the appropriate field binding to the appropriate Data Objects or other variables.



Download the project from Business Central to your file system by clicking on any asset and then click the setting gear icon in the project explorer at the top right corner.





Once the project is downloaded in the local file system go to $PROJECT_NAME/src/main/resources/path/to/form/StateCityListForm.frm file and open this .frm file in any text editor and search for property "dataProvider" which is empty and it doesn't have value. You have to give the value of the custom data provider class which we have created above. Please note that you have to give fully qualified class name.

So, the dataProvider property should look like in .frm file:

"dataProvider" : "org.jbpm.formModeler.examples.providers.MyDataSelectorProvider",

After the above modification save it and again we have to reimport the project in the Business Central.

Go to the project folder where your pom.xml is located and execute below git commands

   - git init .
   - git add .
   - git commit -m "commit message"

After that copy the path till $PROJECT_NAME directory and go to the Business Central and import the project by Clicking the import project Option from the dropdown.



After clicking the import project option one popup window would open paste your project location inside the text box and click on the import button.




Once the project is imported build and deploy it and create a process instance of the process and you should be able to see the data dynamically loaded inside the ListBox of the Process or Task Form whichever you have created.




Please note that I have used Wildfly Application Server 14 also known as JBoss EAP for jBPM installation and deployment. 

Saturday, May 8, 2021

File custom field type in jBPM6

 https://github.com/kiegroup/jbpm-form-modeler/tree/6.2.x/jbpm-form-modeler-sample-custom-types/jbpm-form-modeler-custom-file-type

Implement your own form renderer for KIE Server

 

As it was described in this article, KIE Server now provides form renderers for process and task forms built in jBPM Console (aka workbench). Out of the box there are two renderers provided

  • based on PatterFly to provide same look and feel as entire jBPM tooling - it's the default renderer
  • based on Bootstrap to provide a simple alternative that utilises well established framework for building web and mobile UIs
This obviously won't cover all possible needs of users and thus the renderers are actually pluggable. In this article we build a custom one from scratch to illustrate what it takes to have your own.

Create project with dependencies

First of all, a new maven project needs to be created. It should be most basic project with packaging jar. Then let's add required dependencies to pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.kie.server.samples</groupId>
  <artifactId>custom-form-renderer</artifactId>
  <version>1.0.0</version>
  <name>Custom Form Renderer</name>
  
  <properties>
    <version.org.kie>7.14.0.Final</version.org.kie>
  </properties>
  
  <dependencies>
    <dependency>
      <groupId>org.kie.server</groupId>
      <artifactId>kie-server-services-jbpm-ui</artifactId>
      <version>${version.org.kie}</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>
</project>

Create configuration folders

Create folders in the project that will configure the renderer - all should be done src/main/resources
  • form-templates-providers - folder that will contain templates, css and java script files used to render the form
  • META-INF/services/org.kie.server.services.jbpm.ui.form.render.FormRenderer - an empty file that will be used as discovery mechanism to find and register the renderer - it will be edited a bit later to provide actual implementation details

Create form renderer implementation

In src/main/java create a class (e.g. org.kie.server.samples.CustomFormRenderer) that will extend org.kie.server.services.jbpm.ui.form.render.AbstractFormRenderer and implement the required methods 
  • getName - provide the name of the template that shall be used as reference when rendering
  • loadTemplates - main implementation that loads different types of templates to be used by renderer
  • default constructor
IMPORTANT: this new class must be configured as the implementation of the renderer so add its fully qualified class name into 
META-INF/services/org.kie.server.services.jbpm.ui.form.render.FormRenderer

There are several types of templates that renderer must provide (and load on startup)
  • master - main template that builds the HTML page
  • header - header template that creates header of the form
  • form-group - form input fields template
  • case-layout - layout for case forms
  • process-layout - layout for process forms
  • task-layout - layout for user task forms
  • table - table to be build for multi subforms
The easiest way is to base your customisation on top of the out of the box templates (either patternfly or bootstrap). In this example I will use bootstrap templates that can be found here.

Copy all resources from the linked directory into 
src/main/resources/form-templates-providers/custom

and then implement the loadTemplates method of the CustomFormRenderer class
package org.kie.server.samples;

import org.kie.server.services.jbpm.ui.form.render.AbstractFormRenderer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class CustomFormRenderer extends AbstractFormRenderer {
    
    private static final Logger logger = LoggerFactory.getLogger(CustomFormRenderer.class);

    public CustomFormRenderer() {
        super(null,  null);
    }
    
    public CustomFormRenderer(String serverPath, String resources) {
        super(serverPath, resources);
    }
    
    public String getName() {
        return "custom";
    }

    @Override
    protected void loadTemplates() {
        loadTemplate(MASTER_LAYOUT_TEMPLATE, this.getClass().
        getResourceAsStream("/form-templates-providers/custom/master-template.html"));
        loadTemplate(PROCESS_LAYOUT_TEMPLATE, this.getClass().
        getResourceAsStream("/form-templates-providers/custom/process-layout-template.html"));
        loadTemplate(TASK_LAYOUT_TEMPLATE, this.getClass().
        getResourceAsStream("/form-templates-providers/custom/task-layout-template.html"));
        loadTemplate(FORM_GROUP_LAYOUT_TEMPLATE, this.getClass().
        getResourceAsStream("/form-templates-providers/custom/input-form-group-template.html"));
        loadTemplate(HEADER_LAYOUT_TEMPLATE, this.getClass().
        getResourceAsStream("/form-templates-providers/custom/header-template.html"));
        loadTemplate(CASE_LAYOUT_TEMPLATE, this.getClass().
        getResourceAsStream("/form-templates-providers/custom/case-layout-template.html"));
        loadTemplate(TABLE_LAYOUT_TEMPLATE, this.getClass().
        getResourceAsStream("/form-templates-providers/custom/table-template.html"));
        
        logger.info("Custom Form renderer templates loaded successfully.");
    }

}

Customise your templates

Since the templates where copied from another renderer we need to customise it, let's start with master template. Open it and replace ${serverPath}/bootstrap with ${serverPath}/custom  
This will ensure that our customised files will be loaded.

Make any additional changes to the master template as needed. I will just add custom text next to header.

Master template is the place where you can add additional scripts or stylesheets. There is main js file called kieserver-ui.js that provide all the logic required to manage and submit forms. It also includes validation, so in case you need extensions to that logic consider to create new file with your changes and replace the location of it to point to your new file.

Make additional customisation to other templates as needed.

Build and deploy renderer to KIE Server

Implementation is completed so now it's time to build the project and deploy to KIE Server.
  • Build the project with maven - mvn clean package
  • Deploy the project to KIE Server by coping the jar file to kie-server.war/WEB-INF/lib
Start the server and take advantage of your custom renderer by using following URL that works for one of the sample projects - Evaluation (make sure to deploy it before using the renderer).

http://localhost:8080/kie-server/services/rest/server/containers/evaluation/forms/processes/evaluation/content?renderer=custom

http://localhost:8080/kie-server/services/rest/server/containers/evaluation/forms/tasks/1/content?renderer=custom

As you can see new renderer is fully operational and customised to your needs.

That's it, you have now your custom form renderer. The sample described in this article can be found in GitHub.
 
Ref: https://mswiderski.blogspot.com/2018/11/implement-your-own-form-renderer-for.html

Let's embed forms ... rendered by KIE Server

 jBPM comes with rather sophisticated form modeller that allows to graphically build forms for processes and tasks. These forms can then be used to interact with process engine to start new instances or complete user tasks.

One of the biggest advantages of using forms built in workbench is that they share the same life cycle as your business assets (processes and user tasks). By that they are versioned exactly the same way - so if you have another version of a process that requires more information to start you simply create new version of the project and make changes to both process definition and form. Once deployed you can start different versions of the process using dedicated forms.

Although to be able to take advantage of these forms users have to be logged into workbench as the only way to render the content is ... through workbench itself. These days are now over ... KIE Server provides pluggable renderers for forms created in workbench. That means you can solely interact with kie server to perform all the needed operations. So what does this brings:

  • renders process forms - used to start new instances
  • renders case forms - used to start new case instances - includes both data and role assignments
  • renders user task forms - used to interact with user tasks - includes life cycle operations

Worth noting is that rendered forms are fully operational, meaning they come with buttons to perform all the operations that are based on the context - e.g. if user task is in in progress state there are buttons to stop, release, save and complete.

Here are few screenshots on how the forms look like, these are taken from the sample projects that come out of the box with jBPM distribution



Evaluation start process form

Mortgage start process form



IT Orders start case form
As it was mentioned, form renderers are pluggable and out of the box there are two implementations

  • based on PatternFly - this is the default renderer that keeps the look and feel consistent with workbench
  • based on Bootstrap
Renderers can be switched per each form rendering request by simply appending query parameter
?renderer=patternfly or ?renderer=boostrap if not given patternfly is the default one.

Here are few examples of the REST endpoints that illustrate how to get these forms rendered

http://localhost:8080/kie-server/services/rest/server/containers/evaluation/forms/processes/evaluation/content
http://localhost:8080/kie-server/services/rest/server/containers/evaluation/forms/tasks/1/content


http://localhost:8080/kie-server/services/rest/server/containers/mortgage-process/forms/processes/Mortgage_Process.MortgageApprovalProcess/content
http://localhost:8080/kie-server/services/rest/server/containers/mortgage-process/forms/tasks/2/content


http://localhost:8080/kie-server/services/rest/server/containers/itorders/forms/cases/itorders.orderhardware/content
http://localhost:8080/kie-server/services/rest/server/containers/itorders/forms/tasks/3/content

Note that containers are given as alias so that brings in additional benefits when working with forms and multiple project versions.

And at the end few short screen casts showing this feature in action

 

Ref: https://mswiderski.blogspot.com/2018/10/lets-embed-forms-rendered-by-kie-server.html

Friday, May 7, 2021

Wednesday, April 28, 2021

Enable SSL Trace in IBM HTTP server

 Step 1: Stop IBM HTTP Server.

Step 2: Turn on IBM HTTP Server verbose logging for SSL

Append the LogLevel directive to httpd.conf:

  • IBM HTTP Server 9.0 and later:

LogLevel debug ibm_ssl:trace8

  • IBM HTTP Server 8.5.5 and earlier:

LogLevel debug

Append SSLTrace directive to httpd.conf (no argument)

SSLTrace

Step 3: Start HTTP Server.

Ref: https://www.ibm.com/support/pages/mustgather-ibm-http-server-ssl-handshake-and-configuration-problems

List all supported ciphers if ibm http server.

 Use the below command to list all support ciphers

bin/apachectl -t -f path/to/httpd.conf -DDUMP_SSL_CIPHERS

Install and use xorg-server on macOS via Homebrew

  The instructions to install and use xorg-server on macOS via Homebrew: Install Homebrew (if you haven't already): /bin/bash -c ...