Skip to content

Commit 009e20d

Browse files
committed
[incubator-kie-drools-6268] Review "Legacy DRL conventions" section wordings
1 parent 5ae2fc5 commit 009e20d

File tree

2 files changed

+68
-38
lines changed

2 files changed

+68
-38
lines changed

drools-docs/src/modules/ROOT/pages/language-reference-traditional/_drl-functions-con.adoc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,27 @@ end
7373
====
7474
A function declared in a DRL file cannot be imported to a rule in a different package while a Java static method in a different package can be imported.
7575
====
76+
77+
// see https://stackoverflow.com/a/75788542/893991
78+
[NOTE]
79+
====
80+
A function body cannot access globals.
81+
82+
From the RHS of a rule, you can always pass a global as a function parameter when invoking the function, for exmaple:
83+
84+
[source]
85+
----
86+
global List names;
87+
88+
rule "Using a function with parameters"
89+
when
90+
// Empty
91+
then
92+
addName( names, "James" );
93+
end
94+
95+
function void addName(List names, String applicantName) {
96+
names.add(applicantName);
97+
}
98+
----
99+
====

drools-docs/src/modules/ROOT/pages/language-reference/_drl-rules.adoc

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3067,10 +3067,41 @@ In this example, the condition is intended to be empty but the word `None` is us
30673067
--
30683068
30693069
[id="con-drl-legacy_{context}"]
3070-
== Legacy DRL conventions
3070+
== Legacy DRL conventions for rule unit
30713071
30723072
[role="_abstract"]
3073-
The following Drools Rule Language (DRL) conventions are no longer applicable or optimal in {PRODUCT} but might be available for backward compatibility.
3073+
The following Drools Rule Language (DRL) conventions are no longer applicable or optimal with rule unit but might be available for backward compatibility. Note that they are still fully supported in traditional DRL.
3074+
3075+
=== Global variables
3076+
3077+
Global variables (`global`) are replaced by properties of a RuleUnitData. Properties of a RuleUnitData can be referred in DRL, so used just like global variables.
3078+
3079+
.Example properties of a RuleUnitData as global
3080+
[source,java]
3081+
----
3082+
public class HelloWorldUnit implements RuleUnitData {
3083+
3084+
private final List<String> results = new ArrayList<>();
3085+
3086+
public List<String> getResults() {
3087+
return results;
3088+
}
3089+
3090+
// DataSources...
3091+
}
3092+
----
3093+
3094+
[source]
3095+
----
3096+
unit HelloWorldUnit;
3097+
3098+
rule HelloWorld
3099+
when
3100+
/strings [ this == "Hello World" ]
3101+
then
3102+
results.add("it worked!");
3103+
end
3104+
----
30743105
30753106
=== Legacy functions in DRL
30763107
@@ -3126,34 +3157,9 @@ end
31263157
A function declared in a DRL file cannot be imported to a rule in a different package while a Java static method in a different package can be imported.
31273158
====
31283159
3129-
// see https://stackoverflow.com/a/75788542/893991
3130-
[NOTE]
3131-
====
3132-
A function body cannot access globals.
3133-
3134-
From the RHS of a rule, you can always pass a global as a function parameter when invoking the function, for exmaple:
3135-
3136-
[source]
3137-
----
3138-
global List names;
3139-
3140-
rule "Using a function with parameters"
3141-
when
3142-
// Empty
3143-
then
3144-
addName( names, "James" );
3145-
end
3146-
3147-
function void addName(List names, String applicantName) {
3148-
names.add(applicantName);
3149-
}
3150-
----
3151-
3152-
====
3153-
31543160
=== Legacy rule attributes
31553161
3156-
The following attributes were used in earlier versions of the {RULE_ENGINE} to provide grouping of rules across a rule base. These attributes are superseded by DRL rule units and are only available for backward compatibility reasons. If you need to group your rules, use DRL rule units as a clearer and simpler grouping method.
3162+
The following attributes are used in traditional DRL to provide grouping of rules across a rule base. If you need to group your rules with rule unit, rule units themselves are a clearer and simpler grouping method.
31573163
31583164
.Legacy rule attributes
31593165
[cols="30%,70%", options="header"]
@@ -3174,7 +3180,7 @@ Example: `ruleflow-group "GroupName"`
31743180
31753181
=== Legacy DRL rule condition syntax
31763182
3177-
In {PRODUCT}, the preferred syntax for DRL rule conditions is through OOPath expressions. For legacy use cases, you can write rules using traditional pattern matching. In this case, you must explicitly indicate the data source using the `from` clause, as shown in the following comparative examples:
3183+
With rule unit, the preferred syntax for DRL rule conditions is through OOPath expressions. For legacy use cases, you can write rules using traditional pattern matching. In this case, you must explicitly indicate the data source using the `from` clause, as shown in the following comparative examples:
31783184
31793185
.Example `PersonRules` DRL file using OOPath notation
31803186
[source]
@@ -3185,11 +3191,11 @@ unit PersonRules;
31853191
import org.acme.Person;
31863192
31873193
rule isAdult
3188-
when
3189-
$person: /persons[ age > 18 ]
3190-
then
3194+
when
3195+
$person: /persons[ age > 18 ]
3196+
then
31913197
modify($person) {
3192-
setAdult(true)
3198+
setAdult(true)
31933199
};
31943200
end
31953201
----
@@ -3203,11 +3209,11 @@ unit PersonRules;
32033209
import org.acme.Person;
32043210
32053211
rule isAdult
3206-
when
3207-
$person: Person(age > 18) from person
3208-
then
3212+
when
3213+
$person: Person(age > 18) from person
3214+
then
32093215
modify($person) {
3210-
setAdult(true)
3216+
setAdult(true)
32113217
};
32123218
end
32133219
----
@@ -3219,7 +3225,7 @@ Using OOPath, you can write nested paths. For example, `/persons[name == "Mark"]
32193225
32203226
=== Legacy DRL rule condition elements
32213227
3222-
The following rule condition elements (keywords) are obsolete in {PRODUCT}:
3228+
The following rule condition elements (keywords) are obsolete with rule unit:
32233229
32243230
`from`::
32253231
(Obsolete with OOPath notation)

0 commit comments

Comments
 (0)