39
A new kind of BPM with Activiti 1 Tom Baeyens & Joram Barrez Alfresco twitter: @tombaeyens @jbarrez

A new kind of BPM with Activiti

Tags:

Embed Size (px)

DESCRIPTION

This session will demonstrate the Activiti tools in the context of the full software development cycle. Starting from business people over developers to system administrators. Activiti facilitates the collaboration between those roles in a pragmatic and new way. For the developer part, we'll briefly dive a bit deeper. With code samples we'll give you a look under the hood.

Citation preview

Page 1: A new kind of BPM with Activiti

1

A new kind of BPM with Activiti

Tom Baeyens & Joram BarrezAlfresco

twitter: @tombaeyens @jbarrez

Page 2: A new kind of BPM with Activiti

2

Tom Baeyens

• Founder of Activiti & jBPM• Passionate about Java and BPM• http://processdevelopments.blogspot.com/

Joram Barrez

• Ex-core developer JBoss jBPM• Core developer Activiti• http://www.jorambarrez.be/

Page 3: A new kind of BPM with Activiti

3

BPM for developers

• Process = Activities + Transitions• Activity = Execution step in your application• Configure out of the box activity types

• User task• Email• Script• Web service• JMS• EJB

• Delegate to Java& scripting where necessary

• Timers

Page 4: A new kind of BPM with Activiti

4

Activiti Engine

• Essence: State machine• Persist state of an execution flow

Execution

Empl John Doe

Date 5/10/2010Doc vacation.xlsState Approved

Page 5: A new kind of BPM with Activiti

5

Transactional Control Flow

• Start process instance• Create new execution• Pass initial data in (optional)• Take transition to “Fetch data from DB”• Execute “Fetch data from DB”• Take transition to “Wait 1”• Stop interpreting process• Persist state• Return Execution

Page 6: A new kind of BPM with Activiti

6

Transactional Control Flow

INSERT INTO ACT_RU_EXECUTION (…, ACTIVITY_ID_, …) values (…, ‘Wait’, …)

Execution

Page 7: A new kind of BPM with Activiti

7

Transactional Control Flow

• Signal• Load existing execution• Pass data in (optional)• Take transition to “Wait 2”• Stop interpreting process• Update runtime execution• Return

Execution

Page 8: A new kind of BPM with Activiti

8

Transactional Control Flow

UPDATE ACT_RU_EXECUTION SET ACTIVITY_ID = ‘Wait 2’

Execution

Page 9: A new kind of BPM with Activiti

9

Transactional Control Flow

• Signal• Load existing execution• Pass data in (optional)• Take transition to “Send email”• Execute “Send email”• Take transition to “end”• Stop interpreting process• Delete runtime execution• Return Execution

Page 10: A new kind of BPM with Activiti

10

Transactional Control Flow

Execution

DELETE FROM ACT_RU_EXECUTION WHERE ID_ = ?

Page 11: A new kind of BPM with Activiti

11

Extra convenience in activity types

• Examples• Task lists • JMS message send & receive• Web service send & receive• And… everything you can do in Java

• Activity pluggability

Page 12: A new kind of BPM with Activiti

12

Extra convenience in history

• Optional, default turned on• Log every process instance

and activity instance• Activities at business levelStatistics are valuable

business intelligenceFor FREE

Page 13: A new kind of BPM with Activiti

13

Coming up

• How to implement a process with Activiti• Showing you the nitty-gritty details

• Making you an Activiti-ninja-developer-hero

Page 14: A new kind of BPM with Activiti

14

Demo

• Use case: banks shouldn’t lend money to just anybody• Thorough analysis is needed• All steps needs to be recorded in official documents• Decisions are done based on Excel decision tables

Page 15: A new kind of BPM with Activiti

15

The mortgage process

Page 16: A new kind of BPM with Activiti

16

The mortgage process

= CMIS call

Page 17: A new kind of BPM with Activiti

17

Deployment

• Collection of resources

Deployment deployment = repositoryService .createDeployment() .addClasspathResource(“mortgage-process.bpmn20.xml”) .addInputStream(“mortgage.png”) .addZipInputStream(“mortgage-docs.zip”) …

Deployment

Page 18: A new kind of BPM with Activiti

18

Deployment

• “Deploying”

repositoryService .createDeployment() .addXXX() … .deploy()

Activiti engine

bpmn

bytes

deployersProcessDefinition

Deployment

Mortgage process

Page 19: A new kind of BPM with Activiti

19

Process versioning

• Markets, customers, products, … change• Business processes change

• Activiti supports versioned process definitions

Process def “mortgage”, version = 1

Process def “mortgage”, version = 2

ProcessInstance processInstanceA = runtimeService.startProcessInstanceByKey(“mortgage”);

repositoryService.createDeployment() .addClasspathResource(“mortgage-process.bpmn20.xml”) .deploy();

ProcessInstance processInstanceB = runtimeService.startProcessInstanceByKey(“mortgage”);

