1. Trang chủ
  2. » Công Nghệ Thông Tin

Activiti in Action EXECUTABLE BUSINESS PROCESSES IN BPMN 2.0 pot

459 1,6K 1
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Activiti in Action Executable Business Processes in BPMN 2.0
Tác giả Tijs Rademakers
Người hướng dẫn Tom Baeyens, Joram Barrez
Trường học Shelter Island
Chuyên ngành Business Process Management
Thể loại Book
Năm xuất bản Unknown
Thành phố Shelter Island
Định dạng
Số trang 459
Dung lượng 15,22 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

contents foreword by tom baeyens xv foreword by joram barrez xvii preface xix acknowledgments xxi about this book xxiii about the cover illustration xxviii P ART 1 I NTRODUCING BPMN 2.0

Trang 1

Tijs Rademakers

FOREWORDS BY Tom Baeyens

AND Joram Barrez

Executable business processes in BPMN 2.0

IN ACTION

Trang 3

Activiti in Action

Trang 6

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 StirlingManning 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

Trang 7

brief contents

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

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

10 ■ Implementing advanced workflow 225

11 ■ Integrating services with a BPMN 2.0 process 260

12 ■ Ruling the business rule engine 286

Trang 8

BRIEF CONTENTS

vi

13 ■ Document management using Alfresco 311

14 ■ Business monitoring and Activiti 340

15 ■ Managing the Activiti Engine 369

Trang 9

contents

foreword by tom baeyens xv foreword by joram barrez xvii preface xix

acknowledgments xxi about this book xxiii about the cover illustration xxviii

P ART 1 I NTRODUCING BPMN 2.0 AND A CTIVITI 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 5The 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 12Implementing a simple book order process 14

1.5 Summary 18

Trang 10

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? 22And then there was BPMN 2.0 23Getting 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 26Detailed 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 33Modeling processes with the Activiti Modeler 34

3.2 Adding technical details with the Activiti Designer 36

Getting up and running with Activiti Designer 36Designing a process from scratch 37Testing processes with the Activiti Designer 39Importing 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 50Mavenizing your Activiti project 51Logging 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 57Working with user tasks via the TaskService 59Deleting process

definitions with the RepositoryService 64Creating users, groups, and memberships with the IdentityService 66A sneak peek into the past with the HistoryService 67

4.3 Using plain Java to do BPM 72

Java service task with class definition 73Introducing asynchronous behavior 75Java service task with class definition and field extensions 76Java service task with method and value expressions 78

Trang 11

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

P ART 2 I MPLEMENTING BPMN 2.0 PROCESSES

WITH A CTIVITI 85

5 Implementing a BPMN 2.0 process 87

5.1 Introducing a real business process 88

Analyzing the loan request process 88Taking a process model to

an XML process file 89

5.2 Developing script and service tasks 90

Scripting in the Activiti Engine 90Implementing a Java service task 92Creating the BPMN 2.0 XML file 93Testing the process with JUnit 94

5.3 Interacting with user tasks and Activiti forms 95

Creating forms in Activiti 95Adding a task form on a start event 96Testing forms using the FormService 97Adding user tasks with an escalation workflow 98

5.4 Handling decisions and sending email 101

Controlling flow with an exclusive gateway 101Implementing

an email service task 102

5.5 Deploying processes to the Activiti Engine 106

Understanding the Activiti BAR file 106Deploying processes to the Activiti Engine 107

5.6 Testing the process with Activiti Explorer 109 5.7 Summary 111

6 Applying advanced BPMN 2.0 and extensions 112

6.1 Using BPMN 2.0 subprocesses 113

Background to BPMN subprocesses 113Implementing embedded subprocesses 114Implementing standalone subprocesses 120

6.2 Working with BPMN 2.0 parallel gateways 126

Implementing a process with a parallel gateway 127Testing a process with a parallel gateway 129

6.3 Adding a JPA extension to your process 130

Modeling a process with a database entity 131Implementing a process with JPA extensions 132Testing a process with JPA extensions 136

Trang 12

6.4 Using execution and task listeners 137

Modeling a process with execution and task listeners 138 Implementing execution and task listeners 139Testing the event stack list 142

6.5 Summary 144

7 Dealing with error handling 146

7.1 Choosing between error handling options 147

Using error end and boundary events 147Using Java logic for error handling 149Using both error handling approaches together 151

7.2 Implementing error handling with BPMN 2.0

constructs 152

Designing the sales opportunity process solution 152Modeling the sales opportunity business process 154Implementing a BPMN process with the Activiti Designer 155Implementing service tasks that invoke a web service 160Testing the sales opportunity process solution 163

7.3 Implementing error handling using Java logic 165 7.4 Summary 168

8 Deploying and configuring the Activiti Engine 169

8.1 Choosing between deployment options 170

Embedding the Activiti Engine in a Java application 170Using

a standalone Activiti Engine instance 172Choosing between the deployment options 175

8.2 Using a Spring-managed Activiti Engine 176

Creating a process engine from a config file or Java 176Creating

a process engine from a Spring configuration 177

8.3 Configuring the Activiti Engine 181

Basic configuration overview of the Activiti Engine 181Configuring the Activiti Engine database options 182Exploring other configuration options 184

8.4 REST communication with the Activiti Engine 185

Introducing the Activiti REST API 185Implementing a new Activiti REST service 187

8.5 Summary 192

Trang 13

9 Exploring additional Activiti modules 193

9.1 Spring annotations 194 9.2 Building an Activiti JEE 6 application 196

Implementing EJB service tasks 197Implementing a JSF process application using CDI 202

9.3 Deploying Activiti to an OSGi container 209

Introducing the OSGi standard 209Using Apache Karaf as an OSGi container 210Installing the Activiti OSGi bundle 211 Getting a list of process definitions in Apache Karaf 215

Building a process and task OSGi bundle 217

9.4 Summary 221

