ACTIVITI IN ACTION PDF
Activiti in Action. EXECUTABLE BUSINESS PROCESSES IN BPMN TIJS RADE MAKE RS. MANNING. Shelter Island. This first part of the book provides an introduction to the Activiti framework and the To download their free eBook in PDF, ePub and Kindle formats, owners. of Activiti, which provide a way to implement BPMN processes with plain Java struction of a large PDF document, this may not be the desired behavior.
|Language:||English, Spanish, French|
|ePub File Size:||20.59 MB|
|PDF File Size:||17.65 MB|
|Distribution:||Free* [*Regsitration Required]|
Purchase of Activiti in Action includes free access to a private web forum run by Man struction of a large PDF document, this may not be the desired behavior. Activiti in Action is a comprehensive tutorial designed to introduce developers to the world of Before diving into the nuts and bolts of Activiti, this book presents a solid introduction to BPMN . eBook $ pdf + ePub + kindle + liveBook. Rademakers & van Liempd / Activiti in Action. 1. BPMN what's in it for developers? This chapter covers. ▫ Introducing the world of BPM. ▫ Designing.
Activiti in Action is a comprehensive tutorial designed to introduce developers to the world of business process modeling using Activiti. Before diving into the nuts and bolts of Activiti, this book presents a solid introduction to BPMN 2. Activiti streamlines the implemention of your business processes: Its XML output goes to the Activiti Engine which then creates the web forms and performs the communications that implement your process. It's as simple as that. Activiti is lightweight, integrates seamlessly with standard frameworks, and includes easy-to-use design and management tools.
Manning | Activiti in Action
Introducing the Activiti framework 1. The Activiti tool stack. Installing the Activiti framework. Implementing your first process in Activiti.
BPMN 2. Taking a closer look at BPM. Introducing BPMN 2. Introducing the Activiti tool stack 3. Working with the Activiti Modeler. Adding technical details with the Activiti Designer. Managing the Engine using the Activiti Explorer. Processes and tasks with the Activiti Explorer. Working with the Activiti process engine 4. Creating an Activiti development environment.
Implementing a BPMN 2. Introducing a real business process. Developing script and service tasks. Interacting with user tasks and Activiti forms. Handling decisions and sending email. Deploying processes to the Activiti Engine. Testing the process with Activiti Explorer. Applying advanced BPMN 2. Using BPMN 2. Working with BPMN 2. Adding a JPA extension to your process.
Using execution and task listeners. Dealing with error handling 7. Choosing between error handling options. Implementing error handling with BPMN 2.
Implementing error handling using Java logic. Deploying and configuring the Activiti Engine 8. Choosing between deployment options. Using a Spring-managed Activiti Engine. Configuring the Activiti Engine. Exploring additional Activiti modules 9. Spring annotations. Building an Activiti JEE 6 application. Deploying Activiti to an OSGi container. Implementing advanced workflow Going beyond a simple user task. Managing the user identities in an LDAP server. Implementing the BPMN 2.
Custom form types and external form rendering. Integrating services with a BPMN 2. Invoking services from a BPMN 2. Using the BPMN 2. Integrating with Apache Camel. Ruling the business rule engine Introducing business rule management. Entering the rule world of Drools. Integrating Drools with Activiti.
Creating a web-based rule editor. Document management using Alfresco Introducing Alfresco Community. Using CMIS to store and retrieve documents. Adding documents to a BPMN 2. A process has been cancelled. Dispatched before the process instance is deleted from runtime.
A user has been added to a group. The event contains the ids of the user and group involved. A user has been removed from a group. All members will be removed from a group. The event is thrown before the members are removed, so they are still accessible. The list below show an overview of what entity-events are dispatched for which entities:.
Only listeners are notified in the engine the events are dispatched from. So in case you have different engines - running against the same database - only events that originated in the engine the listener is registered for, are dispatched to that listener.
The events that occur in the other engine are not dispatched to the listeners, regardless of the fact they are running in the same JVM or not. Certain event-types related to entities expose the targeted entity. Depending on the type or event, these entities cannot be updated anymore e. If possible, use the EngineServices exposed by the event to interact in a safe way with the engine. No entity-events are dispatched related to history, as they all have a runtime-counterpart which have their events dispatched.
The engine API is the most common way of interacting with Activiti. The central starting point is the ProcessEngine , which can be created in several ways as described in the configuration section.
ProcessEngine and the services objects are thread safe. So you can keep a reference to 1 of those for a whole server. Proper creation and closing of all process engines can be done with ProcessEngines. The ProcessEngines class will scan for all activiti. For all activiti. For all activiti-context. First the Spring application context is created and then the process engine is obtained from that application context.
All services are stateless. This means that you can easily run Activiti on multiple nodes in a cluster, each going to the same database, without having to worry about which machine actually executed previous calls. Any call to any service is idempotent regardless of where it is executed.
The RepositoryService is probably the first service needed when working with the Activiti engine. This service offers operations for managing and manipulating deployments and process definitions. It is a representation of the structure and behaviour of each of the steps of a process. A deployment is the unit of packaging within the Activiti engine.
A deployment can contain multiple BPMN 2. The choice of what is included in one deployment is up to the developer. It can range from a single process BPMN 2. The RepositoryService allows to deploy such packages. Deploying a deployment means it is uploaded to the engine, where all processes are inspected and parsed before being stored in the database.
From that point on, the deployment is known to the system and any process included in the deployment can now be started. Suspend and activate deployments as a whole or specific process definitions. Suspending means no further operations can be done on them, while activation is the opposite operation.
Retrieve various resources such as files contained within the deployment or process diagrams that were auto generated by the engine. Retrieve a POJO version of the process definition which can be used to introspect the process using Java rather than xml.
While the RepositoryService is rather about static information i. It deals with starting new process instances of process definitions. As said above, a process definition defines the structure and behaviour of the different steps in a process. A process instance is one execution of such a process definition. For each process definition there typically are many instances running at the same time. The RuntimeService also is the service which is used to retrieve and store process variables.
This is data which is specific to the given process instance and can be used by various constructs in the process e. The Runtimeservice also allows to query on process instances and executions. Executions are a representation of the 'token' concept of BPMN 2. Basically an execution is a pointer pointing to where the process instance currently is.
Lastly, the RuntimeService is used whenever a process instance is waiting for an external trigger and the process needs to be continued. A process instance can have various wait states and this service contains various operations to signal the instance that the external trigger is received and the process instance can be continued. Tasks that need to be performed by actual human users of the system are core to a BPM engine such as Activiti.
Everything around tasks is grouped in the TaskService , such as. Creating new standalone tasks. These are tasks that are not related to a process instances. Manipulating to which user a task is assigned or which users are in some way involved with the task.
Claiming and completing a task. Claiming means that someone decided to be the assignee for the task, meaning that this user will complete the task. Completing means doing the work of the tasks.
Typically this is filling in a form of sorts. The IdentityService is pretty simple. For example, a task could be assigned to any user, but the engine does not verify if that user is known to the system. The FormService is an optional service. Meaning that Activiti can perfectly be used without it, without sacrificing any functionality. This service introduces the concept of a start form and a task form. A start form is a form that is shown to the user before the process instance is started, while a task form is the form that is displayed when a user wants to complete a form.
Activiti allows to define these forms in the BPMN 2. This service exposes this data in an easy way to work with. The HistoryService exposes all historical data gathered by the Activiti engine. When executing processes, a lot of data can be kept by the engine this is configurable such as process instance start times, who did which tasks, how long it took to complete the tasks, which path was followed in each process instance, etc.
This service exposes mainly query capabilities to access this data. The ManagementService is typically not needed when coding custom application using Activiti. It allows to retrieve information about the database tables and table metadata. Furthermore, it exposes query capabilities and management operations for jobs. Later on, these topics will be discussed in more detail. The DynamicBpmnService can be used to change part of the process definition without needing to redeploy it.
You can for example change the assignee definition for a user task in a process definition, or change the class name of a service task. For more detailed information on the service operations and the engine API, see the javadocs. The base exception in Activiti is the org. ActivitiException , an unchecked exception.
This exception can be thrown at all times by the API, but expected exceptions that happen in specific methods are documented in the the javadocs. For example, an extract from TaskService:. In the example above, when an id is passed for which no task exists, an exception will be thrown.
Also, since the javadoc explicitly states that taskId cannot be null, an ActivitiIllegalArgumentException will be thrown when null is passed. Even though we want to avoid a big exception hierarchy, the following subclasses were added which are thrown in specific cases. Thrown when the Activiti engine discovers a mismatch between the database schema version and the engine version.
Thrown when an optimistic locking occurs in the data store caused by concurrent access of the same data entry. Thrown when a class requested to load was not found or when an error occurred while loading it e.
Activiti User Guide
Thrown when an object that is requested or action on does not exist. Thrown when a task is already claimed, when the taskService. As described above, the way to interact with the Activiti engine is through the services exposed by an instance of the org. ProcessEngine class.
The following code snippets assume you have a working Activiti environment, i. If you simply want to try out the code below, you can download or clone the Activiti unit test template , import it in your IDE and add a testUserguideCode method to the org. MyUnitTest unit test. The end goal of this little tutorial will be to have a working business process which mimics a simplistic vacation request process at a company:. Everything that is related to static data such as process definitions are accessed through the RepositoryService.
Conceptually, every such static piece of data is content of the repository of the Activiti engine. Create a new xml file VacationRequest. Please read the BPMN 2. To make this process known to the Activiti engine, we must deploy it first. Deploying means that the engine will parse the BPMN 2. This way, when the engine reboots, it will still know all of the deployed processes:. After deploying the process definition to the Activiti engine, we can start new process instances from it.
For each process definition, there are typically many process instances. The process definition is the blueprint , while a process instance is a runtime execution of it. Everything related to the runtime state of processes can be found in the RuntimeService.
There are various way to start a new process instance.
In the following snippet, we use the key we defined in the process definition xml to start the process instance. Process variables are commonly used because they give meaning to the process instances for a certain process definition. Typically, the process variables are what make process instances differ from one another. When the process starts, the first step will be a user task.
This is a step that must be performed by a user of the system. Typically, such a user will have an inbox of tasks which lists all the tasks that need to be done by this user. Following code snippet shows how such a query might be performed:. To continue the process instance, we need to finish this task. For the Activiti engine, this means you need to complete the task. Following snippet shows how this is done:. The process instance will now continue to the next step. In this example, the next step allows the employee to complete a form that adjusts their original vacation request.
The employee can resubmit the vacation request which will cause the process to loop back to the start task. Suspending the process definition is done through the RepositoryService:. To reactivate a process definition, simply call one of the repositoryService. When suspended, the process cannot be continued e. Suspending a process instance can be done by calling the runtimeService.
Activating the process instance again is done by calling the runtimeService. We will expand these sections further in the future with additional coverage of the Activiti API. Of course, as with any open source project, the best way to learn is to inspect the code and read the Javadocs! There are two ways of querying data from the engine: The query API and native queries. You can add various conditions to your queries all of which are applied together as a logical AND and precisely one ordering.
The following code shows an example:. Sometimes you need more powerful queries, e. For these cases, we introduced native queries, which allow you to write your own SQL queries. The return type is defined by the Query object you use and the data is mapped into the correct objects, e.
Since the query will be fired at the database you have to use table and column names as they are defined in the database; this requires some knowledge about the internal data structure and it is recommended to use native queries with care. The table names can be retrieved via the API to keep the dependency as small as possible. Every process instance needs and uses data to execute the steps it exists of. In Activiti, this data is called variables , which are stored in the database.
Variables can be used in expressions for example to select the correct outgoing sequence flow in an exclusive gateway , in java service tasks when calling external services for example to provide the input or store the result of the service call , etc.
A process instance can have variables called process variables , but also executions which are specific pointers to where the process is active and user tasks can have variables. A process instance can have any number of variables. Any of the startProcessInstanceXXX methods have an optional parameters to provide the variables when the process instance is created and started.
For example, from the RuntimeService:. Note that variables can be set local for a given execution remember a process instance consists of a tree of executions.
The variable will only be visible on that execution, and not higher in the tree of executions. Variables can also be fetched again, as shown below. Note that similar methods exist on the TaskService. This means that tasks, like executions, can have local variables that are alive just for the duration of the task. Variables are often used in Java delegates , expressions , execution- or tasklisteners, scripts, etc.
The simplest methods are these:. For historical and backwards compatible reasons , when doing any of the calls above, behind the scenes actually all variables will be fetched from the database. This means that if you have 10 variables, and only get one through getVariable "myVariable" , behind the scenes the other 9 will be fetched and cached.
This is not bad, as subsequent calls will not hit the database again. For example, when your process definition has three sequential service tasks and thus one database transaction , using one call to fetch all variables in the first service task might be better then fetching the variables needed in each service task separately.
Note that this applies both for getting and setting variables. Of course, when using a lot of variables or simply when you want tight control on the database query and traffic, this is not appropriate.
Since Activiti 5. When using true for the parameter fetchAllVariables , the behaviour will be exactly as described above: However, when using false as value, a specific query will be used and no other variables will be fetched nor cached.
Only the value of the variable in question here will be cached for subsequent use. Transient variables are variables that behave like regular variables, but are not persisted. Typically, transient variables are used for advanced use cases i. Like regular variables, transient variables are put on the highest parent when set. This means that when setting a variable on an execution, the transient variable is actually stored on the process instance execution.
Like regular variables, a local variant of the method exists if the variable should be set on the specific execution or task. A transient variable can only be accessed until the next wait state in the process definition. After that, they are gone.
The wait state means here the point in the process instance where it is persisted to the data store. Note that an async activity also is a wait state in this definition!
Transient variables can only be set by the setTransientVariable name, value , but transient variables are also returned when calling getVariable name a getTransientVariable name also exists, that only checks the transient variables. The reason for this is to make the writing of expressions easy and existing logic using variables works for both types.
A transient variable shadows a persistent variable with the same name. This means that when both a persistent and transient variable is set on a process instance and the getVariable "someVariable" is used, the transient variable value will be returned. Also, these config parameters are not important for historical audit purposes, so we pass them as transient variables:. Note that the variables will be available until the user task is reached and persisted to the database.
For example, in the Additional Work user task they are not available anymore. The Process Data would get the response transient variable, parse it and store the relevant data in real process variables as we need them later. The condition on the sequence flow leaving the exclusive gateway are oblivious to whether persistent or transient variables are used in this case the status transient variable:.
Activiti uses UEL for expression-resolving. Although there are 2 types of expressions, value-expression and method-expression, Activiti abstracts this so they can both be used where an expression is needed. Value expression: By default, all process variables are available to use. Also all spring-beans if using Spring are available to use in expressions.
Some examples:. Method expression: When invoking a method without parameters, be sure to add empty parentheses after the method-name as this distinguishes the expression from a value expression. The passed parameters can be literal values or expressions that are resolved themselves. Note that these expressions support resolving primitives incl. On top of all process variables, there are a few default objects available to be used in expressions:. The DelegateExecution that holds additional information about the ongoing execution.
The DelegateTask that holds additional information about the current Task. Only works in expressions evaluated from task listeners. The id of the user that is currently authenticated. If no user is authenticated, the variable is not available. Business processes are an integral part of software projects and they should be tested in the same way normal application logic is tested: Since Activiti is an embeddable Java engine, writing unit tests for business processes is as simple as writing regular unit tests.
Activiti supports both JUnit versions 3 and 4 styles of unit testing. In the JUnit 3 style, the org. ActivitiTestCase must be extended. This will make the ProcessEngine and the services available through protected member fields. In the setup of the test, the processEngine will be initialized by default with the activiti. To specify a different configuration file, override the getConfigurationResource method. Process engines are cached statically over multiple unit tests when the configuration resource is the same.
By extending ActivitiTestCase , you can annotate test methods with org. Before the test is run, a resource file of the form testClassName. At the end of the test, the deployment will be deleted, including all related process instances, tasks, etc.
The Deployment annotation also supports setting the resource location explicitly. See the class itself for more information. To get the same functionality when using the JUnit 4 style of writing unit tests, the org. ActivitiRule Rule must be used. Through this rule, the process engine and services are available through getters.
As with the ActivitiTestCase see above , including this Rule will enable the use of the org. Deployment annotation see above for an explanation of its use and configuration and it will look for the default configuration file on the classpath.
Process engines are statically cached over multiple unit tests when using the same configuration resource. The following code snippet shows an example of using the JUnit 4 style of testing and the usage of the ActivitiRule. When using the in-memory H2 database for unit tests, the following instructions allow to easily inspect the data in the Activiti database during a debugging session. The screenshots here are taken in Eclipse, but the mechanism should be similar for other IDEs.
Suppose we have put a breakpoint somewhere in our unit test. In Eclipse this is done by double-clicking in the left border next to the code:. If we now run the unit test in debug mode right-click in test class, select Run as and then JUnit test , the test execution halts at our breakpoint, where we can now inspect the variables of our test as shown in the right upper panel.
Now select Display or execute the shortcut instead of right-clicking. Now open up a browser and go to http: You can now see the Activiti data and use it to understand how and why your unit test is executing your process in a certain way. The ProcessEngine is a thread-safe class and can easily be shared among multiple threads. In a web application, this means it is possible to create the process engine once when the container boots and shut down the engine when the container goes down.
The following code snippet shows how you can write a simple ServletContextListener to initialize and destroy process engines in a plain Servlet environment:. The contextInitialized method will delegate to ProcessEngines. That will look for activiti. If you have multiple such resource files on the classpath, make sure they all have different names. When the process engine is needed, it can be fetched using. Of course, it is also possible to use any of the variants of creating a process engine, as described in the configuration section.
The contextDestroyed method of the context-listener delegates to ProcessEngines. That will properly close all initialized process engines. The ProcessEngine can be configured as a regular Spring bean.
The starting point of the integration is the class org. That bean takes a process engine configuration and creates the process engine. This means that the creation and configuration of properties for Spring is the same as documented in the configuration section.
For Spring integration the configuration and engine beans will look like this:. Note that the processEngineConfiguration bean now uses the org. SpringProcessEngineConfiguration class. Below is the Spring configuration file that we use in this example you can find it in SpringTransactionIntegrationTest-context. The section shown below contains the dataSource, transactionManager, processEngine and the Activiti Engine services. This is done to make sure the SQL connections retrieved from the DataSource and the Spring transactions play well together.
In this case no additional wrapping will occur. First the application context is created with any of the Spring ways to do that. In this example you could use a classpath XML resource to configure our Spring application context:. Then we can get the service beans and invoke methods on them. The ProcessEngineFactoryBean will have added an extra interceptor to the services that applies Propagation. So, for example, we can use the repositoryService to deploy a process like this:. The other way around also works.
In this case, the Spring transaction will be around the userBean.
The UserBean looks like this. Remember from above in the Spring bean configuration we injected the repositoryService into the userBean. The example below exposes a single bean printer , available to use under the key "printer".
When no beans property is set, all Spring beans in the context will be available. Now the exposed beans can be used in expressions: Spring integration also has a special feature for deploying resources. In the process engine configuration, you can specify a set of resources. When the process engine is created, all those resources will be scanned and deployed.
There is filtering in place that prevents duplicate deployments. Only when the resources actually have changed, will new deployments be deployed to the Activiti DB. This makes sense in a lot of use case, where the Spring container is rebooted often e. By default, the configuration above will group all of the resources matching the filtering into a single deployment to the Activiti engine.
The duplicate filtering to prevent re-deployment of unchanged resources applies to the whole deployment. In some cases, this may not be what you want. For instance, if you deploy a set of process resources this way and only a single process definition in those resources has changed, the deployment as a whole will be considered new and all of the process definitions in that deployment will be re-deployed, resulting in new versions of each of the process definitions, even though only one was actually changed.
To be able to customize the way deployments are determined, you can specify an additional property in the SpringProcessEngineConfiguration , deploymentMode. This property defines the way deployments will be determined from the set of resources that match the filter.
There are 3 values that are supported by default for this property:. Group all resources into a single deployment and apply duplicate filtering to that deployment. Create a separate deployment for each individual resource and apply duplicate filtering to that deployment. This is the value you would use to have each process definition be deployed separately and only create a new process definition version if it has changed.
Create a separate deployment for resources that share the same parent folder and apply duplicate filtering to that deployment. This value can be used to create separate deployments for most resources, but still be able to group some by placing them in a shared folder.
In addition to using the values listed above for deploymentMode , you may require customized behavior towards determining deployments.
This method determines which deployment strategy is used for a certain value of the deploymentMode configuration. When integrating with Spring, business processes can be tested very easily using the standard Activiti testing facilities. The following example shows how a business process is tested in a typical Spring-based unit test:.
Note that for this to work, you need to define a org. ActivitiRule bean in the Spring configuration which is injected by auto-wiring in the example above. When using Hibernate 4. This is not needed for Hibernate 4. The following dependency should be added:.
Spring Boot is an application framework which, according to its website , makes it easy to create stand-alone, production-grade Spring based Applications that can you can "just run". It takes an opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss.
Most Spring Boot applications need very little Spring configuration.
Part 1 Introducing BPMN 2.0 and Activiti
For more information on Spring Boot, see http: The Spring Boot - Activiti integration is currently experimental. It has been developer together with Spring committers, but it is still early days. We welcome all to try it out and provide feedback. Spring Boot is all about convention over configuration. To get started, simply add the spring-boot-starters-basic dependency to your project. For example for Maven:. This dependency will transitively add the correct Activiti and Spring dependencies to the classpath.
You can now write the Spring Boot application:. Activiti needs a database to store its data. If you would run the code above, it would give you an informative exception message that you need to add a database driver dependency to the classpath. For now, add the H2 database dependency:. So by just adding the dependency to the classpath and using the EnableAutoConfiguration annotation a lot has happened behind the scenes:.
An in-memory datasource is created automatically since the H2 driver is on the classpath and passed to the Activiti process engine configuration. Also, any BPMN 2. Create a folder processes and add a dummy process definition named one-task-process. Also add following code lines to test if the deployment actually worked.
The CommandLineRunner is a special kind of Spring bean that is executed when the application boots:. As stated above, Spring Boot is about convention over configuration. By default, by having only H2 on the classpath, it created an in memory datasource and passed that to the Activiti process engine configuration. To change the datasource, simply override the default by providing a Datasource bean.
For example, to switch to a MySQL database:. Spring Boot makes this really easy. Add following dependency to the classpath:. Create a new class, a Spring service, and create two methods: Here, we simply delegate to the service defined above.
Both the Service and the RestController will be found by the automatic component scan ComponentScan we added to our application class. Run the application class again. This will add in the Spring configuration and beans for using JPA. By default the JPA provider will be Hibernate. Create a file application. We add the method to find a Person by username. Spring will automagically implement this based on conventions i.
The startProcess now gets an assignee username in, which is used to look up the Person, and put the Person JPA object as a process variable in the process instance. A method to create Dummy users is added. This is used in the CommandLineRunner to populate the database. And there is a lot more to the Spring Boot integration:. To deploy processes, they have to be wrapped in a business archive. A business archive is the unit of deployment to an Activiti Engine.
A business archive is equivalent to a zip file. It can contain BPMN 2. In general, a business archive contains a collection of named resources. When a business archive is deployed, it is scanned for BPMN files with a. Each of those will be parsed and may contain multiple process definitions. Java classes present in the business archive will not be added to the classpath.
All custom classes used in process definitions in the business archive for example Java service tasks or event listener implementations should be present on the Activiti Engine classpath in order to run the processes.
See the javadocs for more details. Process definitions live in the Activiti database. These process definitions can reference delegation classes when using Service Tasks or execution listeners or Spring beans from the Activiti configuration file. These classes and the Spring configuration file have to be available to all process engines that may execute the process definitions. All custom classes that are used in your process e.
When you are using the demo setup and you want to add your custom classes, you should add a jar containing your classes to the activiti-explorer or activiti-rest webapp lib. When expressions or scripts use Spring beans, those beans have to be available to the engine when executing the process definition. If you are building your own webapp and you configure your process engine in your context as described in the spring integration section , that is straightforward.
But bear in mind that you also should update the Activiti rest webapp with that context if you use it. You can do that by replacing the activiti.
Instead of making sure that all process engines have all the delegation classes on their classpath and use the right Spring configuration, you may consider including the Activiti rest webapp inside your own webapp so that there is only a single ProcessEngine. That is actually good because the executable BPMN process file will probably live in a version control system repository e. Subversion, Git or Mercurial as part of your development project.
Versions of process definitions are created during deployment. For each process definition in a business archive the following steps are performed to initialize the properties key , version , name and id:. The process definition id attribute in the XML file is used as the process definition key property.
The process definition name attribute in the XML file is used as the process definition name property. If the name attribute is not specified, then id attribute is used as the name.
The first time a process with a particular key is deployed, version 1 is assigned. For all subsequent deployments of process definitions with the same key, the version will be set 1 higher than the maximum currently deployed version.
The key property is used to distinguish process definitions. When deploying this process definition, the process definition in the database will look like this:. Suppose we now deploy an updated version of the same process e. The process definition table will now contain the following entries:. When the runtimeService. Should we create a second process, as defined below and deploy this to Activiti, a third row will be added to the table. Note how the key for the new process is different from our first process.
Even though the name is the same we should probably have changed that too , Activiti only considers the id attribute when distinguishing processes.
The new process is therefore deployed with version 1. A process diagram image can be added to a deployment. This image will be stored in the Activiti repository and is accessible through the API.
This image is also used to visualize the process in Activiti Explorer. The following naming conventions for the process diagram image apply in this specific order:. If an image resource exists in the deployment that has a name of the BPMN 2.
In case you have multiple images defined in one BPMN 2. Each diagram image will then have the process key in its file name. If no such image exists, am image resource in the deployment matching the name of the BPMN 2.
Note that this means that every process definition defined in the same BPMN 2. In case there is only one process definition in each BPMN 2. In case no image is provided in the deployment, as described in the previous section , the Activiti engine will generate a diagram image if the process definition contains the necessary diagram interchange information.
The resource can be retrieved in exactly the same way as when an image is provided in the deployment. If, for some reason, it is not necessary or wanted to generate a diagram during deployment the isCreateDiagramOnDeploy property can be set on the process engine configuration:.
Both deployments and process definitions have user defined categories. The process definition category is initialized value in attribute in the BPMN file: This introduction is written under the assumption you are using the Eclipse IDE to create and edit files. Very little of this is specific to Eclipse, however. Make sure that the file ends with.
The root element of the BPMN 2. Within this element, multiple process definitions can be defined although we advise to have only one process definition in each file, since this simplifies maintenance later in the development process. An empty process definition looks as listed below. Note that the minimal definitions element only needs the xmlns and targetNamespace declaration. The targetNamespace can be anything, and is useful for categorizing process definitions.
Optionally you can also add the online schema location of the BPMN 2. This id can then be used to start a new process instance of the process definition, through the startProcessInstanceByKey method on the RuntimeService.
This method will always take the latest deployed version of the process definition. Important to note here is that this is not the same as calling the startProcessInstanceById method.
This method expects the String id that was generated at deploy time by the Activiti engine, and can be retrieved by calling the processDefinition. The format of the generated id is key: If you get an ActivitiException stating that the generated id is too long, limit the text in the key field of the process. In this section we will cover a very simple business process that we will use to introduce some basic Activiti concepts and the Activiti API.
This tutorial assumes that you have the Activiti demo setup running , and that you are using a standalone H2 server. Edit db. The end result will be a simple Java SE program that deploys a process definition, and interacts with this process through the Activiti engine API. The use case is straightforward: In BPMCorp, a financial report needs to be written every month for the company shareholders. This is the responsibility of the accountancy department.
When the report is finished, one of the members of the upper management needs to approve the document before it is sent to all the shareholders. The business process as described above can be graphically visualized using the Activiti Designer. The graphical BPMN 2. What we see is a none Start Event circle on the left , followed by two User Tasks: The none start event tells us what the entry point to the process is.
The User Tasks declarations are the representation of the human tasks of our process. Note that the first task is assigned to the accountancy group, while the second task is assigned to the management group. See the section on user task assignment for more information on how users and groups can be assigned to user tasks.
The elements are connected with each other through sequence flows. These sequence flows have a source and target , defining the direction of the sequence flow. We have now created the process definition of our business process. From such a process definition, we can create process instances. In this case, one process instance would match with the creation and verification of a single financial report for a particular month. All the process instances share the same process definition.
To be able to create process instances from a given process definition, we must first deploy this process definition. Deploying a process definition means two things:.
The process definition will be stored in the persistent datastore that is configured for your Activiti engine. So by deploying our business process, we make sure that the engine will find the process definition after an engine reboot. The BPMN 2. More information on deployment can be found in the dedicated section on deployment. As described in that section, deployment can happen in several ways. One way is through the API as follows. Note that all interaction with the Activiti engine happens through its services.
Now we can start a new process instance using the id we defined in the process definition see process element in the XML file. Note that this id in Activiti terminology is called the key. This will create a process instance that will first go through the start event. After the start event, it follows all the outgoing sequence flows only one in this case and the first task write monthly financial report is reached. The Activiti engine will now store a task in the persistent database.
At this point, the user or group assignments attached to the task are resolved and also stored in the database. At such a wait state, the current state of the process instance is stored in the database. It remains in that state until a user decides to complete their task. At that point, the engine will continue until it reaches a new wait state or the end of the process. When the engine reboots or crashes in the meantime, the state of the process is safe and well in the database.
After the task is created, the startProcessInstanceByKey method will return since the user task activity is a wait state. In this case, the task is assigned to a group, which means that every member of the group is a candidate to perform the task. We can now throw this all together and create a simple Java program. Create a new Eclipse project and add the Activiti JARs and dependencies to its classpath these can be found in the libs folder of the Activiti distribution.
Before we can call the Activiti services, we must first construct a ProcessEngine that gives us access to the services. Here we use the 'standalone' configuration, which constructs a ProcessEngine that uses the database also used in the demo setup.
You can download the process definition XML here. This file contains the XML as shown above, but also contains the necessary BPMN diagram interchange information to visualize the process in the Activiti tools.
We can now retrieve this task through the TaskService by adding the following logic:. Note that the user we pass to this operation needs to be a member of the accountancy group, since that was declared in the process definition:. We could also use the task query API to get the same results using the name of the group. We can now add the following logic to our code:.
By default, no user is in the accountancy group. Then click Users and add the group to fozzie. As explained, the process will execute up to the first user task.
Select the Tasks page to view this new task. Note that even if the process was started by someone else, the task would still be visible as a candidate task to everyone in the accountancy group. An accountant now needs to claim the task.
By claiming the task, the specific user will become the assignee of the task and the task will disappear from every task list of the other members of the accountancy group. Claiming a task is programmatically done as follows:.
In the Activiti UI App, clicking the claim button will call the same operation. The task will now move to the personal task list of the logged on user. You also see that the assignee of the task changed to the current logged in user.
The accountant can now start working on the financial report. Once the report is finished, he can complete the task , which means that all work for that task is done. For the Activiti engine, this is an external signal that the process instance execution must be continued. The task itself is removed from the runtime data. The single outgoing transition out of the task is followed, moving the execution to the second task 'verification of the report'.
The same mechanism as described for the first task will now be used to assign the second task, with the small difference that the task will be assigned to the management group. In the demo setup, completing the task is done by clicking the complete button in the task list. The second task is now visible in the unassigned task lists. The verification task can be retrieved and claimed in exactly the same way as before.
Completing this second task will move process execution to the end event, which finishes the process instance. The process instance and all related runtime execution data are removed from the datastore. When you log into Activiti Explorer you can verify this, since no records will be found in the table where the process executions are stored. Programmatically, you can also verify that the process is ended using the historyService.
Combine all the snippets from previous sections, and you should have something like this this code takes in account that you probably will have started a few process instances through the Activiti Explorer UI.
As such, it always retrieves a list of tasks instead of one task, so it always works:. However, as you are going through the BPMN 2. This way, a manager could reject the financial report which would recreate the task for the accountant. Frameworks, and particularly open-source frameworks such as Activiti, can implement a solution that has the same and often better implemented ;- features as those of a big vendor.
Due to the BPMN 2. The downside of a standard however, is the fact that it is always the result of many discussions and compromises between different companies and often visions.
As a developer reading the BPMN 2. Since Activiti puts ease of development as a top-priority, we introduced something called the Activiti BPMN extensions.
These extensions are new constructs or ways to simplify certain constructs that are not in the BPMN 2. Although the BPMN 2. The prerequisite of such a custom extension is that there always must be a simple transformation to the standard way of doing things. When using a custom extension, this is always clearly indicated by giving the new XML element, attribute, etc.
So whether you want to use a custom extension or not, is completely up to you. Several factors will influence this decision graphical editor usage, company policy, etc.
We only provide them since we believe that some points in the standard can be done simpler or more efficient. Who knows, some day your idea might pop up in the specification!
Events are used to model something that happens during the lifetime process. Events are always visualized as a circle. In BPMN 2.
The type of trigger is defined by the inner icon or the type declaration in the XML. Catching events are visually differentiated from a throwing event by the inner icon that is not filled i. Throwing events are visually differentiated from a catching event by the inner icon that is filled with black. Event definitions define the semantics of an event.
Without an event definition, an event "does nothing special". For instance a start event without and event definition does not specify what exactly starts the process. If we add an event definition to the start event like for instance a timer event definition we declare what "type" of event starts the process in the case of a timer event definition the fact that a certain point in time is reached.
Timer events are events which are triggered by defined timer. They can be used as start event , intermediate event or boundary event. The behavior of the time event depends on the business calendar used.
- APEX INTERACTIVE REPORT PDF
- GIRAPH IN ACTION PDF
- I SPY 1 ACTIVITY BOOK
- TRANSACTIONAL ANALYSIS ERIC BERNE EBOOK
- MVC 4 IN ACTION PDF
- ACTIVE DIRECTORY 5TH EDITION PDF
- COMIC BOOK SPEECH BUBBLES
- DR COHEN DIET RECIPE BOOK
- MICHEL VAILLANT PDF
- PARA SA BROKEN HEARTED PDF
- DUG DOWN DEEP JOSHUA HARRIS PDF
- MASTERING APACHE CASSANDRA PDF