Defaulting properties using oeCloud Business Rules Engine

Defaulting properties is a very popular application use case using oeCloud Business Rule Engine. This is a mechanism to enrich the model instance (usually before save) with new properties based on some rules defined in a Decision Table. The enrichment of model with different properties can be sometimes based on some complex logic. With oeCloud Business Rules engine an user can express various complex scenarios using Decision Tables witten in DMN 1.1 FEEL (Friendly Enough Expression Language) syntax.

What you’ll build

  • Default Rule decision table using excel.
  • Use oe-studio Rule Manager to upload excel.
  • Use oe-studio to attach rule to application model using Model Rules
  • POST data to the application model.

What You’ll need

  • You should know js-feel.
  • You should know DMN 1.1.
  • You should have basic understanding of oeCloud Business Rules Engine.
  • You should be familiar with oe-studio.
  • You should have completed the previous guide.

Please Note

The usage of business rule engine mentioned in this guide is HIGHLY EXPERIMENTAL and may change in the future. Some of the APIs elaborated in this guides will be available for backward compatibility but the usage of which will be highly discouraged when better alternatives (work in progress) are made available. The current implementation makes use of business rules defined in excel(.xlsx) format. The future implementations will encourage users to use a Rule Designer(work in progress) to create and publish rules. The usage of excel formatted business rules will be highly discouraged in the future releases.

How to complete this guide

You can start from scratch and complete each step, or you can bypass basic setup steps if you are already familiar with it. To start from the scratch go to Getting Started

Default Rule Decision Table

Let’s consider the decision table MarvelsSuperheroes.

The above decision table can be described as, given the name of the superhero, the defaulting rule adds isLeader, abilities and group properties to the payload.

Upload Rule

This guide assumes you have a basic understanding of oe-studio.

In oe-studio, browse to Rule Manager which can be found on the bottom navigation panel.

Rule Manager

To upload rule, click on the ADD RULE button on the Rules panel. This will bring up an upload element which can be used to upload the excel document.

Rule Upload

After the rule is uploaded, it can be found in the Rules panel from which it can be downloaded or deleted.

Rule List

Create Model

Let’s create the Marvels model with the following model definition,

{
  "name": "Marvels",
  "base": "BaseEntity",
  "description": "Marvel's superhero wiki",
  "properties": {
    "name": {
        "type": "string",
        "required": true
    },
    "isLeader": {
        "type": "boolean",
        "required": true
    },
    "abilities": {
        "type": "string",
        "required": true
    },
    "group": {
        "type": "string",
        "required": true
    }
  }
}

Attach Default Rule to Model

Open Model Definition panel in oe-studio. Search and click on the model Marvels.

Marvels Model

Now click on the triple dot menu button near the close (X) button on the model element. This opens up the menu items, which includes Add Model Rule.

Add Model Rule

On click of Add Model Rule, a panel opens up which includes:

Model Rule List

  • Rules List : List of all uploaded rules.
  • Default Rules: List of all default rules.
  • Validation Rules: List of all validation rules. We will discuss this in the further guides.

As you can see the Marvels rule is available in the Rules List. You can drag it to Default Rules.

Add Default Rule

Now click on Save Rule.

Sample POST

Let’s POST some data to see if it works as desired.

We need to include only name in the POST data as the rest of the properties are added by the business rules engine.

Marvels POST

As you can see, other properties have been added by the business rules engine using the MarvelsSuperheroes decision table.

Summary

As we observed from this guide,

  • Defaulting properties are made intuitive with the use of decision tables.
  • Rules can be uploaded and attached to model using oe-studio.
  • oeCloud business rules engine can be used to enable defaulting properties in a model instance.

In the next guide, we will discuss how model validations can be performed using oeCloud business rules engine.