P ART 3 E NHANCING BPMN 2.0 PROCESSES 223

10 Implementing advanced workflow 225

10.1 Going beyond a simple user task 226

Working with subtasks 226Delegating tasks 231 Implementing the four-eye principle 233

10.2 Managing the user identities in an LDAP server 236

Installing Apache Directory Server 237Writing LDAP query logic for the Activiti Engine 241

10.3 Implementing the BPMN 2.0 multi-instance activity 246

Configuring a multi-instance activity 246Implementing a multi-instance embedded process 247

10.4 Custom form types and external form rendering 253

Implementing a custom form type 253Using external form rendering 257

10.5 Summary 259

11 Integrating services with a BPMN 2.0 process 260

11.1 Invoking services from a BPMN 2.0 process 261

Calling services via a service task 261Separating process logic from integration logic 262

11.2 Using the BPMN 2.0 web service task 264

11.3 Integrating with Apache Camel 268

Introducing Apache Camel 268Sending and receiving process messages with Apache Camel 272

Trang 14

11.4 Integrating with Mule ESB 276

Introducing Mule ESB 276Sending and receiving process messages with Mule ESB 280

11.5 Summary 285

12 Ruling the business rule engine 286

12.1 Introducing business rule management 287

What’s a business rule? 287Business rule management systems 288Using different types of rules in business processes 289Business rule management in BPMN 2.0 291

12.2 Entering the rule world of Drools 292

Drools, the business logic integration platform 292Introducing Drools Expert 293Hands-on with Drools Expert 296Using spreadsheets to create Drools decision tables 298

12.3 Integrating Drools with Activiti 301

Activiti and the business rule task 301Using business rules in a process definition 303

12.4 Creating a web-based rule editor 307

Introducing flexibility with a custom rule authoring application 307

12.5 Summary 309

13 Document management using Alfresco 311

13.1 Introducing Alfresco Community 312

Installing Alfresco Community 312Introducing Activiti integration in Alfresco 315

13.2 Using CMIS to store and retrieve documents 320

Retrieving folder content from Alfresco using CMIS 320Storing

a new document version 323

13.3 Adding documents to a BPMN 2.0 process definition 326

Working with task and process instance attachments 326 Implementing a document-aware process definition 328 Deploying and testing the document-aware process definition 336

13.4 Summary 338

14 Business monitoring and Activiti 340

14.1 Monitoring business processes 341

Introducing business activity monitoring (BAM) 341 Introducing complex event processing (CEP) 343

Trang 15

14.2 Meeting the Esper framework 345

Kick-starting Esper 345Introducing event windows 347

14.3 Monitoring Activiti processes with Esper 355

Integrating Activiti and Esper 355Testing the Activiti and Esper setup 356

14.4 Monitoring Activiti with a Vaadin dashboard 359

An Activiti BAM architecture 359Producing REST events with Activiti 360Setting up the Vaadin application with the Esper REST service 362Monitoring Activiti processes with a Vaadin dashboard 364

14.5 Summary 366

P ART 4 M ANAGING BPMN 2.0 PROCESSES 367

15 Managing the Activiti Engine 369

15.1 Working with the Activiti database 370

Understanding the Activiti runtime execution database model 370 Understanding the Activiti history database model 377Creating the Activiti database 379Upgrading the Activiti database 380

15.2 Dealing with process versioning 381

15.3 Understanding the job executor 384

15.4 Building an administrator dashboard 386

15.5 Summary 392

appendix A Working with the source code 395

appendix B BPMN 2.0 supported elements in Activiti 398

index 418

Trang 17

foreword by tom baeyens

Business processes represent the core functions of an organization If these corefunctions are implemented inefficiently, a company gives its competitors an easyadvantage Business Process Management (BPM) is nothing more than ensuring that

an organization is run well and remains in good shape For small companies, a singleperson might be able to oversee everything that is going on and deal with situations

as they occur But when companies grow larger and processes expand, it’s harder tomaintain control Work is delegated, people start optimizing their own responsibili-ties, and an overview can quickly get lost Over the long run, constant monitoringand improving of business processes are what separates good organizations fromexcellent ones

One aspect of managing business processes is automation Despite big ments in software technology in the last decade, building custom software to supportbusiness processes remains expensive for enterprises

Traditional BPM Systems (BPMSs) have attempted to simplify the creation of ware for monitoring business processes The biggest advantage of BPMSs is that they’rebased on flowchart diagrams Business managers and technical team members canunderstand these diagrams, which helps bring communication of requirements to anew level

The bottleneck of traditional BPMSs has been flexibility BPMSs that focus on nical integration with backend systems over web services (for example, BPEL) are notsuited for business people And BPMSs that focus on business diagrams are typicallylimited in backend integration and scripting

Trang 18

tech-FOREWORD BY TOM BAEYENS

xvi

This lack of flexibility is why I started building a home-brewed process engine back

in 2002 Initially, the goal was to build an interpreter for state machines It was muchlater that I heard from many developers that they had gone through the same initialphase Originally, my process engine was intended as an internal project for which Iwas doing Java consulting

Without expectations and without really knowing what I was getting myself into, Ipublished the project on SourceForge as jBPM My reaction to the first forum post was,

“Cool! Someone found my engine!”—and this motivated me to improve Many moreforum posts kept me going until JBoss came along and asked me to develop it further After the Business Process Model and Notation (BPMN) standard was introduced,

we realized that it would be crucial to have an Apache-licensed implementation of

BPMN jBPM’s LGPL could pose a problem for mass adoption At the same time,Alfresco needed an Apache-based BPMN engine, so the company hired me, and that ishow Activiti was born Because of the different licenses, we couldn’t use any of the

jBPM code, so we had to write it from scratch at Alfresco: but this became an nity to revisit all the key architectural decisions that had been made before

