Upload
alfresco-software
View
4.487
Download
2
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
1
A new kind of BPM with Activiti
Tom Baeyens & Joram BarrezAlfresco
twitter: @tombaeyens @jbarrez
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/
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
4
Activiti Engine
• Essence: State machine• Persist state of an execution flow
Execution
Empl John Doe
Date 5/10/2010Doc vacation.xlsState Approved
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
6
Transactional Control Flow
INSERT INTO ACT_RU_EXECUTION (…, ACTIVITY_ID_, …) values (…, ‘Wait’, …)
Execution
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
8
Transactional Control Flow
UPDATE ACT_RU_EXECUTION SET ACTIVITY_ID = ‘Wait 2’
Execution
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
10
Transactional Control Flow
Execution
DELETE FROM ACT_RU_EXECUTION WHERE ID_ = ?
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
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
13
Coming up
• How to implement a process with Activiti• Showing you the nitty-gritty details
• Making you an Activiti-ninja-developer-hero
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
15
The mortgage process
16
The mortgage process
= CMIS call
17
Deployment
• Collection of resources
Deployment deployment = repositoryService .createDeployment() .addClasspathResource(“mortgage-process.bpmn20.xml”) .addInputStream(“mortgage.png”) .addZipInputStream(“mortgage-docs.zip”) …
Deployment
18
Deployment
• “Deploying”
repositoryService .createDeployment() .addXXX() … .deploy()
Activiti engine
bpmn
bytes
deployersProcessDefinition
Deployment
Mortgage process
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”);
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
21
Starting the process
• ProgrammaticallyBPMN start event
ProcessInstance processInstanceA = runtimeService.startProcessInstanceByKey(“myProces”);
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”);
23
Start form
• Activiti Explorer• Supports easy-to-build-and-understand HTML forms
24
User task
• Wait state• Creates a Task entry in the DB
25
Service task
• Call custom business logic• Support for
• Delegation to class• Expressions (see later)
26
Service task
• Soon• Webservice support
27
Exclusive gateway
• Control flow• Selects 1 (and only 1) outgoing seq-flow
based on the expressions
Mail task
• Automatic step• Specific service task shipped with Activiti
28
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
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
Timers
• Work is often time constrained• A timer boundary event can be attached
to the boundary of any task or subprocess
31
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
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>
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);
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
Spring integration
• ProcessEngine as a Spring bean
• Delegate to Spring beans
36
<bean id=“printer” …
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
Throwing it all together
38
Process variables
Spring bean
Decision based on JPA entity property
Update JPA entity
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?