Skip to content

Commit

Permalink
Merge pull request #19297 from tarilabs/tarilabs-20210809-KOGITO-5643
Browse files Browse the repository at this point in the history
KOGITO-5643 Kogito quickstarts on Quarkus is failing
  • Loading branch information
gsmet authored Aug 9, 2021
2 parents f41bb27 + eb73fa0 commit b8eff91
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 15 deletions.
4 changes: 2 additions & 2 deletions docs/src/main/asciidoc/kogito-drl.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
68 changes: 55 additions & 13 deletions docs/src/main/asciidoc/kogito.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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> person;
public PersonUnit() {
this(DataSource.createSingleton());
}
public PersonUnit(SingletonStore<Person> person) {
this.person = person;
}
public SingletonStore<Person> getPerson() {
return person;
}
public void setPerson(SingletonStore<Person> 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.
Expand All @@ -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
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit b8eff91

Please sign in to comment.