alfresco devcon 2010: a new kind of bpm with activiti
DESCRIPTION
TRANSCRIPT
![Page 1: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/1.jpg)
1
A new kind of BPM with Activiti
Tom Baeyens & Joram BarrezAlfresco
twitter: @tombaeyens @jbarrez
![Page 2: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/2.jpg)
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: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/3.jpg)
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: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/4.jpg)
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: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/5.jpg)
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: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/6.jpg)
6
Transactional Control Flow
INSERT INTO ACT_RU_EXECUTION (…, ACTIVITY_ID_, …) values (…, ‘Wait’, …)
Execution
![Page 7: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/7.jpg)
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: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/8.jpg)
8
Transactional Control Flow
UPDATE ACT_RU_EXECUTION SET ACTIVITY_ID = ‘Wait 2’
Execution
![Page 9: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/9.jpg)
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: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/10.jpg)
10
Transactional Control Flow
Execution
DELETE FROM ACT_RU_EXECUTION WHERE ID_ = ?
![Page 11: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/11.jpg)
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: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/12.jpg)
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: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/13.jpg)
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: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/14.jpg)
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: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/15.jpg)
15
The mortgage process
![Page 16: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/16.jpg)
16
The mortgage process
= CMIS call
![Page 17: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/17.jpg)
17
Deployment
• Collection of resources
Deployment deployment = repositoryService .createDeployment() .addClasspathResource(“mortgage-process.bpmn20.xml”) .addInputStream(“mortgage.png”) .addZipInputStream(“mortgage-docs.zip”) …
Deployment
![Page 18: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/18.jpg)
18
Deployment
• “Deploying”
repositoryService .createDeployment() .addXXX() … .deploy()
Activiti engine
bpmn
bytes
deployersProcessDefinition
Deployment
Mortgage process
![Page 19: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/19.jpg)
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: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/20.jpg)
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: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/21.jpg)
21
Starting the process
• ProgrammaticallyBPMN start event
ProcessInstance processInstanceA = runtimeService.startProcessInstanceByKey(“myProces”);
![Page 22: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/22.jpg)
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: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/23.jpg)
23
Start form
• Activiti Explorer• Supports easy-to-build-and-understand HTML forms
![Page 24: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/24.jpg)
24
User task
• Wait state• Creates a Task entry in the DB
![Page 25: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/25.jpg)
25
Service task
• Call custom business logic• Support for
• Delegation to class• Expressions (see later)
![Page 26: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/26.jpg)
26
Service task
• Soon• Webservice support
![Page 27: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/27.jpg)
27
Exclusive gateway
• Control flow• Selects 1 (and only 1) outgoing seq-flow
based on the expressions
![Page 28: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/28.jpg)
Mail task
• Automatic step• Specific service task shipped with Activiti
28
![Page 29: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/29.jpg)
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: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/30.jpg)
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: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/31.jpg)
Timers
• Work is often time constrained• A timer boundary event can be attached
to the boundary of any task or subprocess
31
![Page 32: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/32.jpg)
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: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/33.jpg)
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: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/34.jpg)
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: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/35.jpg)
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: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/36.jpg)
Spring integration
• ProcessEngine as a Spring bean
• Delegate to Spring beans
36
<bean id=“printer” …
![Page 37: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/37.jpg)
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: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/38.jpg)
Throwing it all together
38
Process variables
Spring bean
Decision based on JPA entity property
Update JPA entity
![Page 39: Alfresco Devcon 2010: A new kind of BPM with Activiti](https://reader033.vdocuments.us/reader033/viewer/2022051411/547c1a18b47959a7508b45d1/html5/thumbnails/39.jpg)
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?