2

I want to leverage on DMN to create a calculation, but the rules for this vary per country per category, so the rules USA and category1, would be different than the rules for USA and category2, and would also be different for Canada and Category 1.

I don't want to add columns for country category and keep it all on a the same table because this will make a super big table, and since each would be maintained by a different set of users would just be simpler to keep it separate if possible.

Is there a way to model this with DMN?

I know BPMN could be use to make this decision on which table to call but was curious if DMN alone would handle this case.

thanks in advance

josesuero
  • 3,260
  • 2
  • 13
  • 19

1 Answers1

5

I know BPMN could be use to make this decision on which table to call but was curious if DMN alone would handle this case.

The most appropriate methodology guideline in your case is indeed to combine the power of BPMN to coordinate which decision service (DMN) to evaluate.

That premised, you may have two alternative options using DMN alone.

DMN-only, option 1

You could define a decision service per each of the DMN model file, each modeling the country-specificity. Then in a "supervisor" DMN model you could evaluate the appropriate decision service from all the countries imported DMN models.

Pro:

  • DMN-only
  • each DMN could indeed be maintained by a different set of users
  • reusability of the defined country-specific decision services

Cons:

  • scalability is limited by the number of options, iff having many country-specific models to import

Example:

option1

this example actually shows which decision to pick, i.e.: all variations are evaluated, and then only the desired one is selected.

But you can definitely refactor the model only to invoke just-and-only the imported decision service you want (e.g.: either of s.Standard card ds() or g.Gold card ds()).

I wanted to show this example as it's a bit broader than your use-case, but as mentioned you can have it simpler.

DMN-only, option 2

You could use the non-DMN-standard invoke() function to dynamically invoke the desired DMN model from a given DMN model, provided the invoked DMN model is resolvable by the specific platform API --i.e.: on Drools is part of the same KieContainer, on Kogito is part of the same Kogito application.

Pro:

  • DMN-only
  • each DMN could indeed be maintained by a different set of users

Cons:

  • the invoke() function is a Drools extended built-in function not part of the DMN Specification.

Example:

option2 drd

In this example, country is used to lookup the name of the model containing the decision table we want to invoke to evaluate the purchase age; then the extended built-in function is used to invoke the desired model, passing the required inputs:

option2 running

This second screenshot shows from left to right: an example of a country-specific DMN model, the "supervisor" DMN model performing the invocation, example of Scenario Test running it for a few selected countries and showing the purchase age is the one requested.

I believe this is one of the very few cases where it actually make sense to leverage platform-integration aspects (such as invoke() function) as it would be naive importing 249 models of the different ISO Countries variants..

tarilabs
  • 2,178
  • 2
  • 15
  • 23
  • 2
    wow, that's amazing, thanks a lot for taking the effort for such detailed answer, I'm giving invoke a try since I'll be using drools or decision manager should be fine. Thanks again – josesuero Aug 18 '21 at 15:10
  • 1
    @josesuero glad to help, please don't forget to mark this as Answered if that solved. Also don't hesitate to join mailing-list or chat if needed in the future https://drools.org/community/getHelp.html but rest assured we monitor `dmn`, `drools` tag on stackoverflow as well. – tarilabs Aug 18 '21 at 15:38
  • 1
    Great answer! Is there any documentation about extended built-in function? I can't even find any info about `invoke()`. – maresmar Mar 24 '22 at 15:21
  • 1
    Thanks @maresmar ! Not sure if we documented it with details inside https://www.drools.org/learn/documentation.html ... if we missed, feel free to raise a JIRA – tarilabs Mar 24 '22 at 17:35
  • 1
    Thanks @tarilabs, I didn't find it there so I made a ticket https://issues.redhat.com/browse/DROOLS-6885 – maresmar Mar 28 '22 at 09:35
  • @maresmar per https://issues.redhat.com/browse/DROOLS-6885?focusedCommentId=20319591&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-20319591 what do you think of https://kiegroup.github.io/dmn-feel-handbook for it? Hope that helps. Let us know, feedback appreciated. Thank you. – tarilabs May 24 '22 at 13:01