During the evolution of jBPM, leading up to Activiti, I took a new approach tothe old problem Initially, the focus was on state machines, but eventually we con-structed an engine to match the way business people and developers collaborate Wedesigned the engine in such a way that it would allow business people to define thegraphical flow of the process and, at the same time, give developers the opportunity

to bind program logic inside the process flows In addition, the engine was weight and integrated easily into any Java environment The result was what we callembeddable BPM

light-BPMN is a recent standard that has emerged from a long list of predecessors in the

BPM space It describes the shapes and connections for drawing business-process grams as well as their meanings and file formats BPMN is different because of its clearfocus on the business side and process modeling, whereas earlier standards focusedmore on the technical aspects

In this book, Tijs has included concrete instructions for developers, technical agers, and business analysts to start building BPMN process solutions with Activiti Thebook includes a comprehensive overview of the Activiti framework, the ActivitiEngine, and BPMN But Tijs goes beyond the basics and describes how to integratethese with a rule engine and web-based services

The reader will get a thorough understanding of BPM technology as it is applied intoday’s enterprise environments This is definitely the most practical guide to BPMN

using Activiti as the engine

TOM BAEYENS

ACTIVITI AND JBPM FOUNDER

CHIEFBPM ARCHITECT, ALFRESCO

Trang 19

foreword by joram barrez

A picture is worth a thousand words

I believe this is a saying that exists in every culture around the world And, truly, ourminds are impressive image-processing machines, spotting structure and anomalies in

a fraction of a second Yet we tend to base much of our daily communication, bothpersonal and professional, on the written word

As software developers, we live in the most interesting of times, with the WorldWide Web, the mobile (r)evolution, and the movement to the cloud with a clear focus

on consumers Yet the building process of that software remains complex—we duce pages and pages of lengthy documents to describe what we would like to seeemerge from that ocean of zeroes and ones

What if there were a way to improve this situation? As it happens, improving thissituation is the main goal of those who are involved with BPM

I started my career as a typical Java developer, a generalist doing tids and tads ofeverything involving Java One day, out of the blue, I was assigned to a jBPM project Atthat point, I had never heard of BPM or anything close to it Long story short: I fell inlove I devoted my days, nights, and weekends to understanding the inner workings ofthe engine Open source is a powerful potion, and I drank it The community washard to please (I got an “rtfm” on my first post) but responsive to those who were will-ing to learn and to share their knowledge

It was, as the French would say, a coup de foudre (love at first sight) I worked on BPM

projects coding during the day, and I lurked on the forums at night And then it pened About a year after my first encounter with BPM, I met Tom Baeyens, the proj-ect lead of jBPM at the time, at a seminar where we both were speakers We connected

Trang 20

hap-FOREWORD BY JORAM BARREZ

is of great value here It may seem simplistic, but by defining how certain shapes havespecific meanings, not only can you visualize your workflows, you can find others in theindustry who speak the same language The fact that version 2.0 also includes executionsemantics adds the next level of power: not only do the diagrams become standardized,but now you can switch the engine that’s executing the diagrams with any BPMN 2.0–compliant engine—not that there is any reason to switch from Activiti, of course!

As a Java developer, I used to loathe BPM suites—big black boxes that cost tons ofmoney to produce pictures Every sane developer understands that pictures will nevermake it into stable, performant software That is why you will love Activiti: it is builtwith benefits for business users in mind, without forgetting the developers All thecode is open source—if something bothers you or isn’t clear, you can join our discus-sions on the forum Activiti in its simplest form is a library, a JAR, one among many,embeddable in every Java project, be it EE, Spring, or OSGi With Activiti, you writeunit tests just as you are used to doing But instead of testing code, you are testing pro-cesses—based on diagrams that you and the business people discussed and under-stood—enriched with Java code to make them do exactly what you want them to do.Then you integrate them with other components exactly as you envisioned

I touch only briefly here on the benefits of BPM and the power of Activiti Tijs does

an outstanding job of covering every facet of Activiti in great detail, and I’m excitedand thankful that he put so much time into this book project Software and opensource frameworks in general rise or fall with the available documentation, and it’s mybelief that this is a superb book that provides much-needed, detailed information.There currently is no better source of knowledge on Activiti and BPMN 2.0 Period Think about it: processes are all around us Without processes, a companywouldn’t exist or, at least, it wouldn’t make money for long Every company needs pro-cesses to fulfill its goals And in this quickly changing world, opportunities exist every-where, from mobile integration in the workflow to massive cloud servicesorchestrations It’s up to you to grab them

JORAM BARREZ

COFOUNDER OF ACTIVITI

CORE ACTIVITI DEVELOPER, ALFRESCO

Trang 21

preface

Writing this book was a life-changer for me After I wrote Open Source ESBs in Action for

Manning a few years ago, I focused on my daily job for some time, working with opensource enterprise integration frameworks like Mule, Camel, ServiceMix, and SpringIntegration My work, over time, drove me to designing and developing processes and

BPM, and I started using jBPM and WebSphere Process Server Then I learned that thefounder of the jBPM project, Tom Baeyens, was leaving JBoss to work on a new opensource project, which was in stealth mode at that time (early 2010) When the firstalpha version of Activiti was released, I told myself I had to contribute to that project,one way or another

A piece that was missing in the first stages of the Activiti project was an Eclipseplug-in I had some email conversations with Tom about contributing the plug-in toActiviti We met and he told me that his goal was to disrupt the process engine spacewith the Activiti project My enthusiasm grew even more and I offered my time to startworking on a first version of the Activiti Designer Together with my former col-leagues, Tiese Barrell, Yvo Swillens, and Ron van Liempd, we were able to deliver afirst version within a couple of months

As we became part of the Activiti developer community, my hands were itching tostart writing a book about Activiti I felt that a great open source process engine wouldneed a detailed book to describe all the possibilities and potential it offers Manningwas eager to publish a book about Activiti, and, together with Ron, we started writing

