Alfresco Devcon 2010: A new kind of BPM with Activiti

904 views

Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Alfresco Devcon 2010: A new kind of BPM with Activiti

  1. 1. Tom Baeyens & Joram BarrezAlfrescotwitter: @tombaeyens @jbarrez2
  2. 2. • Founder of Activiti & jBPM• Passionate about Java and BPM• http://processdevelopments.blogspot.com/• Ex-core developer JBossjBPM• Core developer Activiti• http://www.jorambarrez.be/3
  3. 3. • 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• Timers4
  4. 4. • Essence: State machine• Persist state of an execution flow Execution EmplJohn Doe Date 5/10/2010 Doc vacation.xls State Approved5
  5. 5. • 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 Execution • Return6
  6. 6. INSERT INTO ACT_RU_EXECUTION (…, ACTIVITY_ID_, …) values (…, „Wait‟, …) Execution7
  7. 7. • Signal • Load existing execution • Pass data in (optional) • Take transition to “Wait 2” • Stop interpreting process • Update runtime execution • Return Execution8
  8. 8. UPDATE ACT_RU_EXECUTION SET ACTIVITY_ID = „Wait 2‟ Execution9
  9. 9. • 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 Execution • Return10
  10. 10. DELETE FROM ACT_RU_EXECUTION WHERE ID_ = ? Execution11
  11. 11. • Examples • Task lists • JMS message send & receive • Web service send & receive • And… everything you can do in Java• Activity pluggability12
  12. 12. • Optional, default turned on• Log every process instance and activity instance• Activities at business levelStatistics are valuable business intelligenceFor FREE13
  13. 13. • How to implement a process with Activiti • Showing you the nitty-gritty details• Making you an Activiti-ninja-developer-hero14
  14. 14. • 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 tables15
  15. 15. 16
  16. 16. = CMIS call17
  17. 17. • Collection of resources Deployment deployment = repositoryService .createDeployment() .addClasspathResource(“mortgage-process.bpmn20.xml”) .addInputStream(“mortgage.png”) .addZipInputStream(“mortgage-docs.zip”) … Deployment18
  18. 18. • “Deploying” repositoryService .createDeployment() .addXXX() bytes … .deploy() Activiti engine Mortgage process bpmn Deployment deployers ProcessDefinition19
  19. 19. • Markets, customers, products, … change • Business processes change• Activiti supports versioned process definitions ProcessInstanceprocessInstanceA = runtimeService.startProcessInstanceByKey(“mortgage”); repositoryService.createDeployment() Process def .addClasspathResource(“mortgage-process.bpmn20.xml”) “mortgage”, ver sion = 1 .deploy(); ProcessInstanceprocessInstanceB = Process def runtimeService.startProcessInstanceByKey(“mortgage”); “mortgage”, ver sion = 220
  20. 20. • But what about existingprocess 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”); Latest deployed ProcessDefinitionprocDef = repositoryService.createProcessDefinitionQuery() .name(“myProcess”) .version(2) .singleResult(); runtimeService.startProcessInstanceById(procDef.getId());21 Specific version
  21. 21. BPMN start event• Programmatically ProcessInstanceprocessInstanceA = runtimeService.startProcessInstanceByKey(“myProces”);22
  22. 22. • Processes often need data to run • Start event can have a start form to capture this data FormInstance form = repositoryService.getStartFormInstance(“mortgage”);• Activiti Explorer23
  23. 23. • Activiti Explorer • Supports easy-to-build-and-understand HTML forms24
  24. 24. • Wait state• Creates a Task entry in the DB25
  25. 25. • Call custom business logic• Support for • Delegation to class • Expressions (see later)26
  26. 26. • Soon • Webservice support27
  27. 27. • Control flow • Selects 1 (and only 1) outgoing seq-flow based on the expressions28
  28. 28. • Automatic step • Specific service task shipped with Activiti29
  29. 29. • 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 • Demo30 Pic from http://silverbackapp.com
  30. 30. • 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 • JPA31
  31. 31. • Work is often time constrained • A timer boundary event can be attached to the boundary of any task or subprocess32
  32. 32. • When timer fires • Current execution(s) inside scope of event are destroyed and process continues following seq-flow going out the timer event33
  33. 33. • Execute a script embedded in the process definition • Any JSR-223 compliant script language • Opens up powerful capabilities • Javascript, XPath, CMIS-script (?) <scriptTask id="theScriptTask" name="Execute script" scriptFormat="groovy"> <script> sum = 0 for (i in inputArray) { sum += i } execution.setVariable(“myVar”, sum) </script> </scriptTask>34
  34. 34. • No need to learn the intern data model • Powerful and uniform query API • Deployments and process definitions repositoryService.createProcessDefinitionQuery.keyLike(“%mortgage%”).latest(); • Process instances and executions runtimeService.createProcessInstanceQuery .processDefinitionKey(“mortgage-process)”.orderByProcessInstanceId().desc(); • History historyService.createHistoricActivityQuery().processDefinitionId(procDefId) .activityType(“userTask”).orderByDuration().asc(); • Variables runtimeService.createProcessInstanceQuery() .variableValueGreaterThan(“amount”, 50000); • Tasks, jobs, users, groups, historic activities/process instances/variables, …35
  35. 35. • 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 support36
  36. 36. • ProcessEngine as a Spring bean • Delegate to Spring beans <bean id=“printer” …37
  37. 37. • 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 store38
  38. 38. Update JPA entity Decision based on Spring bean JPA entity property Process variables39
  39. 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? 40

×