Page 20: A new kind of BPM with Activiti

20

Process versioning

• But what about existing process instances?• They execute according the original process definition• “Phase-out” strategy

• New process instances• Default: latest deployed process definition• Instance migration

runtimeService.startProcessInstanceByKey(“process-key”);

ProcessDefinition procDef = repositoryService.createProcessDefinitionQuery() .name(“myProcess”) .version(2) .singleResult();runtimeService.startProcessInstanceById(procDef.getId());

Latest deployed

Specific version

Page 21: A new kind of BPM with Activiti

21

Starting the process

• ProgrammaticallyBPMN start event

ProcessInstance processInstanceA = runtimeService.startProcessInstanceByKey(“myProces”);

Page 22: A new kind of BPM with Activiti

22

Start form

• Processes often need data to run• Start event can have a start form to capture this data

• Activiti Explorer

FormInstance form = repositoryService.getStartFormInstance(“mortgage”);

Page 23: A new kind of BPM with Activiti

23

Start form

• Activiti Explorer• Supports easy-to-build-and-understand HTML forms

Page 24: A new kind of BPM with Activiti

24

User task

• Wait state• Creates a Task entry in the DB

Page 25: A new kind of BPM with Activiti

25

Service task

• Call custom business logic• Support for

• Delegation to class• Expressions (see later)

Page 26: A new kind of BPM with Activiti

26

Service task

• Soon• Webservice support

Page 27: A new kind of BPM with Activiti

27

Exclusive gateway

• Control flow• Selects 1 (and only 1) outgoing seq-flow

based on the expressions

Page 28: A new kind of BPM with Activiti

Mail task

• Automatic step• Specific service task shipped with Activiti

28

Page 29: A new kind of BPM with Activiti

Unit testing your business processes

• With Activiti, your business processes are an integral part of your software project

• So they should be tested just the same as your regular application code …

• With unit tests !

• Activiti supports both JUnit 3 and JUnit4 style of testing your business processes

• And ships with a lot of convience for testing

• Demo

29Pic from http://silverbackapp.com

Page 30: A new kind of BPM with Activiti

The cool stuff

• That didn’t make it into the demo• But is just too cool not to share with you

• Timers• Script support• Query API• Spring integration• Method expressions• JPA

30

Page 31: A new kind of BPM with Activiti

Timers

• Work is often time constrained• A timer boundary event can be attached

to the boundary of any task or subprocess

31

Page 32: A new kind of BPM with Activiti

Timers

• When timer fires• Current execution(s) inside scope of event are

destroyed and process continues following seq-flow going out the timer event

32

Page 33: A new kind of BPM with Activiti

Script task

• Execute a script embedded in the process definition• Any JSR-223 compliant script language• Opens up powerful capabilities

• Javascript, XPath, CMIS-script (?)

33

<scriptTask id="theScriptTask" name="Execute script" scriptFormat="groovy">  <script>    sum = 0    for (i in inputArray) {      sum += i    } execution.setVariable(“myVar”, sum)  </script></scriptTask>

Page 34: A new kind of BPM with Activiti

Query API

• No need to learn the intern data model • Powerful and uniform query API

• Deployments and process definitions

• Process instances and executions

• History

• Variables

• Tasks, jobs, users, groups, historic activities/process instances/variables, …

34

repositoryService.createProcessDefinitionQuery.keyLike(“%mortgage%”).latest();

runtimeService.createProcessInstanceQuery .processDefinitionKey(“mortgage-process)”.orderByProcessInstanceId().desc();

historyService.createHistoricActivityQuery().processDefinitionId(procDefId) .activityType(“userTask”).orderByDuration().asc();

runtimeService.createProcessInstanceQuery() .variableValueGreaterThan(“amount”, 50000);

Page 35: A new kind of BPM with Activiti

Spring integration

• First-class integration with Spring• Define and inject Activiti process engine and services• Leverage and integrate with Spring transaction

management• Delegate to Spring beans in the process definition• Resource deployment and duplicate filtering for

simplified development• Spring unit testing support

35

Page 36: A new kind of BPM with Activiti

Spring integration

• ProcessEngine as a Spring bean

• Delegate to Spring beans

36

<bean id=“printer” …

Page 37: A new kind of BPM with Activiti

Method expressions and JPA

• Besides the typical expressions that everyone supports, Activiti has

• method expressions• method parameters

• Variables, execution, …

• First-class JPA support• Store JPA entity as process variable

• Seamless integration of domain model with process• Only domain model reference is stored

• Fetch/update is done in original data store

37

Page 38: A new kind of BPM with Activiti

Throwing it all together

38

Process variables

Spring bean

Decision based on JPA entity property

Update JPA entity

Page 39: A new kind of BPM with Activiti

The Activiti Experience

39

• Satisfy your Activiti itch

• One-stop-shop download:• http://www.activiti.org

• Demo: “The Activiti Experience”• Do you have an excuse for not

trying out Activiti later today?