From eb73fa0056ebd89ff9f01231220fe9db858c103e Mon Sep 17 00:00:00 2001 From: tarilabs Date: Mon, 9 Aug 2021 11:43:09 +0200 Subject: [PATCH] KOGITO-5643 Kogito quickstarts on Quarkus is failing --- docs/src/main/asciidoc/kogito-drl.adoc | 4 +- docs/src/main/asciidoc/kogito.adoc | 68 +++++++++++++++++++++----- 2 files changed, 57 insertions(+), 15 deletions(-) diff --git a/docs/src/main/asciidoc/kogito-drl.adoc b/docs/src/main/asciidoc/kogito-drl.adoc index a07761a094a66..e8eb082f0bd64 100644 --- a/docs/src/main/asciidoc/kogito-drl.adoc +++ b/docs/src/main/asciidoc/kogito-drl.adoc @@ -37,8 +37,8 @@ The output value returned is based uniquely on the input provided. === Business rule A business rule allows to externalise decision logic into reusable pieces that can be easily -used in declarative way. There are multiple ways of writing rules like decision tables, -decision trees, rules, etc. For this example we focus on the rule format backed by DRL +used in declarative way. There are multiple ways of writing rules like https://drools.org/learn/dmn.html[DMN models], +decision tables, decision trees, rules, etc. For this example we focus on the rule format backed by DRL (Drools Rule Language). == Solution diff --git a/docs/src/main/asciidoc/kogito.adoc b/docs/src/main/asciidoc/kogito.adoc index b36c5ddcc5d37..981d5062b8312 100644 --- a/docs/src/main/asciidoc/kogito.adoc +++ b/docs/src/main/asciidoc/kogito.adoc @@ -64,9 +64,11 @@ At the same time this is the entry point to the service that can be consumed by === Business rule A business rule allows to externalise decision logic into reusable pieces that can be easily -used in declarative way. There are multiple ways of writing rules like DMN models, decision tables, -decision trees, rules, etc. For this example we focus on the rule format backed by DRL -(Drools Rule Language). +used in declarative way. There are multiple ways of writing rules like https://drools.org/learn/dmn.html[DMN models], +decision tables, decision trees, rules, etc. + +For this example we focus on the rule format backed by DRL (Drools Rule Language), +but the same business logic may be expressed with other supported Kogito knowledge formats as well. == Solution @@ -165,24 +167,57 @@ the generated project. [source,plain] ---- -package org.acme.kogito - -import org.acme.kogito.model.Person; +package org.acme.kogito; +unit PersonUnit; -rule "Is adult" ruleflow-group "person" +import org.acme.kogito.model.Person; +rule "Is adult" when - $person: Person(age > 18) + $person: /person[age > 18] then - modify($person) { - setAdult(true) + modify($person) { + setAdult(true) }; end ---- This is really a simple rule that marks a person who is older that 18 years as an adult. +This example rule uses Rule Units, a new concept introduced in Kogito that helps users to encapsulate the set of rules and the facts against which those rules will be matched. The facts inserted will be inserted into a `DataStore`, a type-safe entry point. To make everything work, we need to define both the RuleUnit and the DataStore, by creating a new class `PersonUnit` inside `src/main/java/org/acme/kogito` directory: + +[source,java] +---- +package org.acme.kogito; + +import org.acme.kogito.model.Person; +import org.kie.kogito.rules.DataSource; +import org.kie.kogito.rules.RuleUnitData; +import org.kie.kogito.rules.SingletonStore; + +public class PersonUnit implements RuleUnitData { + + private SingletonStore person; + + public PersonUnit() { + this(DataSource.createSingleton()); + } + + public PersonUnit(SingletonStore person) { + this.person = person; + } + + public SingletonStore getPerson() { + return person; + } + + public void setPerson(SingletonStore person) { + this.person = person; + } +} +---- + Finally we create a business process that will make use of this rule and some other activities to approve a given person. Using new item wizard (File -> New -> Other -> BPMN2 Model) create `persons.bpmn` inside `src/main/resources/org/acme/kogito` folder of the generated project. @@ -208,7 +243,7 @@ To model this process yourself, just follow these steps (start event should be a * drag the Tasks -> Business Rule Task from the palette and drop it next to start event, link it with start event ** double click on the business rule task *** on tab I/O Parameters, set data input and output (map `person` process variable to input data with name `person` and same for data output) -*** on tab Business Rule Task, set rule flow group to the value defined in the drl file (`person`) +*** on tab Business Rule Task, set rule flow group to the FQCN value of the RuleUnit using the `unit:` prefix (`unit:org.acme.kogito.PersonUnit`) * drag the Gateways -> XOR gateway from the palette and drop it next to the business rule task, link it with rule task * drag the Tasks -> User Task from the palette and drop it next to the gateway, link it with gateway ** double click on the user task @@ -417,9 +452,16 @@ curl -X GET http://localhost:8080/persons \ To learn more about persistence in Kogito visit https://github.com/kiegroup/kogito-runtimes/wiki/Persistence[this page] -== Using decision tables +== Using DMN decision tables + +Kogito, like Drools, offers support of the https://drools.org/learn/dmn.html[DMN open standard] for visual and semantic execution of declarative logic. +The business rules in this example may be also expressed using DMN decision tables or other visual paradigm of DMN, instead of DRL and RuleUnits. + +For more information about DMN support in Kogito, you may refer to the companion Quarkus guide specific to xref:kogito-dmn.adoc[Kogito DMN support on Quarkus], or the Kogito documentation in the links below. + +== Using legacy decision tables -Kogito allows to define business rules as decision tables using the Microsoft Excel file formats. +Kogito allows to define DRL rules as decision tables using the Microsoft Excel file formats. To be able to use such assets in your application, an additional dependency is required: [source,xml]