czwartek, 17 września 2015

Unified KIE Execution Server - Part 4

Here we come with next part of the Unified KIE Execution Server blog series - this time Part 4 that introduces Client UI written in JavaScript - AngularJS.
This aims at illustrating how easy it is to built fully featured Client UI that interacts with KIE Execution Server through REST API.

KIE Execution Server has been designed from the very beginning to be lightweight and consumable with whatever technology you like. Obviously it has to run on Java but components that integrate with it can be written in any language. To demonstrate that it actually works I came up with very basic UI written in AngularJS that uses:

REST API

JSON as data format

So what can it do? Quite a lot to be honest - although those who are familiar with AngularJS will directly notice that I am not an expert in this area while looking at the code. Apologies for that, although this was not the intention to show best practice in building AngularJS applications but to show you how easy it is (as I managed to do so :)) to interact with KIE Execution Server.

Let's start with it then...

Installation

Installation is extremely simple - just clone this repository where you find jbpm-angular-js module. This is the application that we'll be using for the demo. Once you have it locally

NOTE: we did put that on the same server as KIE Execution Server to avoid any CORS releated issues that will come up when using JavaScript application that resides on different server than the back end application.

Now you can start the Wildfly server and (assuming you use configuration used in previous parts of this blog series) access the AngularJS application at:

You'll be presented with very simple logon screen that asks (as usual) for user name and password and in addition to that for KIE Execution Server URL that will be used as our backend service. Here you can simply put:

Following screenshot shows the process definition that we are going to use:

A very simple process that consists of two user tasks:

first 'Review and Register' is used for gathering data from assigned user

second 'Show details' is just for the demo purpose to illustrate that process variable was properly updated with data given in first task

This process has two process variables:

person - that is of type org.jbpm.test.Person and consists of following fields

name - String

address - String

age - Integer

registered - Boolean

note - String

While working with this process we are going to exchange data between client (JavaScript) and server (Java) and as data format we will use JSON.

An important note for this application - this is a vary basic and generic application so it requires to provide valid JSON values when working with variables. To give an example (or two...)

"my string" - for string type

123 - for number type

{"one", "two", "three"} - for list of strings

{"Person":{"name":"john","age":25}} - for custom objects

Custom objects requires identifier that KIE Execution Server can use when unmarshalling to proper type. This can be given in either way:

Simple class name = Person

Fully qualified class name = org.jbpm.test.Person

Both formats are supported, though FQCN is usually safer (in case of possible conflicts when there are more than one class with same simple name). That's not so common case therefore short/simple name might be used in most of the cases.

Before it can be actually used (as presented in below screencast) you need to deploy the container to kie server. Deploy sample project called kie-server-demo that you can find in this repository (simply clone it and build locally with maven or with (even better) KIE workbench) - see part 3 on how to deploy containers/projects

Demo

Here is screen cast demoing entire application working with described process.

I'd like to encourage you to give it a try yourself and see how does it fit your needs. With this you can start building UI for KIE Execution Server in the preferred technology/language. It's has never be so simple :)

here is a complete example how to invoke remotely process in kie server over REST api:https://github.com/mswiderski/jbpm-examples/blob/master/kie-server-test/src/main/java/org/jbpm/test/kieserver/KieExecutionServerClientTest.java

Thanks for reply. In the bulid path i have two missing jar(Maven Dependencies), kie-internal-6.3.0-SNAPSHOT.jar and kie-server-client-6.3.0-SNAPSHOT.jar. i'm download form mvnrepository kie-server-client-6.3.0.jar and kie-internal-6.3.0.jar and add external jars but. im have errors in pom.xml Missing artifact org.kie:kie-internal:jar:6.3.0-SNAPSHOT and Missing artifact org.kie.server:kie-server-client:jar:6.3.0-SNAPSHOT.

Becouse i not found newest files in repository on disk c i use kie-internal 6.4.0 final and kie-service-klient 6.0.1 (folder kie-server-klient not working and have different files structure becouse i use path to service-client). Now i have no compilation errors but program still not working correctly.

This is my console content:

Exception in thread "main" java.lang.NoClassDefFoundError: org/optaplanner/core/api/score/buildin/simple/SimpleScore at org.kie.server.api.marshalling.jaxb.JaxbMarshaller.(JaxbMarshaller.java:114) at org.kie.server.api.marshalling.BaseMarshallerBuilder.build(BaseMarshallerBuilder.java:40) at org.kie.server.api.marshalling.MarshallerFactory.getMarshaller(MarshallerFactory.java:52) at org.kie.server.client.impl.AbstractKieServicesClientImpl.(AbstractKieServicesClientImpl.java:76) at org.kie.server.client.impl.KieServicesClientImpl.(KieServicesClientImpl.java:70) at org.kie.server.client.KieServicesFactory.newKieServicesClient(KieServicesFactory.java:101) at org.jbpm.test.kieserver.KieExecutionServerClientTest.main(KieExecutionServerClientTest.java:46)Caused by: java.lang.ClassNotFoundException: org.optaplanner.core.api.score.buildin.simple.SimpleScore at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 7 more