in the autumn of 2010 We had a hard time keeping up with the frequent releases andthe new functionality that kept on coming But, it also was a lot of fun to be able towrite about a new functionality that was just (or about to be) released

Trang 22

After a few meet-ups with the Activiti developer community and a couple of nicedinners with the Activiti team, we began discussing the possibility of my joiningAlfresco to work on Activiti In May 2011, I accepted the offer and was able to beginworking 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 onthe Activiti Engine, and starting in a new job, that time caught up with me After Ihad settled in a bit, I took up the writing task again and began working on theremaining chapters

So here I am, at the end of the process I’ve switched from being a consultant to anopen source software engineer, and I’m close to completing my second book And, justlike with my previous book, I have a new family addition coinciding with the book’srelease I hope you will enjoy reading this book as much as I loved writing it!

Trang 23

acknowledgments

Many people deserve thanks for helping me with this book project First of all, I want

to thank Ron for starting this adventure with me and for his contributions to the book

A big thank you to the guys on the Activiti team—Tom, Joram, and Frederik—forstarting this great open source project and for all the help they gave me during the writ-ing of the book Special thanks to Tom and Joram for kindly contributing the forewords I’d also like to thank the guys at camunda (Bernd and Daniel, in particular) fortheir contribution to the Activiti project and for their help when I was writing aboutthe camunda fox cycle and the Activiti CDI module

Thanks to Balsamiq Studios and Giacomo “Peldi” Guilizzoni for providing licensesfor their great Balsamiq tool I really enjoyed creating the graphics for this book Thanks to Tiese Barrell and Yvo Swillens for their enthusiasm and developmentwork on the Activiti Designer Together we became part of the great Activiti devel-oper community

A special thank-you to Andy Verberne for his work on the technical proofread ofthe final manuscript (again)

Without the patience of my lovely Ankie, the writing of this book would not havebeen possible She managed to love me, even after long working days and in spite of

my sometimes grumpy communication when examples were not working as expected.Liv and Noah, thank you for all the joy you bring to my life Thanks to my parents andparents-in-law for their love and interest in my writing

Thanks also to the following reviewers of the manuscript who read it and providedfeedback during the various stages of its development: Gil Goldman, Michał Minicki,

Trang 25

about this book

Activiti is an open source Business Processing Model and Notation (BPMN) 2.0 processengine framework that provides an environment for running your business and tech-nical processes It’s a project funded by Alfresco and established by jBPM founder TomBaeyens Activiti provides much more functionality than simply running BPMN 2.0 pro-cesses in a rock-solid way It provides a web-based modeling tool for business analysts, anEclipse plug-in for developers, and a web application to work with and manage the pro-cesses In addition, Activiti community members, including SpringSource, FuseSource,MuleSoft, and camunda, have implemented further functionality like full Spring inte-gration, an OSGi bundle, Mule and Camel integration, and a CDI module

This book is written by one of the Activiti core developers and the lead developer

of the Activiti Designer component It contains loads of examples to help you stand the BPMN 2.0 language and how to work with all the extensions Activiti provides

under-In the final chapters, the book goes beyond Activiti’s core functionality and shows how

to do CMIS communication from a process definition and how to implement a ness activity monitoring environment using the open source Esper framework You should not expect to find examples of all the nitty-gritty details of the BPMN 2.0specification Instead, the focus is on Activiti-supported elements and the most commonuse cases for developing process definitions

You also won’t find in-depth discussions of the business side of BPM Many otherbooks focus on the business perspectives of BPM; this book focuses on the technicalaspects of BPM, mostly on BPMN 2.0 and Activiti

Trang 26

ABOUT THIS BOOK

xxiv

Who should read this book?

This book is written for everyone who’s interested in learning about Activiti In tion, it’s a great way to learn about BPMN 2.0 from a practical perspective Every devel-oper, process designer and analyst, or architect will benefit from the information andexamples provided to learn about the basics and details of the Activiti framework.With the technical perspective offered in this book, you shouldn’t be afraid of the Javaand XML code listings

addi-Roadmap

The book has 14 chapters divided into 4 parts:

■ Part 1 Introducing BPMN 2.0 and Activiti

■ Part 2 Implementing BPMN 2.0 processes with Activiti

■ Part 3 Enhancing BPMN 2.0 processes

■ Part 4 Managing BPMN 2.0 processes

There are also two appendixes Appendix A explains how to work with the sourcecode examples, and appendix B covers elements supported by Activiti BPMN 2.0 Part 1 shows you how to get started with the Activiti framework and explains thebackground of the BPMN 2.0 standard You are introduced to the different compo-nents of the Activiti framework and developing with the Activiti API

Chapter 1 introduces the Activiti framework and shows you how to set up the iti default environment At the end of the chapter, you implement your first simple

Activ-BPMN 2.0 process definition and test it with a simple JUnit test

Chapter 2 provides a short introduction to Business Process Management Here,you’ll learn about the background of the BPMN 2.0 standard, compared with otherstandards like WS-BPEL Finally, you are introduced to core BPMN 2.0 elements Chapter 3 provides an overview of all the components of the Activiti framework,including the Activiti Modeler, Activiti Designer, Activiti Explorer, and the camundafox cycle Using a simple process example, we walk through the components andyou’ll learn how to model, design, and deploy a BPMN 2.0 process definition

Chapter 4 gives an overview of the Activiti API, starting with short code examplesillustrating the main Activiti interfaces Then, you’ll learn how to implement Javalogic in a BPMN 2.0 process definition and how to work with Spring beans

In part 2, we shift the focus from understanding the Activiti framework and

BPMN 2.0 to using them to develop process definitions We discuss and use most ofthe supported BPMN 2.0 elements and talk about important topics like error han-dling and deploying process definitions to an Activiti Engine In the final chapter, weexplore additional modules provided by the Activiti framework, such as CDI

andOSGi

Chapter 5 shows how to implement a full-blown process definition using Activiti

