list contains for structure data type in DMN decision table

2.4k Views Asked by At

I am planning to use Drools for executing the DMN models. However I am having trouble to write a condition in DMN Decision table where the input is an array of objects with structure data type and condition is to check if the array contains an object with specific fields. For ex: Input to decision table is as below:

[
  {
    "name": "abc",
    "lastname": "pqr"
  },
  {
    "name": "xyz",
    "lastname": "lmn"
  },
  {
    "name": "pqr",
    "lastname": "jkl"
  }
]

Expected output: True if the above list contains an element that match {"name": "abc", "lastname": "pqr"} both on the same element in the list.

I see that FEEL has support for list contains, but I could not find a syntax where objects in array are not of primitive types like number,string etc but structures. So, I need help on writing this condition in Decision table.

Thanks!


Edited description:

I am trying to achieve the following using the decision tableenter image description here wherein details is list of info structure. Unfortunately as you see I am not getting the desired output wherein my input list contains the specific element I am looking for.

Input: details = [{"name": "hello", "lastname": "world"}]

Expected Output = "Hello world" based on condition match in row 1 of the decision table.

Actual Output = null

NOTE: Also in row no 2 of the decision table, I only check for condition wherein I am only interested in the checking for the name field.

Content for the DMN file can be found over here

2

There are 2 best solutions below

1
On

In this question is not clear the overall need and requirements for the Decision Table.

For what pertaining the part of the question about:

True if the above list contains an element that match {"name": "abc", "lastname": "pqr"} ... I see that FEEL has support for list contains, but I could not find a syntax where objects in array are not of primitive types like number,string etc but structures.

This can be indeed achieved with the list contains() function, described here.

Example expression

list contains(my list, {"name": "abc", "lastname": "pqr"})

where my list is the verbatim FEEL list from the original question statement.

Example run:

enter image description here

giving the expected output, true.

Naturally 2 context (complex structures) are the same if all their properties and fields are equivalent.

0
On

In DMN, there are multiple ways to achieve the same result.

If I understand the real goal of your use case, I want to suggest a better approach, much easier to maintain from a design point of view.

First of all, you have a list of users as input so those are the data types:

Data types

Then, you have to structure a bit your decision:

DG

The decision node at least one user match will go trough the user list and will check if there is at least one user that matches the conditions inside the matching BKM.

at least one user match can implemented with the following FEEL expression:

some user in users satisfies matching(user)

The great benefit of this approach is that you can reason on specific element of your list inside the matching BKM, which makes the matching decision table extremely straightforward:

decisin table