Hi Maciej. This looks convincing, we are using the jbpm 6.1 in embedded mode in our web application. And definitely this would be very useful for us to separate it out to an execution server. However I see the following 3 features which are still lacking, do you guys have any plans for that or is it already there in some other form ?

1) Option to develop rich/fancy and custom forms. We want to develop the html forms with branding,look and feel which fits to our project. Can we develop them externally (job of an UI developer) and re integrate back to process definition in workbench.

2) How can we achieve user input validations which are performed on server side ? Meaning we would like to validate the user input by our own business logic by contacting some other web service or by contacting other DB.

3) Can we persist the java objects used as process variables within process instance to external DB (other than JBPM DB ) ?

>>>1) Option to develop rich/fancy and custom forms.>>>We want to develop the html forms with branding,look and feel which fits to our project. Can we develop them >>>externally (job of an UI developer) and re integrate back to process definition in workbench.

take a look at this article that shows how you can use form content to render your own UI http://mswiderski.blogspot.com/2016/03/jbpm-ui-extension-on-kie-server.html

>>>2) How can we achieve user input validations which are performed on server side ? Meaning we would like to >>>validate the user input by our own business logic by contacting some other web service or by contacting >>>other DB.you would have to write your own kie server extension (see this article) to achieve that http://mswiderski.blogspot.com/2015/12/kie-server-extend-existing-server.html

>>> 3) Can we persist the java objects used as process variables within process instance to external DB (other than JBPM DB ) ?of course you can see this http://mswiderski.blogspot.com/2014/02/jbpm-6-store-your-process-variables.html

I will try out the answers for Question 1 and 2. Meanwhile can you please let me know how do I configure persistent strategy in KIE execution server(For question 3). I would like to have Process variables stored in Database-1 for Container-1 (kjar) and similarly would like to have the process variablesstored in Database-2 for Container-2 (kjar). Is there any configuration file kind of thing which defines the persistence configurations for each container that I can drop in jboss application server without modifying the kie execution server ?

I have looked into your blog for the configuration of persistence strategy but I believe it works if Iam using jBPM in embedded mode or If I havedirect access to jBPM APIs.

you can design your data object to be persistable see docs (25.3.2.5. Generation of JPA enabled Data Models) then it's really up to your data source definition that is referenced from persistence.xml where that data will be stored. Make sure data source is XA so it can properly participate in transaction.

Hi Maciej,Many thanks for this article, it helped me to understand how to use rest api Calls.I used app with version 7.1.After i press New to create process instance i got submit button Only and when press submit the process start.Even when i press Details to view variables the page didn't show the variables (the response contain the variables but the page didn't print the variables ).thanks

I was trying to build UI using AngularJs and integrate with JBPM so i have downloaded the jbpm-angular-js module and copy the app.war in parallel to kie-server.war and started the server.

with localhost:8080/app it is showing 404-pagenot found but other endpoints i.e. process defination/querying the containers are working fine. Can you please let me know what could be the reason of showing 404

After going through blogs , I was added HR group to user kieserver but still task summary is empty. Also when in details page the initiator coming as "UnKnown". Please help me to get it work end to end.

- Created Custom Class for both UserGroupCallbackImpl and UserInfoImpl to fetch/validate user/group details from the Database.- Also added following properties org.jbpm.ht.callback=custom org.jbpm.ht.custom.callback=com.nav.usergroup.CustomDBUserGroupCallbackImpl org.jbpm.ht.userinfo=custom org.jbpm.ht.custom.userinfo=com.nav.usergroup.CustomDBUserInfoImpl

org.jbpm.services.task.exception.PermissionDeniedException: User '[UserImpl:'unknown']' was unable to execute operation 'Start' on task id 641 due to a no 'current status' match at org.jbpm.services.task.internals.lifecycle.MVELLifeCycleManager.evalCommand(MVELLifeCycleManager.java:161) ~[jbpm-human-task-core-7.1.0.Final.jar:7.1.0.Final]

When i debug the code, identityProvider.getName() [org.kie.server.services.jbpm.UserTaskServiceBase] is giving "unknown"