We explore the workflow and form capabilities of the Activiti Engine and you’ll learnhow to use an email task to send emails during process execution

Trang 27

ABOUT THIS BOOK xxv

Chapter 6 introduces a number of advanced BPMN 2.0 constructs and Activitiextensions You’ll learn about multiple execution paths using the parallel gateway andhow to structure larger process definitions using standalone or embedded subpro-cesses You also are introduced to the JPA and listener Activiti extensions

Chapter 7 describes ways to deal with error handling in BPMN 2.0 processes Youcan use the standard error end event and boundary error event or implement anapproach using Java exceptions and multiple outgoing sequence flows

Chapter 8 talks about ways to deploy the Activiti Engine in your environment Youcan choose an embedded approach, using only Activiti JARs, or go for a standaloneapproach using the Activiti RESTAPI At the end of chapter, you’ll also learn how toimplement an additional REST service when necessary

Chapter 9 shows how to make use of the Activiti OSGi bundle and the CDI module.With the OSGi bundle, you can deploy Activiti on an OSGi container like Apache Karafand take advantage of the flexibility offered by that platform The Activiti CDI moduleprovides integration with the Contexts and Dependency Injection JEE framework Youcan use handy annotations to quickly build a JSF process and workflow application

In part 3, we focus on more advanced features and extensions to the Activitiframework In the previous two parts, we looked at the basic functionality of Activitiand BPMN 2.0, so now it’s time to step up and talk about advanced ways of usingActiviti We integrate Activiti with the Drools rule engine, the Alfresco documentmanagement system, Mule and Camel for external communication, and Esper forbusiness activity monitoring

Chapter 10 discusses advanced workflow features with subtasks, task delegation,and the four-eye principle workflow pattern We also show how to use an LDAP serverfor identity management and how to use the BPMN 2.0 multi-instance construct And,finally, we look at how to implement additional form types and go for an externalform-rendering approach

Chapter 11 shows how you can communicate with external services and tions to execute business logic that is necessary during process execution With theActiviti Mule and Camel modules, it’s simple to use the powerful features these frame-works provide to implement all kinds of communication logic

Chapter 12 provides a detailed overview of how to use the Drools rule engine withActiviti business rule tasks We start with an introduction to the Drools framework andimplement a couple of rule examples After you implement a process definition con-taining two business rule tasks, you’ll learn how to implement a Vaadin web applica-tion where you can change deployed rules in real time

Chapter 13 shows how Activiti is used in the open source Alfresco product and howyou can use the CMIS standard (with Apache Chemistry) to communicate withAlfresco from a process definition

Chapter 14 introduces business activity monitoring with Activiti using the opensource Esper framework You’ll learn how to fire events to Esper using Activiti listen-ers and how to implement eventing logic in Esper to combine events into useful

Trang 28

ABOUT THIS BOOK

Chapter 15 discusses important topics that are needed to run processes on the iti Engine successfully First, we look at the database model of the Activiti Engine indetail, and then we move on to dealing with process versioning Then, you’ll see howjobs are handled in the Activiti Engine using the asynchronous job executor implemen-tation And, finally, you’ll learn how you can extend the Activiti Explorer with additionalmanagement functionality, like a report of all running and completed process instances Appendix A provides an overview of all the projects you’ll find in the book’s sourcecode Pointers are given on where each project is used in which chapter of the book.Appendix B provides a detailed overview of the BPMN 2.0 elements supported by theActiviti Engine

Activ-Code conventions and downloads

Source code in listings or in text appears in a fixed-width font like this to separate

it from ordinary text Code annotations accompany many of the listings, highlightingimportant concepts In some cases, numbered cueballs link to additional explanationsthat follow the listing

There are many code examples in this book The process definitions are describedusing XML code that shows the BPMN 2.0 XML elements The process logic, like Javaservice tasks and listeners, is implemented in Java

The source code for the book is divided into a number of projects The examples project contains the most example code and the other projects are used toimplement special artifacts like web applications For a full description of the sourcecode projects, please refer to appendix A

Source code for the examples in this book can be downloaded from the lisher’s website at www.manning.com/ActivitiinAction There’s also a special websitedevoted to this book at www.bpmnwithactiviti.org

pub-Author Online

Purchase of Activiti in Action includes free access to a private web forum run by

Man-ning Publications where you can make comments about the book, ask technical tions, and receive help from the author and from other users To access the forumand subscribe to it, point your web browser to www.manning.com/ActivitiinAction.This page provides information on how to get on the forum once you’re registered,what kind of help is available, and the rules of conduct on the forum

Manning’s commitment to our readers is to provide a venue where a meaningfuldialog between individual readers and between readers and the author can take place.It’s not a commitment to any specific amount of participation on the part of the

Trang 29

ABOUT THIS BOOK xxvii

author, whose contribution to the forum remains voluntary (and unpaid) We suggestyou try asking the author some challenging questions lest his interest stray!

The Author Online forum and the archives of previous discussions will be ble from the publisher’s website as long as the book is in print

accessi-About the author

Tijs Rademakers is a senior software engineer at Alfresco, where he is a member of theActiviti core development team He is an Activiti committer to the Activiti Engine and

lead developer for the Activiti Eclipse Designer Tijs is coauthor of Open Source ESBs in

Action (Manning, 2008) and has over 10 years of software engineering experience,

with a focus on open source BPM and enterprise integration frameworks He lives inValkenswaard in the Netherlands with his girlfriend and two children

Trang 30

about the cover illustration

The figure on the cover of Activiti in Action is captioned “Member of the Eastern

Goths,” also known as the Ostrogoths, an ancient Germanic tribe that in the late fifthcentury AD established a large kingdom in Italy Their descendants still live in north-ern Italy today This illustration is taken from a recent reprint of Balthasar Hacquet’s

Images and Descriptions of Southwestern and Eastern Wenda, Illyrians, and Slavs published

