Skip to content

Commit

Permalink
Add decision table documentation (#5891) (#6101)
Browse files Browse the repository at this point in the history
Co-authored-by: Marcel Philipiak <[email protected]>
  • Loading branch information
mk-software-pl and Diamekod0221 authored May 24, 2024
1 parent d502869 commit f97412b
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 2 deletions.
101 changes: 99 additions & 2 deletions docs/scenarios_authoring/Enrichers.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,109 @@ DatabaseLookupEnricher is a specialized look-up component; it returns all column

![alt_text](img/databaseLookupEnricher.png "databaseLookup Enricher")

### Decision Table

Some decision trees can't be easily modeled using filter/switch/split nodes or resulting tree can be huge/unreadable. In such cases user may try to use the Decision Table component.
This can be helpful in situations like enriching data using static dictionary or matching business objects to specified segments based on multiple decision parameters.

Our implementation of the decision table is more generic than the one described in [Wikipedia](https://en.wikipedia.org/wiki/Decision_table).
In our implementation, columns contain "decision parameters" and "decisions".
Nussknacker does not distinguish these two types of columns; however, if you need the functionality of a decision table you probably will include one or more columns with decisions.
To match one or more rows (as in a classic decision table) a **_match condition_** returning a boolean value has to be created.
This expression can refer to the variables used in the scenario and values in the columns - hence the name for these columns - "decision parameters".
The result will be a list of matched rows - the rows for which the **_match condition_** returned `true`.
As we do not differentiate the "decision parameter" columns and "decision" columns, the whole matched rows will be returned.

#### Configuration

- **_Decision Table_**:

A user-defined tabular data. The user has control over the number of columns and the type of data in a specific column.
The values are validated upon input and an empty cell is treated as null.
- **_Match condition_**:

A `Boolean` SpEL expression based on which one or more rows of the decision table will be selected. To create the expression you can refer to the variables used in the scenario and values in the decision table. Use `#ROW.columnName' notation to access a single cell value.

- **_Output_**:

A name of the output variable that will hold a list of matched decision table rows. The rows themselves are records, so the output variable is of type `List[Record[...]]`.

#### Usage example

We will demonstrate the use of the decision table with a simple business example. Consider a telecom that wants to send offers
based on the data of a specific customer.

Suppose that the `#input` variable contains customer data: "name", "age", "gender" and `Boolean` field "isBigSpender".

The example decision table is shown below. We use two `MinAge` and `MaxAge` columns to define the age intervals
for our customers.

![alt_text](img/decisionTableData.png "Basic decision table.")

The partial match predicates might look as below.

Age:
```
(#ROW.MinAge != null ? #input.age > #ROW.MinAge : true) &&
(#ROW.MaxAge != null ? #input.age <= #ROW.MaxAge : true)
```

Gender:
```
(#ROW.Gender != null ? #input.gender == #ROW.Gender : true)
```

IsBigSpender:
```
(#ROW.IsBigSpender != null ? #input.isBigSpender == #ROW.IsBigSpender : true)
```

The overall match expression would look like this:
```
(#ROW.MinAge != null ? #input.age > #ROW.MinAge : true) &&
(#ROW.MaxAge != null ? #input.age <= #ROW.MaxAge : true) &&
(#ROW.Gender != null ? #input.gender == #ROW.Gender : true) &&
(#ROW.IsBigSpender != null ? #input.isBigSpender == #ROW.IsBigSpender : true)
```

The decision's table output variable will contain a list of matched rows.


Assuming the `#input` is:
```json
{
"name": "Andrzej Podolski",
"age": 45,
"gender": "Male",
"isBigSpender": true
}
```

The result will be (JSON notation):
```
[
{
"MinAge": 30,
"MaxAge": 50,
"Gender": "Male",
"IsBigSpender": true,
"OfferedPlan": "Family Package"
}
]
```

If you want to get the _decision columns_ only, you need to transform the resulting list in an additional node as shown [here](Spel.md#transforming-lists).


## OpenAPI enricher

[OpenAPI](https://swagger.io) is a specification for machine-readable interface files for describing, producing, consuming, and visualizing RESTful web services. Nussknacker can read definition of an OpenAPI interface and generate a component for the interaction with the given service.
[OpenAPI](https://swagger.io) is a specification for machine-readable interface files for describing, producing,
consuming, and visualizing RESTful web services. Nussknacker can read definition of an OpenAPI interface and
generate a component for the interaction with the given service.

Once an OpenAPI component is configured in the Model it will become available in the Designer. Because Nussknacker can determine the definition of the service input parameters, the node configuration form will contain entry fields for these parameters. In the example below customer_id field is the input parameter to the openAPI service.
Once an OpenAPI component is configured in the Model it will become available in the Designer. Because Nussknacker
can determine the definition of the service input parameters, the node configuration form will contain entry fields
for these parameters. In the example below customer_id field is the input parameter to the openAPI service.

![alt_text](img/openApiEnricher.png "openAPI Enricher")

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f97412b

Please sign in to comment.