Sunday, May 9, 2021

BPM Tutorial: Quy trình xin nghỉ phép (Phần 1 - Model the process)

 Với BPM Tutorial: Quy trình xin nghỉ phép, bạn sẽ bước đầu tiếp cận với cách thức mô hình hóa một quy trình công việc trên giấy tờ sang một quy trình đơn giản bằng phần mềm. Dựa trên bộ công cụ Process Desiger - Workflow Center của hãng IBM.

Xem bài viết gốc tại https://viblo.asia/p/bpm-tutorial-quy-trinh-xin-nghi-phep-phan-1-model-the-process-XL6lA2qB5ek

PHẦN I: MODEL THE PROCESS

Mục đích bài học:

  • Tạo được Process Application
  • Thêm các Team bằng cách thêm Lane và gán team vào Process
  • Thêm Activities, events, và gateways vào Process
  • Thêm timer itermediate event vào Process
  • Tạo biến cho Process
  • Tạo Snapshot đầu tiên

Yêu cầu về ứng dụng: Bạn phải có Process Designer (ver 8.6.0) cài đặt trên server có sẵn và đăng nhập bằng trình duyệt web (Tối ưu nhất cho Firefox)

1. Tạo Process Application

Đầu tiên bạn phải tạo Process application trước khi bạn có thể làm bất cứ điều gì, Process Application được lưu trên Process Center repository.

  1. Đăng nhập vào Process Center 
  2. Click Create New Process App 
  3. Điền vào thông tin sau: 
  4. Click Create, để mở process, Click Open in Designer. Sẽ hiển thị ra Process App Settings 

2. Tạo Process

Trong Library (tab chọn 3 dấu gạch ngang), click chọn Processes và chọn tiếp Process và gõ "Absence Management". Màn hình process diagram được tạo ra như sau: 

STTAreaChi tiết
1Main toolbarTruy cập Designer, Inspector, Optimizer và Process Center. Nút save tất cả các edit, tạo snapshot, help...
2LibraryTruy cập đến các library item cho process hiện tại
3Main canvasKhu vực bạn có thể mình họa process. Mỗi process được khởi tạo tự động có một start event và end event. Hai lane mặc định bao gồm một cho user và một cho system
4PaletteBao gồm các thành phần để mô hình hóa process

3. Tạo Team

Dựa vào yêu cầu của process, bạn phải tạo team cho mỗi một vai trò của user: Employee, Manager. Để mô hình hóa team, bạn thêm lane và assign team cho lane đó. Mỗi lane chứa activities thể hiện một thao tác/ thi hành của team hoặc hệ thống (system). Khi bạn tạo Process, Process Designer tạo ra 2 lane mặc định: Team và System. Với Absence Process, bạn phải tạo lane và team như sau: (Đây chỉ là quy trình demo nên ta sẽ sử dụng chính user đang thực hiện develop để gán cho team)

LaneTeam titleTeam properties
EmployeeEmployeeMembers (chọn user bạn đang sử dụng) Manager bỏ trống
ManagerManagerMembers (chọn user bạn đang sử dụng) Manager bỏ trống
SystemSystem

Ta có một số định nghĩa sau đây:

Khái niệmMô tả 2
LanesCung cấp ngữ cảnh cho một mô hình quy trình
TeamsBao gồm member thực hiện các tác vụ được mô hình hóa
MembersUser groups hoặc user đơn lẻ của team
ManagersManager có thể truy cập Team Performance dashboard trong Process Portal để quản lý

Cách thức tiến hành:

  1. Click vào team lane, trong phần General đổi tên thành Employee 
  2. Tạo team cho lane Employee:
  • Trong mục General/BehaviorDefault Lane Team click New.
  • Điền Employee nhấn Finish.
  • Trong màn hình hiển thị các thuộc tính của Team Employee, mục MembersUser chọn user bạn đang đăng nhập
  • Trong mục Managers chọn Manager of All Users

  1. Ấn vào mũi tên để quay lại process

  1. Tạo lane Manager:
  • Kéo thả một lane từ palette vào trong sơ đồ
  • Đặt tên lane Manager, đổi màu trong mục Color thành màu xanh
  1. Tạo team cho lane Manager: (tương tự bước 2)
  2. Click nút Finish editting