by the Ethnographic Museum in Split, Croatia, in 2008 Hacquet (1739–1815) was anAustrian physician and scientist who spent many years studying the botany, geology,and ethnography of many parts of the Austrian Empire, as well as the Veneto, theJulian Alps, and the western Balkans, inhabited in the past by peoples of many differ-ent tribes and nationalities Hand drawn illustrations accompany the many scientificpapers and books that Hacquet published

The rich diversity of the drawings in Hacquet’s publications speaks vividly of theuniqueness and individuality of Alpine and Balkan regions just 200 years ago This was

a time when the dress codes of two villages separated by a few miles identified peopleuniquely as belonging to one or the other, and when members of an ethnic tribe,social class, or trade could be easily distinguished by what they were wearing Dresscodes have changed since then and the diversity by region, so rich at the time, hasfaded away It is now often hard to tell the inhabitant of one continent from anotherand today’s inhabitants of the picturesque towns and villages in the Italian Alps arenot readily distinguishable from residents of other parts of Europe

We at Manning celebrate the inventiveness, the initiative, and the fun of the puter business with book covers based on costumes from two centuries ago broughtback to life by illustrations such as this one

Trang 31

com-Part 1

Introducing BPMN 2.0 and Activiti

This first part of the book provides an introduction to the Activiti frameworkand the background about the BPMN 2.0 standard In chapter 1, we’ll cover how

to set up an Activiti environment, starting with the download of the Activitiframework In chapter 2, you’ll be introduced to the main elements of the BPMN

2.0 standard in order to create process definitions Chapter 3 offers an overview

of the Activiti framework’s main components, including the Activiti Designerand Explorer Finally, in chapter 4, we’ll discuss the Activiti API with several shortcode examples

Trang 33

Introducing the Activiti framework

Every day, your actions are part of different processes For example, when youorder a book in an online bookstore, a process is executed to get the book paid for,packaged, and shipped to you When you need to renew your driver’s license, therenewal process often requires a new photograph as input Activiti provides anopen source framework to design, implement, and run processes Organizationscan use Activiti to implement their business processes without the need for expen-sive software licenses

This chapter will get you up and running with Activiti in 30 minutes First, we’lltake a look at the different components of the Activiti tool stack, including a Mod-eler, Designer, and a REST web application Then, we’ll discuss the history of theActiviti framework and compare its functionality with its main competitors, jBPM

Trang 34

4 C 1 Introducing the Activiti framework

Before we dive into code examples in section 1.4, we’ll first make sure the Activitiframework is installed correctly At the end of this chapter, you’ll have a running Activ-iti environment and a deployable example

First, let’s look at Activiti’s tool stack and its different components, including themodeling environment, the engine, and the runtime explorer application

1.1 The Activiti tool stack

The core component of the Activiti framework is the process engine The processengine provides the core capabilities to execute Business Process Model and Notation(BPMN) 2.0 processes and create new workflow tasks, among other things You canfind the BPMN specification and lots of examples at www.bpmn.org, and we’ll go intomore detail about BPMN in chapter 2 The Activiti project contains a couple of tools

in addition to the Activiti Engine Figure 1.1 shows an overview of the full Activititool stack

Let’s quickly walk through the different components listed in figure 1.1 With theActiviti Modeler, business and information analysts are capable of modeling a BPMN 2.0-compliant business process in a web browser This means that business processes can eas-ily be shared—no client software is needed before you can start modeling The Activitidesigner is an Eclipse-based plugin, which enables a developer to enhance the modeledbusiness process into a BPMN 2.0 process that can be executed on the Activiti processengine You can also run unit tests, add Java logic, and create deployment artifacts withthe Activiti Designer

In addition to the design tools, Activiti provides a number of supporting tools.With Activiti Explorer, you can get an overview of deployed processes and even diveinto the database tables underneath the Activiti process engine You can also use Activ-iti Explorer to interact with the deployed business processes For example, you can get

a list of tasks that are already assigned to you You can also start a new process instanceand look at the status of that newly created process instance in a graphical diagram

The core process engine, which can be embedded in your Java (web) application or can run standalone

Activiti REST

Web application that starts the process engine and provides a REST API

Supporting tools Activiti Explorer

Use processes and tasks and process engine management (web based)

Deploy simple processes to the engine

Deploy advanced processes to the engine

Start processes, tasks and manage engine

Figure 1.1 An overview of the Activiti tool stack: in the center, the Activiti process engine, and on the right and left sides, the accompanying modeling, design, and management tools The grayed-out components are add-ons to the core Activiti framework.

Trang 35

Getting to know Activiti

Finally, there’s the Activiti REST component, which provides a web application thatstarts the Activiti process engine when the web application is started In addition, itoffers a RESTAPI that enables you to communicate remotely with the Activiti Engine The different components are summarized in table 1.1

You can’t start developing without a clear understanding of the Activiti framework andthe architecture that’s built around a state machine Let’s take a closer look at the his-tory of the Activiti framework and discuss the Activiti Engine in more detail

1.2 Getting to know Activiti

When you start working with a new framework, it’s always good to know some projectbackground and have an understanding of the main components In this section,we’ll be looking at exactly that

1.2.1 A little bit of history

The Activiti project was started in 2010 by Tom Baeyens and Joram Barrez, the formerfounder and the core developer of jBPM (JBoss BPM), respectively The goal of theActiviti project is to build a rock-solid open source BPMN 2.0 process engine In thenext chapter, we’ll talk in detail about the BPMN 2.0 specification, but in this chapterwe’ll focus on the Activiti framework itself and getting it installed and up and runningwith simple examples

Activiti is funded by Alfresco (known for its open source document managementsystem of the same name; see www.alfresco.com and chapter 13 for more details), butActiviti acts as an independent, open source project Alfresco uses a process engine to

Table 1.1 An overview of the different components of the Activiti tool stack

Component name Short description

Activiti Engine The core component of the Activiti tool stack that performs the process engine

