The Workflow Common Library
This standalone library was created to provide interfaces, service implementations, REST services, and DTOs for common workflow-related application functionality. This library utilizes Activiti as the workflow engine. This library provides wrappers around the Activiti API for common workflow operations, such as:
- Configuring your Process Engine
- Deploying a Process Definition
- Creating and starting a Process Instance
- Claiming and completing a Task
Interfaces
The library provides interfaces for managing objects, persisting objects, caching objects in Atoti Server, and managing processes and tasks. The library provides default implementations, but here we will talk about the interfaces that are used to abstract the common operations that can be performed on these objects. This is because each Atoti Server using this library is expected to define its own workflow definition BPMN files that will be responsible for the logic passed to the workflow.
Managing Objects
There are different types of objects that can be managed within the workflow engine. We use interfaces to abstract the common operations that can be performed on these objects.
The IKeyedObject
interface is the parent interface for managing objects in the workflow engine. It provides methods for getting and setting the unique identifier (the key
) of the object within the workflow engine.
The IVersionedObject
interface - which extends IKeyedObject
- adds methods for getting and setting the live
time period of the object within the workflow engine.
The following interfaces extend IVersionedObject
:
IProcessInstance
: Represents a process instance in the workflow engine and adds methods required by the workflow engine to manage the process instance.IBitemporalObject
: Represents an object in the workflow engine that is both versioned and has avalid
time period.
The IProcessDefinition
interface represents a process definition in the workflow engine. It extends IBitemporalObject
and provides methods for getting and
setting the fields required by the workflow engine.
Persisting Objects
The objects that we manage in the workflow engine are persisted in a database. We use interfaces to abstract the common CRUD operations that can be performed on these objects into JPA services, namely:
- getting objects from the JPA repository
- getting objects from the JPA repository by key
- validating the creation of an object in the JPA repository
- creating an object in the JPA repository
- validating the update of an object in the JPA repository
- updating an object in the JPA repository
- validating the creation or update of an object in the JPA repository
- saving an object (create or update) in the JPA repository
- validate the deletion of an object in the JPA repository
- deleting an object in the JPA repository
The interfaces are as follows and are applied to their correspondingly named objects:
IKeyedObjectService
IVersionedObjectService
IProcessInstanceService
IBitemporalObjectService
IProcessDefinitionService
Caching objects in Atoti Server
To keep your Atoti Server application datastores up-to-date with your workflow objects, we have implemented a caching service that is invoked when there are changes made to the workflow. The interfaces for the caches provide methods for the following operations:
- updating objects in the workflow
- updating statuses in the workflow
- saving process instances
- saving tasks
- saving objects
- removing objects from the workflow
The interfaces are as follows and applied to their correspondingly named objects:
IKeyedObjectWorkflowCacheService
IVersionedObjectWorkflowCacheService
IProcessInstanceWorkflowCacheService
IBitemporalObjectWorkflowCacheService
IProcessDefinitionWorkflowCacheService
Managing process and tasks
The above interfaces can be thought of as accessories to the workflow in the context of an Atoti Server application. The true interaction with the workflow engine takes place in the workflow services. The interfaces for these services provide methods for the following operations:
- getting a process instance by key
- getting all process instances
- getting a managed object from a process instance
- getting the history identifiers of a process instance by key
- getting the history of a process instance by key
- starting a process
- claiming and completing a task
- sending a signal event to trigger a state transition
- getting the current state of the process instance
The interfaces are as follows and applied to their correspondingly named objects:
IKeyedObjectWorkflowService
IVersionedObjectWorkflowService
IBitemporalObjectWorkflowService
Adding workflow core support to an application server
Importing the library
To use the Atoti Workflow Common Library library, import it into the Maven POM file:
<dependency>
<groupId>com.activeviam.apps</groupId>
<artifactId>adjustments-services</artifactId>
<version>2.4.0</version>
</dependency>
Adding services to the application configuration
Spring configuration
You can import the provided service implementations directly within the application configuration:
@Import(value = {
DefaultWorkflowConfig.class, // configuration for the workflow engine
DefaultAuditConfig.class, // configuration for the audit trail
})
Once imported, the services auto-wire any relevant beans provided in the application and expose the REST service endpoints.