4. Tạo activity và event

Ta có một số định nghĩa:

Khái niệmMô tả
EventĐiều khiển luồng (flow) và các object trong process
Start eventĐược triggers thời điểm khởi tạo process.
End eventXảy ra khi process kết thúc và tất cả các thành phần trong process kết thúc
ActivityMột Tác vụ công việc đơn lẻ mà con người (Human) hoặc hệ thống (System) phải thực hiện trong quá trình process đi từ start đến end. Có nhiều loại Activity
User taskLà một Activity kiểu User Task, do con người thực hiện và hoàn thành
System taskLà một Activity kiểu System task, do hệ thống tự động hoặc service tự động hoàn thành
Script taskLà một Activity sử dụng JavaScript để xử lý
Decision taskLà một Activity xử lý điều kiện hoặc quyết định

Cách thức tiến hành:

  1. Xác định team nào sẽ thực hiện các tác vụ: Tạo đơn xin nghỉ phép, Phê duyệt đơn nghỉ phép, Update HR Info. Xem bảng sau:
LaneActivities, color, and descriptionEvents
EmployeeTạo đơn xin nghỉ phép. Màu Red. User sẽ điền vào form và tạo một đơn xin nghỉ phépStart
ManagerPhê duyệt đơn nghỉ phép. Màu Green. User sẽ phê duyệt hoặc từ chối đơn xin nghỉ phép
SystemUpdate HR Info. Màu Default. Từ quyết định của Manager, hệ thống sẽ update thông tin ngày phép còn lại của người dùngEnd
  1. Mở Process Absence Management, tab Definition
  2. Xóa Inline User Task mặc định trên màn hình đi, Kéo Activity từ cột Palette vào Lane Employee
  3. Trong mục Properties,
  • General đổi tên thành Tạo đơn xin nghỉ phép
  • Implement Mục Activity Type , chọn User Task (lưu ý là ngoài cách này, có thể nhấp vào mũi tên bên cạnh Activity Palette, chọn User Task sau đó kéo thả) 
  1. Add thêm User Task và System Task vào diagram, di chuyển Event Start và End như hình vẽ sau:

  2. Lưu lại

5. Tạo luồng (flow)

Bây giờ trong process đã có activity và event, bạn phải thêm những luồng cơ bản để điều khiển những thứ đó. Luồng điều khiển này sẽ liên kết các activity với nhau và xem rằng ai hoàn thành những activity đó.

Note: Nếu có hơn một đường nối từ một object, thì đường đầu tiên được thêm sẽ là flow mặc định, đường tiếp theo sẽ đi theo một điều kiện nhất định nào đó.

Thông thường, bạn sẽ phải thêm những object để điều khiển luồng, gateway là một ví dụ khi mà có hơn một đường ra cho một activity nào đó. Ta đi qua một số khái niệm sau:

Khái niệmMô tả
Flow thông thường Một mũi tên chỉ đến bước tiếp theo của tiến trình khi nào mà bước trước đó kết thúc
Flow có điều kiện Một mũi tên tính toán ra biểu thức theo điều kiện và kết quả tính toán quyết định đường đi tiếp theo khi điều kiện được thỏa mãn
Flow mặc định Một mũi tên với nét kẻ gạch ở đầu, mô tả một đường đi mặc định khi không có điều kiện nào được thỏa mãn

Cách thức tiến hành:

  1. Mở Process Absence Management, tab Definition
  2. Trong Process Diagram, di chuyển chuột đến Start và click vào điểm kéo thả để tạo điểm đầu của mũi tên.
  3. Kéo con chỏ chuột về điểm chọn của Tạo đơn xin nghỉ phép và click lần nữa. 
  4. Tương tự vậy, ta kết nối Tạo đơn xin nghỉ phép với Phê duyệt đơn nghỉ phép và nối Phê duyệt đơn nghỉ phép với Update HR Info, nối đồng thời Phê duyệt đơn nghỉ phép và Update HR Info với End ta được như hình. 
  5. Lưu lại.

6. Tạo event gateway