func-tions, such as executing BPMN 2.0 business processes and creating workflow tasks.

Activiti Modeler A web-based modeling environment for creating BPMN 2.0-compliant business

pro-cess diagrams This component is donated by Signavio, which also provides a mercial modeling tool, named the Signavio Process Editor.

com-Activiti Designer An Eclipse plugin that can be used to design BPMN 2.0-compliant business

pro-cesses with the addition of Activiti extensions, such as a Java service task and cution listeners You can also unit test processes, import BPMN 2.0 processes, and create deployment artifacts.

exe-Activiti Explorer A web application that can be used for a wide range of functions in conjunction with

the Activiti Engine You can, for example, start new process instances and get a list

of tasks assigned to you In addition, you can perform simple process management tasks, like deploying new processes and retrieving the process instance status.

Activiti REST A web application that provides a REST interface on top of the Activiti Engine In the

default installation (see section 1.1.3), the Activiti REST application is the entry point to the Activiti Engine

Trang 36

6 C 1 Introducing the Activiti framework

support features such as a review and approval process for documents, which meansthat the document has to be approved by one user or a group of users For this kind offunctionality, Activiti is integrated into the Alfresco system to provide the necessaryprocess and workflow engine capabilities

NOTE jBPM was used in the past instead of Activiti to provide this processand workflow functionality jBPM is still included in Alfresco, but it may bedeprecated at some point in time

Besides running the Activiti process engine in Alfresco, Activiti is built to run alone or embedded in any other system In this book, we’ll focus on running Activitioutside the Alfresco environment, but we’ll discuss the integration opportunitiesbetween Activiti and Alfresco in detail in chapter 13

In 2010, the Activiti project started off quickly and succeeded in producingmonthly (!) releases of the framework In December 2010, the first stable and produc-tion-ready release (5.0) was made available The Activiti developer community, includ-ing companies like SpringSource, FuseSource, and Mulesoft, has since been able todevelop new functionality on a frequent basis In this book, we’ll explore this contrib-uted functionality, such as the Spring integration (chapter 4) and the Mule andApache Camel integration (chapter 11)

But first things first What can you do with a process engine? Why should you usethe Activiti framework? Let’s discuss the core component, the Activiti Engine

1.2.2 The basics of the Activiti Engine

Activiti is a BPMN 2.0 process-engine framework that implements the BPMN 2.0 cation It’s able to deploy process definitions, start new process instances, execute usertasks, and perform other BPMN 2.0 functions, which we’ll discuss throughout this book But at its core, the Activiti Engine is a state machine A BPMN 2.0 process definitionconsists of elements like events, tasks, and gateways that are wired together viasequence flows (think of arrows) When such a process definition is deployed on theprocess engine and a new process instance is started, the BPMN 2.0 elements are exe-cuted one by one This process execution is similar to a state machine, where there’s

specifi-an active state specifi-and, based on conditions, the state execution progresses to specifi-anotherstate via transitions (think again of arrows) Let’s look at an abstract figure of a statemachine and see how it’s implemented in the Activiti Engine (figure 1.2)

In the Activiti Engine, most BPMN 2.0 elements are implemented as a state.They’re connected with leaving and arriving transitions, which are called sequenceflows in BPMN 2.0 Every state or corresponding BPMN 2.0 element can have attached

a piece of logic that will be executed when the process instance enters the state Infigure 1.2, you can also look up the interface and implementing class that are used inthe Activiti Engine As you can see, the logic interface ActivityBehavior is imple-mented by a lot of classes That’s because the logic of a BPMN 2.0 element is imple-mented there

Trang 37

Getting to know Activiti

When you see a complex BPMN 2.0 example later on in the book, remember that, inessence, it’s a rather simple state machine Now let’s look at a couple other opensource process engines that offer functionality similar to Activiti, and also considerthe differences

1.2.3 Knowing the competitors

When you’re interested in an open source process engine like Activiti, it’s always good

to know a little bit more about the competing open source frameworks Because themain developers of Activiti were previously involved with the JBoss BPM or jBPM frame-work, there’s also some controversy surrounding this discussion It’s obvious that jBPM

and Activiti share a lot of the same architectural principles, but there are also manydifferences We’ll only discuss the two main open source competitors of Activiti:

JBoss BPM or jBPM—An open source process engine that first supported the tom jPDL process language, but, because version 5.0 supports BPMN 2.0, the

cus-jBPM project has merged with the JBoss Drools project (an open source ness-rule management framework) and replaced Drools Flow as the rule flowlanguage for the Drools framework

busi-■ BonitaSoft—An open source process engine that provides support for the

BPMN 2.0 process language The main differentiators of BonitaSoft are thelarge set of supported elements and the integrated development environment.Let’s discuss the similarities and differences between Activiti and its two competitors

in a bit more detail

Transition

Interface: PvmTransition Class: TransitionImpl

Logic

Interface: ActivityBehavior Class: Lots of classes

Leaving transitions *

1 Behavior

ed In addition, they contain logic implemented with the ActivityBehavior interface.

Trang 38

8 C 1 Introducing the Activiti framework

Because jBPM 5 also implements the BPMN 2.0 specification, a lot of similar ality can be found But there are a number of differences that are important to men-tion; see table 1.2

function-It’s always difficult to compare two open source frameworks objectively, and this book

is about Activiti This book by no means presents the only perspective on the ences between the frameworks, but it identifies a number of differences that you canconsider when making a choice between them

Next up is the comparison between Activiti and BonitaSoft

ACTIVITI AND BONITASOFT

BonitaSoft is the company behind Bonita Open Solution, an open source BPM uct There are a number of differences between Activiti and BonitaSoft:

prod-Table 1.2 Main differences between Activiti and jBPM

jBPM has a base team of JBoss employees In addition, there are indi- vidual committers.

Spring support Activiti has native Spring support, which

