Managing Customers with Data Objects
Data object models are supported in Flowable Work.
Data objects and everything that's related are not an easy topic. As such, this documentation is written using an example that introduces and describes the various models, BPMN/CMMN tasks with corresponding configurable properties and the runtime behavior. Using the example, the goal is to have a better understanding how things fit together which is hopefully more useful than documenting the different parts in isolation.
In the example that follows next, most of the sections are agnostic of whether the data object is backed by a database table or a REST API. The parts that are specific to database or REST, are marked as such. If you're reading through the example and want to focus on only one implementation, you can skip the sections marked with the other implementation.
Download the Example
The example as described below can be downloaded and imported into Flowable Design:
- Example using a database table.
- Example using a REST API.
- When following the REST example, it can be useful to run the mock REST application.
Introduction
In this tutorial, we’ll look at creating data objects of which the data is either fully managed by Flowable or the data exists somewhere else and it can be accessed via a REST API. We'll call these database-backed or REST-backed data objects from this point on.
In the database option, Flowable will use a relational database table to store the data and generate the required SQL automatically behind the scenes. This is a great choice when you want to use the benefits of data objects and the data doesn't exist yet in an external system.
In the REST option, Flowable will not store any data itself except a reference to the external service. Whenever the data is needed or changed, a REST call that is configured through a related service model is executed.
The only difference between the two is when it comes to the service model. All the other steps are exactly the same for both approaches. The sections that are specific for the database and REST implementation are clearly marked in the title. If you're interested in one flavour of implementation only, you can skip the other.
The steps we’ll go through are
-
Create the app and data object model
-
Create the service model based on the data object model (database or REST)
-
Create a Liquibase changelog for the data object model (database only)
-
Create an example case model and form models
-
Publish the app and create the database table in Flowable Control
-
Run the case instances showing the usage of the data objects in Flowable Work
App and Data Object Model
In Flowable Design, select the workspace you will be working in, then click on the Create a new app
button:
Fill in a name
and key
in the subsequent popup and click on the Create
button:
An empty app model is now created and the Flowable Design UI switches to the app model edit view. Now click the Create
button:
Once clicked, the Open or create new model
modal is shown. Give the data object model a name, set the key, and optionally
add a meaningful description for it. Once all the information is entered then click on the Create
button. This will
automatically link the data object model with our app.
Once created, the Data Object Model editor opens, and we can start defining it.
Defining the Data Object Fields
A data object consists of one or more fields. New fields can be added by clicking the Add
button.
The following form is shown:
Following properties can be set:
-
Label (required): a human-readable version of the (technical) name of the field.
-
Name (required): the (technical) name of the field. This is the name that is used for example in expressions in process or case models (e.g. in
${customer.country === 'Belgium'}
the technical name is country). -
Type (required): the type of the field. Currently supported are String/Date/Boolean/Integer/Double/Long/Json fields.
-
Default value (optional): a value for the field that is set in case when a value would not have been set.
-
Description (optional): a human-readable explanation of the purpose of this field.
Let’s add following fields to the data object:
-
Name (string): the name of the customer
-
Active (boolean): a flag indicating whether this is an active customer or not
-
Country (string): the country where the customer resides.
-
Yearly fee (double): a monetary value indicating a monetary value the customer pays every year.
This should result in something that looks like this:
The actions column of the table shows the following actions (from left to right):
-
Grip dots: moves the field up or down.
-
Edit: this will allows changing the field settings.
-
Delete: this deletes the field. A confirmation will be asked before deleting.
You might have noticed when creating fields that there is a Lookup ID
flag. Don't worry about that yet, we'll come back to that below.
Before looking into the Data source section, let's first have a quick look at the Permissions and the Advanced Settings section.
Permissions
Permissions as described here are only applicable for the database-backed data objects. When using REST, you need to pass the relevant information (such as e.g. the current user, groups, etc.) to the REST API that's being called using expressions in e.g. the body or URL.
The permissions section can be clicked open by clicking on the arrow icon next to it. Once opened, permissions can be configured:
By default, any operation is possible by any user, which is expressed by having Flowable User
in each row (any user in Flowable is part of this group).
The capabilities allow to configure which groups can execute which operation (Create, Delete, Get, Update). For example: the permissions could be configured that all users can see the customer data, but only certain groups can create or delete them.
The Object ownership
section allows to configure which groups automatically get a certain role when a data object is created, following the owner
and watcher
concept from other places in Flowable.
In this tutorial, it is okay that any user can do anything with our customer data objects. Leave everything to the default settings.
Advanced Settings
The last section of the data object model view allows to set advanced settings. When clicked open the optional advanced settings are displayed:
All these fields are (technical) metadata settings:
-
Type: A custom type for the data object.
-
Sub type: A custom sub type for the data object.
-
External Id: An external id to identify the data object.
The main use case for these is to categorize or easily query and retrieve data objects and its deployed definition via the API’s by setting a hard-coded value here.
In this tutorial, we won't need those settings, and we leave them empty.
Service Model / Data Source
In this part, we’ll create the service model needed to retrieve and manipulate the data for the customer data objects. The customer data object model defines the various fields of the data object, but it is the service model that is linked to the data object model that defines how the data is actually handled.
The service model, in the context of data objects, is also called the data source
here:
After selecting Create new data source
other fields will appear, such as the Type
field. In the Type
field, it's now possible to choose either to have database-backed or REST-backed data objects. The next sections will handle each option separately.
Service Model (Database)
If you're interested in the REST version, you can skip this part.
After selecting Database
, the text fields will reflect the minimal settings needed to create a service model for a database-backed data object:
Fill in the following details:
- Name: the name of the service model that will be created, for example
Customer data source
. - Key: a unique key for the service model, similar to all model keys in Flowable, for example
customerDataSource
. - Table name: the name of the relational database table that will hold the data object date, for example
CUSTOMERS
.
After filling in these fields, click the Generate now
button.
The following popup is now shown:
This popup indicates - correctly - that we have not set a Lookup ID
yet. Indeed, when we added the fields to the data object model
we didn't create a field where the Lookup ID
flag was ticked. Since a data object backed by a database table always needs to have
Lookup ID, we can generate one now by clicking the Add default Lookup ID
. It will add a field ID
to the data object model as the first field.
Only one field can be marked as the Lookup ID
, which is a value that uniquely identities the data object.
Behind the scenes, Flowable will store this value as a process or case instance variable and use it to
lookup the data object data when needed.
Typically, this value is automatically generated, but it can also be a value that is set manually based on a form value for example.
After having clicked the Add default Lookup ID
button, following things happen:
- A new service model is created.
- The service model is linked to the data object model.
- The data object model is automatically saved.
- The service model is added to the app model
A new tab appears for the service model. The UI automatically switches to it:
Configuring the Service Model (Database)
In the middle of the screen, the section Database details
is shown. Click on it to open it.
A few things need to be configured now:
-
Table name: this should already be populated with the value we've filled in when the service model was generated.
-
Column mappings: Every data object field needs to be mapped to a column name. In the example here, we’ve simply used the uppercased name of the field, with a
_
suffix. -
The ID field, which is the Lookup ID has the
Autogenerated
flag checked by default, which we leave that way
Auto-generated Lookup ID?
If checked (the default for a database data object model), Flowable will generate a unique identifier for each new data object. If unchecked, the modeler will be responsible for making sure each new data object gets a unique value for its lookup ID.
Technically, the lookup id value will be used for the primary key of the table of the data objects.
The Database details
should look like this now:
Liquibase Changelog Model (Database)
You might have noticed that a new Related data objects
section appeared at the bottom of the Database details
section once the column mappings were filled in.
This section allows to generate and link a Liquibase Changelog Model
or Database Schema Model
to the service model.
Liquibase is an open source, database-independent library for tracking, managing, and applying database schema changes. All database schema changes are stored in a human-readable form (XML).
Liquibase scripts are not automatically applied on publish. Flowable Control has special handling for these models, as we'll see later in this tutorial.
A name and key for this model are automatically generated:
Click the Generate now
button to generate and link a Liquibase Changelog Model.
Doing so will save the current service model and generate a new Liquibase Changelog Model based on the data object model fields and the column mappings defined earlier. A new tab with the Liquibase Changelog Model appears and the Design UI automatically switches to it:
Inspecting the generated XML, we can see it will create a table with the name we've picked and a column with the correct type for each of the data object fields. We don't need to change anything, the Liquibase Changelogs Model is good to go.
More information about all possible options of the Liquibase databaseChangelog can be read in the Liquibase documentation.