droolsdmn

Rules Engine using DMN - Input Array question


I do have an unique need for my Decision Engine use case. I am using DMN and DRD via a GUI editor like RedHat Process Automation Manager. To provide an analogy, let's say I have a simple decision call "CreditApproved" and it takes an input.

Input:

{ [
{BorrowerId:12345,
BorrowerIncome:50000,
 FICO:600},
{BorrowerId:12346,
BorrowerIncome:90000,
 FICO:720}
 ]  
}
DECISION:
IF (BorrowerIncome>60000) and (FICO>700))
    ApprovalInd = "Y"
ELSE
    ApprovalInd = "N"

Expected Output:

{ [
{BorrowerId:12345,
 BorrowerIncome:50000,
 FICO:600,
 ApprovalInd: "N"
},
{BorrowerId:12346,
 BorrowerIncome:90000,
 FICO:720,
 ApprovalInd: "Y"
}
 ]  
}

Question: Given the array of borrowers in the input (this JSON struct is what I get from the calling API), how do I iterate through the decision n times (2 times in the above example) and generate an output JSON which is the same as the input JSON but append the ApprovalInd to each occurrence of the array


Solution

  • You could use a FEEL-Expression:

    for c in Input return {
        "BorrowerId": c.BorrowerId,
        "BorrwerIncome": c.BorrowerIncome,
        "FICO": c.FICO,
        "ApprovalInd": if c.BorrowerIncome > 60000 and FICO > 700 then "Y" else "N"
    }
    

    This FEEL-Expressions iterates over all entries in the Input called "Input" and returns the same value for BorrowerId, BorrowerIncome and FICO. The value for ApprovalInd is determined by the if-then Statement.