makes it easy to use Spring beans in your processes and to use Spring for JPA and transaction management.

jBPM has no native Spring support, but you can use Spring with additional development effort.

Business rules

support

Activiti provides a basic integration with the Drools rule engine to support the BPMN 2.0 business rule task.

jBPM and Drools are integrated on a project level, so there’s native integra- tion with Drools on various levels.

Additional

tools

Activiti provides modeler (Oryx) and designer (Eclipse) tools to model new process defini- tions The main differentiator is the Activiti Explorer, which provides an easy-to-use web interface to start new processes, work with tasks and forms, and manage running pro- cesses In addition, it provides ad hoc task support and collaboration functionality.

jBPM also provides a modeler based on the Oryx project and a Eclipse designer With a web application, you can start new process instances and work with tasks The form support is limited.

Project Activiti has a strong developer and user

com-munity with a solid release schedule of two months Its main components are the Engine, Designer, Explorer, and REST application.

jBPM has a strong developer and user community The release schedule isn’t crystal clear, and some releases have been postponed a couple of times The Designer application is (at the moment

of writing) still based on Drools Flow, and the promised new Eclipse plugin keeps getting postponed.

Trang 39

Installing the Activiti framework

■ Activiti is developer-focused and provides an easy-to-use Java API to cate with the Activiti Engine BonitaSoft provides a tool-based solution whereyou can click and drag your process definition and forms

communi-■ With Activiti, you’re in control of every bit of the code you write With Soft, the code is often generated from the developer tool

Bonita-■ BonitaSoft provides a large set of connectivity options to a wide range of party products This means it’s easy to configure a task in the developer tool toconnect to SAP or query a particular database table With Activiti, the connectiv-ity options are also very broad (due to the integration with Mule and Camel),but they’re more developer focused

third-Although both frameworks focus on supporting the BPMN 2.0 specification and ing a process engine, they take different implementation angles BonitaSoft provides adevelopment tool where you can draw your processes and configure and deploy themwithout needing to write one line of code This means that you aren’t in control of theprocess solution you’re developing Activiti provides an easy-to-use Java API that willneed some coding, but, in the end, you can easily embed it into an application or run

offer-it on every platform you’d like

As you can see, Activiti is not the only open source process engine capable of ning BPMN 2.0 process models, but it’s definitely a flexible and powerful option, andone that we’ll discuss in detail in this book Now that you know the different compo-nents of Activiti, let’s get the framework installed on your development machine

run-1.3 Installing the Activiti framework

The first thing you have to do is point your web browser to the Activiti website at

www.activiti.org You’ll be guided to the latest release of Activiti via the download ton Download the latest version and unpack the distribution to a logical folder, such as

but-C:\activiti (Windows)

/usr/local/activiti (Linux or Mac OS)

This isn’t the beginning of a long and complex

installation procedure—with Activiti, there’s a

setup directory that contains an Ant build file

that installs the Activiti framework The

direc-tory structure of the distribution is shown in

figure 1.3

Before you go further with the installation

procedure, make sure that you’ve installed a

Java 5 SDK or higher, pointed the JAVA_HOME

environment variable to the Java installation

directory, and installed a current version (1.8.x

or higher) of Ant (http://ant.apache.org)

Shortcuts to the Java SDK and the Ant framework

are also provided on the Activiti download page

Figure 1.3 The directory structure of the Activiti distribution with the setup directo-

ry and the Ant build.xml file as the main parts for the installation procedure.

Trang 40

10 C 1 Introducing the Activiti framework

The last thing to confirm is that you have an internet connection available without

a proxy, because the Ant build file will download additional packages If you’re behind

a proxy, make sure you’ve configured the Ant build to use that proxy (more info can

be found at http://ant.apache.org/manual/proxy.html)

When you open a terminal or command prompt and go to the setup directoryshown in figure 1.3, you only have to run the ant command (or ant demo.start) Thiswill kick off the Activiti installation process, which will look for a build.xml file in thesetup directory The installation performs the following steps:

1 An H2 database is installed to /apps/h2, and the H2 database is started onport 9092

2 The Activiti database is created in the running H2 database

3 Apache Tomcat 6.0.x is downloaded and installed to /apps/apache-tomcat-6.0.x,where x stands for the latest version

4 Demo data, including users, groups, and business processes, are installed to theH2 database

5 The Activiti REST and Activiti Explorer WARs are copied to the webapps tory of Tomcat

direc-6 Tomcat is started, which means that the Activiti Explorer and REST applicationsare running

7 Depending on on your OS, a web browser is started by the installation script withthe Activiti Explorer URL On Windows 7, no web browser is started; in other ver-sions of Windows, the web browser is only started if you have Firefox installed.When the Ant script has finished, you have the Activiti tool stack installed and run-ning That’s not bad for about a minute of installation time The Ant build file isn’tonly handy for installing Activiti but also for doing common tasks, like stopping andstarting the H2 database (ant h2.stop, ant h2.start) and the Tomcat server (anttomcat.stop, ant tomcat.start) and for re-creating a vanilla database schema(ant internal.db.drop, ant internal.db.create) It’s worth the time to look at theAnt targets in the Ant build file

The installation of Activiti consists foremost of two web applications beingdeployed to a Tomcat server and a ready-to-use H2 database being created with exam-ple processes, groups, and users already loaded Figure 1.4 shows the installationresult in a schematic overview

Notice that we haven’t yet installed the Activiti Modeler and Designer applications.These components aren’t part of the installation script and have to be installed sepa-rately We’ll discuss how to do this in chapter 3

To verify whether the installation has succeeded, the Activiti Explorer, listed intable 1.3, should be available via your favorite web browser You can use the userkermitwith password kermit to log in To work with the Activiti REST application, youcan use a REST client, such as the REST client Firefox plugin You can read more aboutthe Activiti RESTAPI in chapter 8

Ngày đăng: 22/03/2014, 17:20

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN