MANNING Tijs Rademakers FOREWORDS BY Tom Baeyens AND Joram Barrez Executable business processes in BPMN 2.0 IN ACTION www.it-ebooks.info <definitions> <process> <startEvent/> <sequenceFlow/> <endEvent/> </process> </definitions> Activiti Designer Activiti Engine Process implementation Web forms Ta sk s Jobs Processes WS REST DB Activiti provides a complete BPM solution, starting with the Activiti Designer to draw your business processes using BPMN. The XML output of the Activiti Designer is deployed to the Activiti Engine that runs the process definition. The Activiti Engine executes automated steps, like calling a web service, as well as manual steps that involve people and web forms. www.it-ebooks.info Activiti in Action www.it-ebooks.info www.it-ebooks.info Activiti in Action EXECUTABLE BUSINESS PROCESSES IN BPMN 2.0 TIJS RADEMAKERS MANNING Shelter Island www.it-ebooks.info For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact Special Sales Department Manning Publications Co. 20 Baldwin Road PO Box 261 Shelter Island, NY 11964 Email: orders@manning.com ©2012 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine. Development editor: Sebastian Stirling Manning Publications Co. Technical proofreader: Andy Verberne 20 Baldwin Road Copyeditor: June Eding PO Box 261 Proofreader: Nermina Miller Shelter Island, NY 11964 Typesetter: Gordan Salinovic Cover designer: Marija Tudor ISBN 9781617290121 Printed in the United States of America 1 2 3 4 5 6 7 8 9 10 – MAL – 17 16 15 14 13 12 www.it-ebooks.info v brief contents PART 1 INTRODUCING BPMN 2.0 AND ACTIVITI 1 1 ■ Introducing the Activiti framework 3 2 ■ BPMN 2.0: what’s in it for developers? 19 3 ■ Introducing the Activiti tool stack 32 4 ■ Working with the Activiti process engine 49 PART 2 IMPLEMENTING BPMN 2.0 PROCESSES WITH ACTIVITI 85 5 ■ Implementing a BPMN 2.0 process 87 6 ■ Applying advanced BPMN 2.0 and extensions 112 7 ■ Dealing with error handling 146 8 ■ Deploying and configuring the Activiti Engine 169 9 ■ Exploring additional Activiti modules 193 PART 3 ENHANCING BPMN 2.0 PROCESSES 223 10 ■ Implementing advanced workflow 225 11 ■ Integrating services with a BPMN 2.0 process 260 12 ■ Ruling the business rule engine 286 www.it-ebooks.info BRIEF CONTENTS vi 13 ■ Document management using Alfresco 311 14 ■ Business monitoring and Activiti 340 PART 4 MANAGING BPMN 2.0 PROCESSES 367 15 ■ Managing the Activiti Engine 369 www.it-ebooks.info vii contents foreword by tom baeyens xv foreword by joram barrez xvii preface xix acknowledgments xxi about this book xxiii about the cover illustration xxviii PART 1 INTRODUCING BPMN 2.0 AND ACTIVITI 1 1 Introducing the Activiti framework 3 1.1 The Activiti tool stack 4 1.2 Getting to know Activiti 5 A little bit of history 5 ■ The basics of the Activiti Engine 6 Knowing the competitors 7 1.3 Installing the Activiti framework 9 1.4 Implementing your first process in Activiti 11 Say hello to Activiti 12 ■ Implementing a simple book order process 14 1.5 Summary 18 www.it-ebooks.info CONTENTS viii 2 BPMN 2.0: what’s in it for developers? 19 2.1 Taking a closer look at BPM 20 Walking around the BPM life cycle 21 2.2 Evolution to BPMN 2.0 22 Wasn’t there a standard called WS-BPEL? 22 ■ And then there was BPMN 2.0 23 ■ Getting your head around all the BPMN 2.0 constructs 24 2.3 Introducing BPMN 2.0 from a developer’s viewpoint 26 High-level modeling with BPMN 2.0 26 ■ Detailed process modeling 28 2.4 Summary 31 3 Introducing the Activiti tool stack 32 3.1 Working with the Activiti Modeler 33 Installing the Activiti Modeler 33 ■ Modeling processes with the Activiti Modeler 34 3.2 Adding technical details with the Activiti Designer 36 Getting up and running with Activiti Designer 36 ■ Designing a process from scratch 37 ■ Testing processes with the Activiti Designer 39 ■ Importing a Modeler process into the Designer 42 3.3 Managing the Engine using the Activiti Explorer 45 3.4 Processes and tasks with the Activiti Explorer 46 3.5 Summary 48 4 Working with the Activiti process engine 49 4.1 Creating an Activiti development environment 50 Getting familiar with the Activiti libraries 50 ■ Mavenizing your Activiti project 51 ■ Logging in the Activiti Engine 53 Developing and testing with the Activiti Engine 54 4.2 Using the Activiti Engine API 56 Starting process instances with the RuntimeService 57 ■ Working with user tasks via the TaskService 59 ■ Deleting process definitions with the RepositoryService 64 ■ Creating users, groups, and memberships with the IdentityService 66 ■ A sneak peek into the past with the HistoryService 67 4.3 Using plain Java to do BPM 72 Java service task with class definition 73 ■ Introducing asynchronous behavior 75 ■ Java service task with class definition and field extensions 76 ■ Java service task with method and value expressions 78 www.it-ebooks.info [...]... ■ 11.5 12 Summary 285 Ruling the business rule engine 286 12.1 Introducing business rule management 287 What’s a business rule? 287 Business rule management systems 288 Using different types of rules in business processes 289 Business rule management in BPMN 2.0 291 ■ ■ ■ 12.2 Entering the rule world of Drools 292 Drools, the business logic integration platform 292 Introducing Drools Expert 293 Hands-on... testing the document-aware process definition 13.4 14 Summary 338 Business monitoring and Activiti 340 14.1 Storing Monitoring business processes 341 Introducing business activity monitoring (BAM) 341 Introducing complex event processing (CEP) 343 www.it-ebooks.info 336 xiii CONTENTS 14.2 Meeting the Esper framework 345 Kick-starting Esper 14.3 345 Introducing event windows ■ Monitoring Activiti processes. .. code listings Roadmap The book has 14 chapters divided into 4 parts: ■ ■ ■ ■ Part 1 Part 2 Part 3 Part 4 Introducing BPMN 2.0 and Activiti Implementing BPMN 2.0 processes with Activiti Enhancing BPMN 2.0 processes Managing BPMN 2.0 processes There are also two appendixes Appendix A explains how to work with the source code examples, and appendix B covers elements supported by Activiti BPMN 2.0 Part... CONTENTS 4.4 Using Spring with Activiti 79 Creating a generic Spring configuration for Activiti 79 Implementing a Spring-enabled unit test for Activiti 81 4.5 Summary 84 PART 2 IMPLEMENTING BPMN 2.0 PROCESSES WITH ACTIVITI 85 5 Implementing a BPMN 2.0 process 87 5.1 Introducing a real business process Analyzing the loan request process an XML process file 89 5.2 88 88 ■ Developing script and... Summary 168 Deploying and configuring the Activiti Engine 169 8.1 Choosing between deployment options 170 Embedding the Activiti Engine in a Java application 170 Using a standalone Activiti Engine instance 172 Choosing between the deployment options 175 ■ ■ 8.2 Using a Spring-managed Activiti Engine 176 Creating a process engine from a config file or Java 176 a process engine from a Spring configuration... nice dinners with the Activiti team, we began discussing the possibility of my joining Alfresco to work on Activiti In May 2011, I accepted the offer and was able to begin working on Activiti full-time In the meantime, the writing of this book fell a little behind schedule There was so much interesting work to be done developing the Activiti Designer, working on the Activiti Engine, and starting in a... decisions and sending email Controlling flow with an exclusive gateway an email service task 102 5.5 Deploying processes to the Activiti Engine Understanding the Activiti BAR file 106 the Activiti Engine 107 5.6 5.7 6 101 101 ■ ■ Implementing 106 Deploying processes to Testing the process with Activiti Explorer Summary 111 109 Applying advanced BPMN 2.0 and extensions 112 6.1 Using BPMN 2.0 subprocesses 113... process definitions Chapter 3 offers an overview of the Activiti framework’s main components, including the Activiti Designer and Explorer Finally, in chapter 4, we’ll discuss the Activiti API with several short code examples www.it-ebooks.info www.it-ebooks.info Introducing the Activiti framework This chapter covers ■ Introduction to Activiti ■ Installing the Activiti framework ■ Implementing a BPMN 2.0. .. Taking a process model to 90 Scripting in the Activiti Engine 90 Implementing a Java service task 92 Creating the BPMN 2.0 XML file 93 Testing the process with JUnit 94 ■ ■ 5.3 ■ Interacting with user tasks and Activiti forms 95 Creating forms in Activiti 95 Adding a task form on a start event 96 Testing forms using the FormService 97 Adding user tasks with an escalation workflow 98 ■ ■ 5.4 ■ Handling... Writing LDAP query Implementing the BPMN 2.0 multi-instance activity Configuring a multi-instance activity 246 multi-instance embedded process 247 10.4 11 Implementing a Custom form types and external form rendering 253 Implementing a custom form type 253 rendering 257 10.5 ■ 246 ■ Using external form Summary 259 Integrating services with a BPMN 2.0 process 260 11.1 Invoking services from a BPMN 2.0 . ENHANCING BPMN 2. 0 PROCESSES 22 3 10 ■ Implementing advanced workflow 22 5 11 ■ Integrating services with a BPMN 2. 0 process 26 0 12 ■ Ruling the business. Summary 22 1 PART 3 ENHANCING BPMN 2. 0 PROCESSES 22 3 10 Implementing advanced workflow 22 5 10. 1 Going beyond a simple user task 22 6 Working with subtasks 22 6 ■ Delegating