jbpm5 community training module #5: domain specific processes

41
jBPM5 Community Training Sponsored by Plugtree

Upload: salaboy-salaboy

Post on 11-Nov-2014

7.859 views

Category:

Technology


1 download

DESCRIPTION

This modules covers two different aspects that we need to understand to customize our business processes to specific business situations. The first concept that we need to understand is the Service Task activity defined in the BPMN v2 specification. Once we understand the nature of external system interactions we need to understand the mechanisms implemented in jBPM5 to provide these extension points. Find more about it in: http://salaboy.wordpress.com http://ilesteban.wordpress.com

TRANSCRIPT

Page 1: jBPM5 Community Training Module #5: Domain Specific Processes

  

jBPM5 Community Training Sponsored by Plugtree

Page 2: jBPM5 Community Training Module #5: Domain Specific Processes

Module 5: jBPM5 Domain Specific ProcessesjBPM5 Community Training

version: 1.0-SNAPSHOTRelease Date: 03/01/2011

Under The Creative Common License

Page 3: jBPM5 Community Training Module #5: Domain Specific Processes

Module 5: Domain Specific Processes

jBPM5 Community Training Course by Mauricio "Salaboy" Salatino and

Esteban Aliverti 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 #5: Domain Specific Processes

Agenda

Domain Specific Processes Introduction

BPMN2 Service TasksWork Item Concept inside jBPM5

Work Items characteristicsWork Item Handlers

Implementing Custom HandlersControlling Flow Execution

Examples

Page 5: jBPM5 Community Training Module #5: Domain Specific Processes

Introduction

BPMS are domain agnostic, that's good but...We need to extend them in order to represent specific business situationsOur processes needs to represent domain specific behavior The activities inside our processes reflect how people work in a specific domainDifferent systems behaves differently and we need to represent this particular behavior in our processes

Page 6: jBPM5 Community Training Module #5: Domain Specific Processes

Introduction

The BPMN2 Standard Specification Service TaskIt provides a generic way to interact with external services

Spec: "A Service Task is a Task that uses some sort of service, which could be a Web service or an automated application." We can use the Service Task concept as extension point to plug domain specific behavior and to handle external interactions

Page 7: jBPM5 Community Training Module #5: Domain Specific Processes

Introduction

Inside jBPM5 the concept of Work Item is used for extension points

Any external interaction from the process perspective is done via a Work ItemThe work item is executed outside the process scopeA Work Item Handler needs to be defined to technically specify the execution behavior At runtime we can plug different implementations for different environments

Page 8: jBPM5 Community Training Module #5: Domain Specific Processes

Work Items Characteristics

Work Items Represent a unit of work executed outside the process engineMain Characteristics:

Domain-specificDeclarative: what, not howHigh-level: no codeCustomizable to the context

Page 9: jBPM5 Community Training Module #5: Domain Specific Processes

Service Task relationship with WorkItems

Service Task relationship with WorkItemsThe Service Task Activity inside BPMN2 exposes an atribute called:

implementation: this attribute can be used to specify which implementation will be called when a specific service task is reached by the process execution.In jBPM5 this implementation attribute will be bond to a specific Work Item Handler that will contain the technical specification about how to interact with an external entity

Page 10: jBPM5 Community Training Module #5: Domain Specific Processes

Service Task relationship with WorkItems

Service Task relationship with WorkItems (cont.)The Service Task activity define the information that will be required by the external interaction and how it will be copied from the process scope to the task scope The Service Task activity define the information that will be generated by the external interaction and needs to be copied back to the process scope

Page 11: jBPM5 Community Training Module #5: Domain Specific Processes

Service Task relationship with WorkItems

Service Task relationship with Work Items (cont.)For each Service Task that we define in our process we need to have at least one WorkItemHandler implementation that must be bound before we execute our processAt runtime we can choose which implementation will be used for each Service Task

Page 12: jBPM5 Community Training Module #5: Domain Specific Processes

WorkItems and WorkItemHandlers

WorkItem and WorkItemHandlersFor each external interaction that our process execute we need to know that a WorkItem will be executedThe engine provides some built in work item handlers for common use cases

Human Task WorkItemHandler is in charge of handling the human task creations in the Human Task ServerEmail WorkItemHandler is in charge of getting the information and interacts with an email server to send an email

Page 13: jBPM5 Community Training Module #5: Domain Specific Processes

WorkItemHandler Interface

WorkItemHandler Interfaceorg.drools.runtime.process.WorkItemHandler

It's located inside an org.drools package because Drools and jBPM5 share the same mechanism for external interactionsForce us to implement only two methods:

public void executeWorkItem(WorkItem wi, WorkItemManager wim);public void abortWorkItem(WorkItem wi, WorkItemManager wim);

Page 14: jBPM5 Community Training Module #5: Domain Specific Processes

WorkItemHandler Interface

WorkItemHandler InterfaceWe can choose and define the behavior of the interaction inside the executeWorkItem(...) methodThe interaction can be synchronous or asynchrnousWe usually do the following things inside the executeWorkItem(...) method:

We get the information required by the interaction using the WorkItemManagerWe execute the interaction with an External (to the process) ServiceWe complete the workItem syncronously or we delegate the completion to the external asynchronous system

Page 15: jBPM5 Community Training Module #5: Domain Specific Processes

WorkItemHandler Binding

WorkItemHandler BindingWe need to get the WorkItemManager from our Knowledge Session and register our WorkItemHandlers implementationsksession.getWorkItemManager() .registerWorkItemHandler(key,impl);When a running process hits and activity that specify the implementation registered (key) the work item handler will be executed (the executeWorkItem(...) method).

Page 16: jBPM5 Community Training Module #5: Domain Specific Processes

Synchronous WorkItemHandler

Synchronous Work Item HandlerExecutes the task When it's finished, it can complete or abort the Work Item using the Work Item Manager methods

Page 17: jBPM5 Community Training Module #5: Domain Specific Processes

Asynchronous WorkItemHandler

Asynchronous Work Item HandlerCall external serviceDelegate the responsibility to the external service app/service to complete or abort the Work Item For this reason the external app/service needs to have access to the session that has the Work Item Manager to complete or abort the Work Item

Page 18: jBPM5 Community Training Module #5: Domain Specific Processes

Asynchronous & Synchronous Interactions

Page 19: jBPM5 Community Training Module #5: Domain Specific Processes

Synchronous External Interactions

Page 20: jBPM5 Community Training Module #5: Domain Specific Processes

Asynchronous External Interactions

Page 21: jBPM5 Community Training Module #5: Domain Specific Processes

Async & Sync External Interactions

Page 22: jBPM5 Community Training Module #5: Domain Specific Processes

Asynchronous WorkItemHandler

Once Asynchronous Work Item HandlerCall external serviceDelegate the responsibility to the external service app/service to complete or abort the Work Item For this reason the external app/service needs to have access to the session that has the Work Item Manager to complete or abort the Work Item

Page 23: jBPM5 Community Training Module #5: Domain Specific Processes

Asynchronous WorkItemHandler

Asynchronous Work Item Handler (cont.)We can implement a simple mechanism to keep track of the external async jobsWe need to store a business key and the workItemId that needs to be finished when the application ends the async job

This mechanism needs to have access to the knowledge session in order to be able to complete the related work item

Page 24: jBPM5 Community Training Module #5: Domain Specific Processes

Vehicle Tracking External Interaction

Page 25: jBPM5 Community Training Module #5: Domain Specific Processes

WorkItemHandler Information Scope

Process execution will handle different pieces of informationWorkItemHandlers are considered to be external to the process scope and for that reason they have a limited scope to handle information We need to manually map the information that it is required by the external interaction to be copied from the process scope to the WorkItemHandler scopeWhen we complete a WorkItem we get the results for the external interactionWe must map manually the information that needs to be copied back from the workItemHandler scope to the process scope

Page 26: jBPM5 Community Training Module #5: Domain Specific Processes

WorkItemHandler Information Mappings

Page 27: jBPM5 Community Training Module #5: Domain Specific Processes

Information Mappings in BPMN 2.0

<ioSpecification> <dataInput id="_5_vehicle.typeInput" name="vehicle.type" /> <dataInput id="_5_vehicle.idInput" name="vehicle.id" /> <dataOutput id="_5_trackingIdOutput" name="trackingId" /> <dataOutput id="_5_trackingExecutionTimeOutput" name="trackingExecutionTime" /> <inputSet> <dataInputRefs>_5_vehicle.typeInput</dataInputRefs> <dataInputRefs>_5_vehicle.idInput</dataInputRefs> </inputSet> <outputSet> <dataOutputRefs>_5_trackingIdOutput</dataOutputRefs> <dataOutputRefs> _5_trackingExecutionTimeOutput </dataOutputRefs> </outputSet> </ioSpecification>

Page 28: jBPM5 Community Training Module #5: Domain Specific Processes

Information Mappings in BPMN 2.0

