Activiti Overview

kanav bahri
4 min readJan 20, 2020

Activiti is an open-source workflow engine written in Java that can execute business processes described in BPMN 2.0. Activiti is the foundation for Alfresco’s Alfresco Process Services and Alfresco is the Activiti project’s leading sponsor.

Overview:

Activiti API is a workflow and Business Process Management system. We can define a process in it, execute it, and manipulate it in different ways using the services provided by the API. It requires JDK 7+.

Activiti development can be done with the IDE of your choice. If you would like to use the Activiti Designer then you need Eclipse Kepler or Luna.

Activiti setup

To install Activiti you’ll need a working Java runtime and Apache Tomcat installation.

To get the Activiti UI and REST web applications running just copy the WARs downloaded from the Activiti download page to the webapps folder in your Tomcat installation directory. By default the UI application runs with an in-memory database along with a default user.

userId: admin

password: test

Maven Dependencies

To use this API, we need to include the Activiti dependency:

<dependency>

<groupId>org.activiti</groupId>

<artifactId>activiti-engine</artifactId>

</dependency>

Configuration

Creating a ProcessEngine

The Activiti process engine is configured through an XML file called activiti.cfg.xml.

<beans xmlns="...">

<bean id="processEngineConfiguration" class=

"org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">

value="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000" />

<property name="jdbcDriver" value="org.postgresql.Driver />

<property name="jdbcUsername" value="root" />

<property name="jdbcPassword" value="" />

<property name="databaseSchemaUpdate" value="true" />

</bean>

</beans>

Now we can obtain the ProcessEngine using the ProcessEngines class:

ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

Activiti Process Engine API and Services

The engine API is the most common way of interacting with Activiti. From the ProcessEngine, you can obtain the various services that contain the workflow/BPM methods. ProcessEngine and the services objects are thread safe.

Services

  • RepositoryService helps us manipulate the deployment of process definitions. This service deals with the static data related to a process definition
  • RuntimeService manages the ProcessInstances (currently running processes) as well as the process variables
  • TaskService keeps track of the UserTasks. The Tasks that need to be carried out manually by a user are at the core of the Activiti API. We can create a task, claim and complete a task, manipulate the assignee of the task, etc. using this service
  • FormService is an optional service. The API can be used without it, and without sacrificing any of its features. It is used to define the start form and task form in a process.
  • IdentityService manages the Users and Groups
  • HistoryService keeps track of the history of Activiti Engine. We can also set different history levels.
  • ManagementService is related to the metadata and usually not required when creating an application.
  • DynamicBpmnService helps us to change anything in a process without redeploying it.

Working with the Activiti services

The way to interact with the Activiti engine is through the services exposed by an instance of the org.activiti.engine.ProcessEngine class. The following code snippets assume you have a working Activiti environment, i.e. you have access to a valid org.activiti.engine.ProcessEngine.

As we can see in the diagram, it is a very simple process. The employee makes a vacation request, providing the number of days and the start date of vacation. The request goes to the manager. They can approve/disapprove the request.

If approved, there is a Service task defined to send the confirmation email. If disapproved, the Employee can either select to modify and resend the request, or do nothing.

Deploying the process

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.

Starting a process instance

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.

Completing tasks

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.

To continue the process instance, we need to finish this task. For the Activiti engine, this means you need to complete the task.

Suspending and activating a process

It’s possible to suspend a process definition. When a process definition is suspended, new process instance can’t be created (an exception will be thrown). Suspending the process definition is done through the RepositoryService

Reference

https://www.activiti.org/userguide/

https://www.baeldung.com/java-activiti

--

--