-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[incubator-kie-drools#5659] Update drools documentation : Bring back …
…traditional DRL syntax explanation (#5660) * [incubator-kie-drools#5659] Update drools documentation : Bring back traditional DRL syntax explanation * - Remove ruleunit and oopath from traditional syntax chapter
- Loading branch information
Showing
28 changed files
with
3,476 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
398 changes: 398 additions & 0 deletions
398
...ls-docs/src/modules/ROOT/pages/language-reference-traditional/_DSL-section.adoc
Large diffs are not rendered by default.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
...les/ROOT/pages/language-reference-traditional/_drl-declarations-access-con.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
[id='drl-declarations-access-con_{context}'] | ||
= Access to DRL declared types in application code | ||
|
||
Declared types in DRL are typically used within the DRL files while Java models are typically used when the model is shared between rules and applications. Because declared types are generated at KIE base compile time, an application cannot access them until application run time. In some cases, an application needs to access and handle facts directly from the declared types, especially when the application wraps the {RULE_ENGINE} and provides higher-level, domain-specific user interfaces for rules management. | ||
|
||
To handle declared types directly from the application code, you can use the `org.drools.definition.type.FactType` API in {PRODUCT}. Through this API, you can instantiate, read, and write fields in the declared fact types. | ||
|
||
The following example code modifies a `Person` fact type directly from an application: | ||
|
||
.Example application code to handle a declared fact type through the FactType API | ||
[source,java] | ||
---- | ||
import java.util.Date; | ||
import org.kie.api.definition.type.FactType; | ||
import org.kie.api.KieBase; | ||
import org.kie.api.runtime.KieSession; | ||
... | ||
// Get a reference to a KIE base with the declared type: | ||
KieBase kbase = ... | ||
// Get the declared fact type: | ||
FactType personType = kbase.getFactType("org.drools.examples", "Person"); | ||
// Create instances: | ||
Object bob = personType.newInstance(); | ||
// Set attribute values: | ||
personType.set(bob, "name", "Bob" ); | ||
personType.set(bob, "dateOfBirth", new Date()); | ||
personType.set(bob, "address", new Address("King's Road","London","404")); | ||
// Insert the fact into a KIE session: | ||
KieSession ksession = ... | ||
ksession.insert(bob); | ||
ksession.fireAllRules(); | ||
// Read attributes: | ||
String name = (String) personType.get(bob, "name"); | ||
Date date = (Date) personType.get(bob, "dateOfBirth"); | ||
---- | ||
|
||
The API also includes other helpful methods, such as setting all the attributes at once, reading values from a `Map` collection, or reading all attributes at once into a `Map` collection. | ||
|
||
Although the API behavior is similar to Java reflection, the API does not use reflection and relies on more performant accessors that are implemented with generated bytecode. |
15 changes: 15 additions & 0 deletions
15
...rc/modules/ROOT/pages/language-reference-traditional/_drl-declarations-con.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[id='drl-declarations-con_{context}'] | ||
= Type declarations and metadata in DRL | ||
|
||
ifdef::DROOLS,JBPM,OP[] | ||
.Type declaration | ||
image::language-reference/type_declaration.png[align="center"] | ||
|
||
.Metadata | ||
image::language-reference/meta_data.png[align="center"] | ||
endif::[] | ||
|
||
Declarations in DRL files define new fact types or metadata for fact types to be used by rules in the DRL file: | ||
|
||
* *New fact types:* The default fact type in the `java.lang` package of {PRODUCT} is `Object`, but you can declare other types in DRL files as needed. Declaring fact types in DRL files enables you to define a new fact model directly in the {RULE_ENGINE}, without creating models in a lower-level language like Java. You can also declare a new type when a domain model is already built and you want to complement this model with additional entities that are used mainly during the reasoning process. | ||
* *Metadata for fact types:* You can associate metadata in the format `@key(value)` with new or existing facts. Metadata can be any kind of data that is not represented by the fact attributes and is consistent among all instances of that fact type. The metadata can be queried at run time by the {RULE_ENGINE} and used in the reasoning process. |
23 changes: 23 additions & 0 deletions
23
...OOT/pages/language-reference-traditional/_drl-declarations-enumerative-con.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[id='drl-declarations-enumerative-con_{context}'] | ||
= Enumerative type declarations in DRL | ||
|
||
DRL supports the declaration of enumerative types in the format `declare enum <factType>`, followed by a comma-separated list of values ending with a semicolon. You can then use the enumerative list in the rules in the DRL file. | ||
|
||
For example, the following enumerative type declaration defines days of the week for an employee scheduling rule: | ||
|
||
.Example enumerative type declaration with a scheduling rule | ||
[source] | ||
---- | ||
declare enum DaysOfWeek | ||
SUN("Sunday"),MON("Monday"),TUE("Tuesday"),WED("Wednesday"),THU("Thursday"),FRI("Friday"),SAT("Saturday"); | ||
fullName : String | ||
end | ||
rule "Using a declared Enum" | ||
when | ||
$emp : Employee( dayOff == DaysOfWeek.MONDAY ) | ||
then | ||
... | ||
end | ||
---- |
23 changes: 23 additions & 0 deletions
23
...s/ROOT/pages/language-reference-traditional/_drl-declarations-extended-con.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[id='drl-declarations-extended-con_{context}'] | ||
= Extended type declarations in DRL | ||
|
||
DRL supports type declaration inheritance in the format `declare <factType1> extends <factType2>`. To extend a type declared in Java by a subtype declared in DRL, you repeat the parent type in a declaration statement without any fields. | ||
|
||
For example, the following type declarations extend a `Student` type from a top-level `Person` type, and a `LongTermStudent` type from the `Student` subtype: | ||
|
||
.Example extended type declarations | ||
[source] | ||
---- | ||
import org.people.Person | ||
declare Person end | ||
declare Student extends Person | ||
school : String | ||
end | ||
declare LongTermStudent extends Student | ||
years : int | ||
course : String | ||
end | ||
---- |
Oops, something went wrong.