jbpm5 community training module 4: jbpm5 apis overview + hands on

39
jBPM5 Community Training Sponsored by Plugtree

Upload: salaboy-salaboy

Post on 11-Nov-2014

9.918 views

Category:

Technology


0 download

DESCRIPTION

This module is about start using jBPM5 and the things that you need to know in order to understand the basic concepts about how it works. During this module you can download and play with a sample project that define a simple business process with some business rules. This module provides different tests that shows how to interact with our processes in different ways and how to test the behavior unit testing them. For more information check out: http://salaboy.wordpress.com/

TRANSCRIPT

Page 1: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

  

jBPM5 Community Training Sponsored by Plugtree

Page 2: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

Module 4: jBPM5 APIs Overview and Hands On

jBPM5 Community Trainingversion: 1.0-SNAPSHOT

Release Date: 01/28/2011Under The Creative Common License

Page 3: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

Module 2: BPM Discipline

jBPM5 Community Training Course by Mauricio "Salaboy" Salatino is licensed under a Creative Commons Attribution

3.0 Unported License.Based on a work at salaboy.wordpress.

com.Permissions beyond the scope of this

license may be available at http://salaboy.wordpress.com/.

Page 4: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

Agenda

jBPM5 API OverviewBasic Concepts and Components Knowledge Builder Knowledge BaseKnowledge Session

Hands On LabsDownloading the Source CodeLoading the Source Code in you IDE Sample Use Case Exercise

Page 5: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

jBPM5 Quick Overview

What is jBPM5? It's a Business Process Engine It execute our business process definitions (BPMN2)It can be easily embedded as your application dependency or be used as a separated services It will be responsible to handle the interaction between Human and Systems defined inside our business processesIt's developer and business analyst oriented

What is not jBPM5?It's not a process designerIt's not a monolithic server It's not a final end user tool

Page 6: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

jBPM5 Components Overview

Page 7: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

jBPM5 Components Overview

jBPM5 Ecosystem jBPM5 Runtime

BPMN2 Semantic ModuleCore Business Process EnginePersistence and Transaction MechanismHistory Logs

jBPM5 Human Task Server jBPM5 Tooling

jBPM5 DesignerjBPM5 Process ConsolejBPM5 REST Process Server jBPM5 BAM

Page 8: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

jBPM5 Runtime

jBPM Runtime BPMN2 Semantic Module: it understand BPMN2 process definitions and let us load our process definitions into the jBPM5 Runtime.

Core Business Process Engine: it runs our Process Definitions. It provide us a full set of APIs to interact and create our process instances.

Persistence and Transaction Mechanism: it helps us to store the runtime status of our running processesHistory Logs: it stores all the activity that it's being executed in the engine.

Page 9: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

jBPM5 Human Task Server

jBPM5 Human Task Server Pluggeable component to handle the human tasks life cycleImplements the Web Service Human Task specification -> http://incubator.apache.org/hise/WS-HumanTask_v1.pdfIt defines the data structures to store information about the Human Tasks involved in our processes, without knowing about the process itselfIt defines the different states that a human task can have during the interaction

Page 10: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

jBPM5 Human Task Server

jBPM5 ToolingjBPM5 Designer: Graphical Process Designer that lets us define BPMN2 compliant business processes.jBPM5 Process Console: It let us test and run our processes, providing us a runtime environment where we can interact with them.jBPM5 REST Process Server: It exposes the jBPM5 runtime through a REST interface to be able to interact with the runtime from different clients and programming languages. jBPM5 BAM: It provides us some widgets and reporting features to externalize, browse and aggregate information that it's being generated from the processes execution.

Page 11: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

jBPM5 Source Code

jBPM5 Source Code -> http://www.github.com/krisv/jbpm

Get the code and build it! git clone https://github.com/krisv/jbpm.gitmvn clean install

Page 12: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

jBPM5 Hands on

jBPM5 Hands OnGet the Example Projects Code (the first time): git clone https://github.com/Salaboy/JBPM5-Training-ExamplesUpdate the Example Projects: git pull (inside the git local copy)

Page 13: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

01-jBPM5-SimpleEmergencyServiceProcess

Simple Emergency Service ProcessGo inside the project directory and build it with:mvn clean installOpen it with your favorite IDE

If you are used to Eclipse you will have plugins available to work with BPMN2 processes. Make sure you have the Maven plugins installedIf you use IntelliJ I recommned you to install the Drools Plugins (No support for BPMN2 yet)If you use Netbeans be sure to have JUnit plugins installed

Open the Test Class: SimpleEmergencyProcessTest

Page 14: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

SimpleEmergencyProcessTest

Simple Emergency Service TestWe will be working with the process definition located at:

src/test/resources/EmergencyServiceSimple.bpmn

And also with the rules file located at:src/test/resources/SelectEmergencyVehicleSimple.drl

The test file contains 4 tests that show different types of interactionWe will analyze each of the tests and compares the differences between themWe will analyze the process and the rules files in order to understand the use cases and the results that we are looking for the tests

Page 15: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

The Business Process

EmergencyServiceSimple.bpmn

Page 16: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

The Business Process

EmergencyServiceSimple.bpmn <definitions> <process processType="Private" isExecutable="true" id="SimpleEmergencyService" name="Emergency Service Main Process"> <startEvent id="_1" name="StartProcess"/> <userTask id="_2" name="Ask for Emergency Information"> <ioSpecification> ... </ioSpecification> <dataInputAssociation> ... </dataInputAssociation> <dataOutputAssociation> ... </dataOutputAssociation> <potentialOwner> <resourceAssignmentExpression> <formalExpression>operator</formalExpression> </resourceAssignmentExpression> </potentialOwner> </userTask> <businessRuleTask id="_3" name="Select Vehicle" g:ruleFlowGroup="select_vehicle"/>

Page 17: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

The Business Process

EmergencyServiceSimple.bpmn (cont) <userTask id="_4" name="Dispatch Vehicle"> ... </userTask>

<scriptTask id="_5" name="Report" scriptFormat="http://www.java.com/java"> <script> </script> </scriptTask> <endEvent id="_6" name="EndProcess"> <terminateEventDefinition/> </endEvent>

Page 18: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

The Business Process

EmergencyServiceSimple.bpmn (connections) <sequenceFlow id="_1-_2" sourceRef="_1" targetRef="_2"/> <sequenceFlow id="_2-_3" sourceRef="_2" targetRef="_3"/> <sequenceFlow id="_3-_4" sourceRef="_3" targetRef="_4"/> <sequenceFlow id="_4-_5" sourceRef="_4" targetRef="_5"/> <sequenceFlow id="_5-_6" sourceRef="_5" targetRef="_6"/> </process> </definitions>

Page 19: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

The Business Rules

SelectEmergencyVehicle.drl rule "New Ambulance for Heart Attack Emergencies" ruleflow-group "select_vehicle" when $process: WorkflowProcessInstance() Emergency(type == "Heart Attack") from $process.getVariable("emergency") then System.out.println("A new Ambuance is being created!"); Ambulance ambulance = new Ambulance("MyAmbulance"); $process.setVariable("vehicle", ambulance); insert(ambulance); end

Page 20: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

The Business Rules

SelectEmergencyVehicle.drl (cont.) rule "New Fire Truck for Fire Emergencies" ruleflow-group "select_vehicle" when $process: WorkflowProcessInstance() Emergency(type == "Fire") from $process.getVariable("emergency") then System.out.println("A new FireTruck is being created!"); FireTruck fireTruck = new FireTruck("MyFireTruck"); $process.setVariable("vehicle", fireTruck); insert(fireTruck); end

Page 21: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

1st Test: automaticHumanTasksTest()

Automatic Human Tasks TestIt creates a basic interaction with our business process

It load the process file using the KnowledgeBuilderIt creates the Knowledge Base and add the Knowledge Packages from the Knowledge BuilderIt creates a Stateful Knowledge Session using the Knowledge Base

It simulates the human interaction with a dumb work item definition to simplify the test (MyAutomaticHumanSimulatorWorkItemHandler)It Start the processBecause the Human Interactions are simulated and automatically completed by the custom work item we can check that the process is completed after calling the startProcess() method

Page 22: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

2nd Test: nonAutomaticHumanTasksTest()

Non Automatic Human Tasks TestIt creates a basic interaction with our business processIt attaches a work item handler to simulate non automatic human interactions (MyNonAutomaticHumanSimulatorWorkItemHandler) After we start the process we need to complete the Human InteractionsWe can complete the Mock Implementation using the completeWorkItem() method that the attached work item handler provides After we complete the first Human Interaction we need to call the fireAllRules() method in order to continue the process execution

Because we don't have rules in this test this doesn't make any sense, be patient for the last test

Page 23: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

3rd Test: inputDataTest()

Input Data TestIt creates a basic interaction with our business processIt attaches a work item handler to simulate non automatic human interactions, but this time the work item changes some values (MyHumanChangingValuesSimulatorWorkItemHandler) Before starting the process the test creates a new Emergency We start the process passing the Emergency inside the Parameters MapThe non automatic work item will change the value of the emergency.revision field Check the process definitionCheck the Work Item Handler implementation

Page 24: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

3rd Test: inputDataTest()

Input Data TestInput/Output Specification

