OE-Workflow and OE-Cloud Integration.

This document explains how we can integrate oe-workflow and oe-cloud with a basic maker-checker example(Four-Eye process). To support maker checker process for any create, update and delete operation on any model of oe-cloud, we are providing a maker-checker mixin. It is also possible to use the workflow without using the maker-checker functionality. This documentation shows an example with maker-checker.

Installation

We are assuming that you have already tried the basic oe-cloud and oe-studio. If not please follow this link Getting started with oe-cloud.

Add oe-workflow to oe-cloud

Dependecny

Add the below line to your package.json file in the oe-cloud directory.

	{ "oe-workflow" : "^1.1.1" }
Loading oe-workflow Application

To load oe-workflow application along with oe-cloud, it is necessary to add oe-workflow as an app to server/app-list.json file. Add the following data to the mentioned file.

	{
   	  "path" : "oe-workflow",
   	  "enabled" : true
	}

Model Creation

Product Model

In this section we will create a Product model and we assume that you know how to create a model. If not please follow this link on How to Create a Model. We will provide with all the attributes of the Product model.

	{
      "name": "Product",
      "base": "BaseEntity",
      "strict": false,
      "plural": "Products",
      "idInjection": true,
      "options": {
        "validateUpsert": true
      },
      "properties": {
        "code": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "category": {
          "type": "string"
        },
        "price": {
          "type": "number"
        },
        "offeredSince": {
          "type": "date"
        },
        "active": {
          "type": "boolean"
        },
        "description": {
          "type": "string"
        }
      }
    }

Workflow Creation

Workflow Basics

oe-workflow follows BPMN(Business Process Management Notation) 2.0 to create the workflows. Workflow Modeler link will walk you through the various elements we can use to design processes. Open the workflow-modeler tab in oe-studio and try few elements in the above document. Additionally you can also visit this BPMN 2.0 Org website for the specification documents.

Workflow design Step-by-Step

Step 1 When you open the workflow modeler for the first time, there will be a circular element on the canvas. This is the start event and all workflows start with this event. If you do not find it on the canvas drag the element from the left panel.

__Step 2__ Add a User task to this start task which will act as a Checker-I in our workflow. Add the username of the checker in the right side property panel under Candidate Users field. Select the task category as Checker, because this is the Checker-I and we do not want to finalize this transaction until Checker-II also approves it.

Add GIF to add the user task, add candiadate user and select task category

Step 3 Add a decision flowobject which will decide on the status given by the Checker-I and take the path accordingly. The gateway which we are using here is Exclusive Gateway. This gateway takes only the first flow that evaluates to true. The default flow can also be suggested if needed.

Add GIF of adding gateway after checker-I and show various gateways in general

Step 4 We have to provide the various paths that might emerge from the gateway. In this case there will two paths, one is when Checker-I accepts his task we want to hand it over to Checker-II and the other path is to prepare a regret message showing that the approval has been declined using a script task. Also We have to specify the flow conditions on the sequence flows coming out of the gateway based on which the flow should be taken. It is not necessary to specify a default flow but it is a good practice.

Add GIF of adding user task and script task out of the gateway

Add GIF of adding flow conditions on the flows coming out of it and make one as default

Add GIF of configuring User task and make sure to select the task category as Checker-AutoFinalize and end events added

Step 5 This completes our workflow design and we have to save and publish this workflow. Add GIF to save and publish the workflow.

###### Workflow Attachment Under the assumption that you have created the `Product` model and workflow, now we will attach this workflow to the model on __Create__ operation. This means that whenever there is a creation of an instance in the `Product` model, the attached workflow will be triggered.

###### Triggering Workflow While designing the workflow, we assigned the Checker I task for `user1` and Checker II for `user2`. Before posting any data to the Product Model, we have to make sure that these two users are created. Refer to the guide on [how to create a User in oe-cloud](https://www.oecloud.io/guides)

Post an instance to the Product Model either through Explorer or through Designer. We will post the following data through explorer in this guide.

    {
      "code": "LPT",
      "name": "Dell XPS Laptop",
      "category": "Laptops",
      "price": 45000,
      "description": "A Dell Laptop",
      "id": "1"
    }

###### Completing Tasks

Fetch Checker I Task The workflow gets triggered when we post the model instance. After the start event the first task it will encounter is Checker I task. Querying the Task model will give the tasks assigned to Checker I who has the username of user1. Users will not be able to check the tasks that are not assigned to them. In this case user1 has to login to retrieve the Checker I task from Task model.

Complete Checker II Task Post to the Task Complete API (/{id}/complete) in the explorer with the retrieved Task Id and the data as given below for approval:

    {
        "pv" : { "__action__" : "approved" }
    }

In case of rejection by the Checker I inplace of approved use rejected.

Fetch Checker I Task In case the checker I task is rejected, the following steps are not required. The product instance posted to the Product model will be deleted as it is being rejected. In case of approval, we will fetch the Checker II task. Querying the same Task model will give the tasks assigned to Checker II in case user2 has logged in.

Complete Checker II Task Post to the Task Complete API (/{id}/complete) in the explorer with the retrieved Task Id and the data as given below for approval:

    {
        "__action__" : "approved"
    }

In case of rejection by the Checker II inplace of approved use rejected.

Fetch Product Model Instance After these approval steps, we can query the Product model to fetch the data. In case of rejection by any of the Checkers will lead to the deletion of the Product instance. In case of approval by all the Checkers, we can get the data posted by us. Get Model Instance through this link if you have posted the same data as above.