Event gateway thể hiện một điểm rẽ nhánh trong process, nơi mà chỉ có một hoặc một vài flow được đi theo, phụ thuộc vào sự kiện (điều kiện) đang diễn ra. Để đơn giản hóa diagram, gateway thường được đặt lên tên một câu hỏi còn các đường ra có thể là câu trả lời tương ứng. Trong Absence Management, bạn cần tạo hai gateway sau đây:

  • Chuyển phê duyệt ?: Nếu như yêu cầu nghỉ phép được điền đủ thông tin và sẵn sàng thì gửi tới Manager, nếu như muốn hủy ý định nghỉ phép thì đơn xin nghỉ phép sẽ bị hủy
  • Phê duyệt ?: Có ba trường hợp xảy ra: Nếu như Manager đồng ý duyệt, luồng sẽ đi tới thông báo cho HR, và trừ ngày phép. Nếu không đồng ý thì luồng sẽ email thông báo cho nhân viên. Nếu yêu cầu chỉnh sửa thì luồng sẽ trở lại Tạo đơn xin nghỉ phép.

Ta có khái niệm:

Khái niệmMô tả
GatewayĐiều khiển luồng của process, ví dụ như tụ hồi/ phân kỳ luồng, xác định, rẽ nhánh, hợp luồng. Có hai kiểu gateway chính: phân chia và tập hợp. Nghĩa là gateway có thể chia luồng thành nhiều luồng nhánh khác nhau hoặc có thể hợp nhiều luồng khác nhau thành một luồng. Do đó có hai loại gateway: exclusive và parallel (độc nhất và song song).
Exclusive gatewayDẫn quy trình đi qua duy nhất một luồng. Sau khi điều kiện thỏa mãn, duy nhất một luồng điều kiện được đi theo, nếu không có điều kiện nào được thỏa mãn thì process đi qua default flow
Parallel gatewayParallel gateway dẫn process qua tất cả các luồng của parallel mà không có điều kiện nào cả.

Cách thức tiến hành:

  1. Mở Process Absence Management, tab Definition

  2. Kéo thả Gateway từ thanh Palette đến khu vực phía bên phải của Tạo đơn xin nghỉ phép. Điền Chuyển phê duyệt? vào mục tên. 

  3. Kết nối gateway:

  • Click vào luồng nối từ Tạo đơn xin nghỉ phép và Phê duyệt đơn nghỉ phép, nhấn Delete
  • Kết nối Tạo đơn xin nghỉ phép với gateway Chuyển phê duyệt ?
  • Kéo thả từ thanh Palette một End Event, nối gateway Chuyển phê duyệt? với End Event, tiếp tục nối gateway này với Phê duyệt đơn xin nghỉ phép
  1. Đặt tên cho luồng
  • Click vào luồng nối giữa Chuyển phê duyệt? và End Event

  • Trong mục PropertiesGeneral đổi tên thành Hủy đơn, hãy đảm bảo rằng bạn đã tick vào box Name visible để hiển thị tên của luồng lên diagram. 

  • Tương tự vậy click vào luồng nối giữa Chuyển phê duyệt? và Phê duyệt đơn nghỉ phép, đổi tên thành Cần phê duyệt

  1. Lặp lại bước 2 và 3 để tạo gateway Phê duyệt? được kết nối sau Phê duyệt đơn nghỉ phép
  2. Sẽ có 3 khả năng xảy ra ở gateway này
  • Yêu cầu điều chỉnh: nối Phê duyệt? trở lại Tạo đơn xin nghỉ phép
  • Từ chối: Kéo từ Palette ra một Intermediate Event/ Message(sending) và nối Phê duyệt? với event này, sau đó nối từ event này tới End
  • Đồng ý: nối từ Phê duyệt? tới Update HR Info rồi tới End 
  1. Lưu lại.

7. Tạo timer intermediate event

Trong phần này ta sẽ đặt một Timer intermediate event, sẽ được khởi chạy khi Manager lưu giữ đơn nghỉ việc quá lâu mà không có động thái phê duyệt/từ chối... Một số khái niệm:

Khái niệmMô tả
Intermediate eventXảy ra giữa Start event và End event của Process. Có 3 loại: timer, message và error. Ta sử dụng intermediate event để thực hiện các service vào thời gian cụ thể nào đó khi điều kiện được đáp ứng. Intermediate event có thể nằm trong luồng hoặc được gắn vào Activity
Timer intermediate eventĐược sử dụng để xác định thời gian chính xác trước khi một hành động nào đó xảy ra
ECM Content intermediate eventKhi nhận được một ECM Content message thì sẽ thực thi hành động tiếp theo
Message intermediate eventGửi hoặc nhận message
Error intermediate eventDùng để xác định những exception có thể xảy ra khi mà process đang chạy và xử lý các exception đó bằng các error handler activity, sub process hoặc flow
  1. Kéo từ Palette ra một Intermediate Event/ Timer , gắn vào Activity Phê duyệt đơn nghỉ phép . Lưu ý là phải gắn vào viền Activity mới đúng. 

  2. Trong mục PropertiesGeneral đặt tên event là **Quá hạn phê duyệt **.

  3. Trong mục PropertiesImplementation bỏ tick ô Interrupt Activity, giữ tick vào ô Repeatable. 

Note:

  • Nếu ta chọn Interrupt activity, thì Timer này trigger là Activity Phê duyệt đơn nghỉ phép cũng đóng luôn, ta phải bỏ chọn nút này bởi vì ta muốn Manager vào thực hiện tác vụ khi nhận được thông báo.
  • Nếu ta bỏ chọn nút Repeatable, thông báo sẽ chỉ được gửi duy nhất một lần. Nếu ta chọn nút này, thông báo sẽ được gửi cách nhau một khoảng thời gian xác định cho đến khi Activity được hoàn thành.
  1. Thêm activity Thông báo quá hạn
  • Kéo một activity System Task từ palette đến System lane , bên trái của Update HR Info
  • Đặt tên cho activity là Thông báo quá hạn
  1. Kết nối Timer với Thông báo quá hạn
  2. Đặt tên cho luồng nối giữa Quá hạn phê duyệt và Thông báo quá hạn là "Trễ thời hạn phê duyệt" và tick vào Name visible. Mục Type, chọn Exception Path 
  3. Thêm một End event vào trong luồng, kéo thả từ palette vào bên phải của Thông báo quá hạn và nối từ đó vào End event luôn, đặt tên End event này là End thông báo Diagram sẽ nhìn như sau: 
  4. Lưu lại.

8. Tạo biến process

Ta cần vài biến Private để mô tả, thể hiện đơn xin nghỉ việc cũng như các quyết định trong gateway.

  • absenceRequest
  • managerDecision (lưu ý quy tắc đặt tên biến theo camel case) Ta đến với các khái niệm:
Khái niệmMô tả
VariablesNói một cách lý thuyết, biến là cung cấp data về ngữ cảnh hiện tại của process đang chạy. Sử dụng biến, process truyền dữ liệu từ step này đến step khác. Có 3 loại biến bên dưới:
Private variablesBiến process hiện tại cần hoặc service cần
Input variablesBiến được truyền vào process hoặc service
Output variablesBiến được truyền ra process hoặc service

Cách thức tiến hành Tạo biến:

  1. Mở Process Absence Management, tab Variables
  2. Click vào dấu cộng trong mục Private để thêm biến private, nhập absenceRequest, tạo thêm biến nữa managerDecision  Lưu ý ta vẫn để kiểu dữ liệu của biến là String (mặc định) vì sẽ thay đổi nó trong phần sau, khi tạo Business object.
  3. Lưu lại.

9. Tạo process snapshot đầu tiên

Snapshot là một trạng thái của library item trong process trong một mốc thời gian nhất định. Bạn có thể tạo snapshot trong Process Center hoặc trong màn hình Designer. Việc quản lý đối với mỗi snapshot như install, export, archive,... được thực thi trong Process Center. Cách thức tạo snapshot

  1. Kiểm tra lại process
  2. Trong Process Designer, click vào biểu tượng trên  main Toolbar / Create a new Snapshot
  3. Điền 0.1 vào mục tên và click Finish

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

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 ...