<userTask id="_2" name="Ask for Emergency Information"> <ioSpecification> <dataInput id="_2_emergencyInput" name="emergency"/>

<dataOutput id="_2_emergencyOutput" name="emergency"/> ...

<inputSet>

<dataInputRefs>_2_emergencyInput</dataInputRefs> ...

</inputSet>

<outputSet>

<dataOutputRefs>_2_emergencyOutput</dataOutputRefs>

</outputSet>

</ioSpecification>

Page 25: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

3rd Test: inputDataTest()

Input Data TestBindings/Associations

<dataInputAssociation> <sourceRef>emergency</sourceRef>

<targetRef>_2_emergencyInput</targetRef>

</dataInputAssociation>

<dataOutputAssociation>

<sourceRef>_2_emergencyOutput</sourceRef>

<targetRef>emergency</targetRef>

</dataOutputAssociation>

Page 26: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

4th Test: emergencyWithRulesTest()

Emergency With Rules TestIt creates a basic interaction with our business process and our business rulesUses the MyHumanChangingValuesSimulator WorkItemHandler Handler Before starting the process the test creates a new Emergency We start the process passing the Emergency inside the Parameters MapThe rules will evaluate the type of emergency and it will decide and create a new Vehicle for according the situation Review the process and rules definition and the Asserts in the test

Page 27: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

5th Test: reactiveProcessAndRulesTest()

Reactive Process and Rules TestIt creates a basic interaction with our business process and our business rulesUses the MyHumanChangingValuesSimulator WorkItemHandler Handler Before starting the process we use a different thread to fire all the rules when they get activated -> Reactive Mode

When the conditions of the rules matches, the rule is automatically triggered without waiting the fireAllRules() methodWe need a separate thread that is continuously evaluating the activations

Page 28: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

5th Test: reactiveProcessAndRulesTest()

Reactive Process and Rules Test (cont.)We start the process passing the Emergency inside the Parameters MapThe rules will evaluate the type of emergency and it will decide and create a new Vehicle for according the situation

In this case we don't need to call the fireAllRules() method after the completion of the first human activity

But we need to wait because multiple threads are now involved

Page 29: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

Some Notes

Some Notes about the testWorkItemHandlers let us attach domain specific activitiesAll the tests use Custom WorkItemHandlers to simulate human interaction

This is to not complicate the testsWe will be dealing with real human interactions in future modules

As you main notice WorkItemHandlers can be designed to be Asynchronous or Synchronous (automatic or wait states)

Page 30: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

Some Notes

Some Notes about the test (cont.)Notice that the console logger gives you a lot of information to understand what is happening inside our knowledge sessionsNotice the interaction between Rules and Processes

This example it's pretty simple, but shows how we can do inferences over our business processes and how we can change or modify the process variables or the process state

Try to understand the XML format for a business process definition

Page 31: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

Homework

HomeworkDebug the tests, try to understand how they workInspect the Process File and the Rules FilePlay with the reactiveProcessAndRulesTest(), change the type of emergency and look how it worksModify the process definition to have one more activity before the Report that selects a Hospital based on the Type of Emergency using rulesList the modification that you have done in order to get it working

Page 32: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

Homework

HomeworkHints:

You need to create a new Domain Entity Called HospitalYou need to add a new<businessRuleTask> activity to the process and the required connectionsYou need to write some new rules that evaluates the Process, the Emergency and the Vehicle that was selectedAdd the required asserts to the new test to check that everything works correctly

Page 33: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

Homeworks Solutions

Homework SolutionsSend me your homework solutions to my personal email

Use the subject [JBPM5 Community Training] - Hands On labs 1If you have doubts about the exercise, post a comment in the blogIf I start receiving too much questions we can probably create a google group for answering questions or use the JBoss jBPM forum

Page 34: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

Conclusions

ConclusionsWe play a little bit with our first tests that uses jBPM5We simulate some human interactions in order to understand basic concepts about:

The business process definitionThe rules definitionsThe execution behavior

Now we now the basic structure of a simple proyect that uses jBPM5 and all the things that we need to have in our environment in order to work with it

Page 35: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

Next Modules

Stay tuned for the next modules that will explain important topics such as:

The Business Process Modeling and Notation V2 Real Human Interactions inside our processesTask List Oriented User interfaces using different technologiesetc.

Page 36: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

Related Links

You can find more information, examples, tutorials and more in:

Salaboy Blog http://salaboy.wordpress.com

Plug Tree Bloghttp://www.plugtree.com

Page 37: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

  

Questions?

Page 38: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

Enjoy! Questions and Feedback are always appreciated!

Page 39: jBPM5 Community Training Module 4: jBPM5 APIs Overview + Hands On

  

Contact us atwww.plugtree.com