<dataInputAssociation> <targetRef>_5_vehicle.typeInput</targetRef> <assignment> <from xs:type="tFormalExpression">#{vehicle.type}</from> <to xs:type="tFormalExpression">_5_vehicle.typeInput</to> </assignment></dataInputAssociation><dataInputAssociation> <targetRef>_5_vehicle.idInput</targetRef> <assignment> <from xs:type="tFormalExpression">#{vehicle.id}</from> <to xs:type="tFormalExpression">_5_vehicle.idInput</to> </assignment></dataInputAssociation><dataOutputAssociation> <sourceRef>_5_trackingIdOutput</sourceRef> <targetRef>trackingId</targetRef></dataOutputAssociation><dataOutputAssociation> <sourceRef>_5_trackingExecutionTimeOutput</sourceRef> <targetRef>trackingExecutionTime</targetRef></dataOutputAssociation>

Page 29: jBPM5 Community Training Module #5: Domain Specific Processes

Examples

Project: 02 - Emergency Service Process and Work Items Examples

Key points: Synchronous Work Items HandlerURL: git://github.com/Salaboy/Drools_jBPM5-Training-Examples.

git

Project: 03 - Emergency Service Process and Asynchronous Work Items Examples

Key points: Asynchronous Work Items HandlerURL: git://github.com/Salaboy/Drools_jBPM5-Training-Examples.git

Page 30: jBPM5 Community Training Module #5: Domain Specific Processes

Examples: Emergency Service Process

A new node was added: "Vehicle Tracking (GPS)"Task Activity represents a Task that needs to be performed by an external systemYou need to register a handler for each TaskHandlers could be Synchronous or Asynchronous

Page 31: jBPM5 Community Training Module #5: Domain Specific Processes

Examples

02 - Emergency Service Process and Work Items Examples:Handlers must implement org.drools.runtime.process.WorkItemHandlerHandlers are registered in the Work Item Manager:ksession.getWorkItemManager(). registerWorkItemHandler( "StartTrackingSystem", trackingSystemHandler );

The handler completes the Work Item inside the executeWorkItem() method -> Synchronous behavior

Page 32: jBPM5 Community Training Module #5: Domain Specific Processes

Examples

03 - Emergency Service Process and Asynchronous Work Items Examples:

Interaction between 3 different "Systems": EmergencyProcessExternalSystemsWorkItemsTest:Test application that embeds jBPM5 runtime.AsyncVehicleTrackingMockSystem:An external system in charge of tracking vehicles.ActiveWorkItemService:Service used to register and complete Work Items. This system maintains the relation between an External Job and a Work Item.

The handler doesn't completes the Work Item inside the executeWorkItem() method -> Asynchronous behavior

Page 33: jBPM5 Community Training Module #5: Domain Specific Processes

Homework

HomeworkAdd a new output parameter to VehicleTrackingSystem task and show its value into the final report. This parameter should contain a String representation of the Date when the External Task was completed.Create an external system mock with an isAdmisible(trackingTime:long):boolean method. This method will receive the total tracking time and will return true if the total time is below a given (harcoded) threshold otherwise it will return false . Add a new "Call to Validation Service" task after VehicleTrackingSystem and create a synchronous handler that invokes the new system.The final report must contain the value returned by this system.

Page 34: jBPM5 Community Training Module #5: Domain Specific Processes

Homework

HomeworkHints:

In order to define a new output parameter for a Task activity and to store its value in a process' variable you need 4 steps:

Create a new <itemDefinition> element.Create a new <property> in the process.Add a new <dataOutput> element in the TaskAdd a new <dataOutputAssociation> in the Task to map the output parameter to a process variable.

Page 35: jBPM5 Community Training Module #5: Domain Specific Processes

Homeworks Solutions

Homework SolutionsSend me your homework solutions to my personal email

Use the subject [JBPM5 Community Training] - Hands On labs 2If 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 36: jBPM5 Community Training Module #5: Domain Specific Processes

Conclusions

ConclusionsWe understand how to plug our custom domain specific behavior into our business processesWe understand internal concepts that are implemented in jBPM5 that provides extension points for our external interactionsWe play with a couple of examples that show a very basic interaction and more realistic scenarios

Page 37: jBPM5 Community Training Module #5: Domain Specific Processes

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 38: jBPM5 Community Training Module #5: Domain Specific Processes

Related Links

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

Salaboy Blog http://salaboy.wordpress.com

Esteban Bloghttp://ilesteban.wordpress.com

Plug Tree Bloghttp://www.plugtree.com

Page 39: jBPM5 Community Training Module #5: Domain Specific Processes

  

Questions?

Page 40: jBPM5 Community Training Module #5: Domain Specific Processes

Enjoy! Questions and Feedback are always appreciated!

Page 41: jBPM5 Community Training Module #5: Domain Specific Processes

  

Contact us atwww.plugtree.com