-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KOGITO-590: Rules should "see" process variables #269
Conversation
} | ||
RuleUnitComponentFactoryImpl impl = (RuleUnitComponentFactoryImpl) RuleUnitComponentFactory.get(); | ||
impl.registerRuleUnitDescription(generatedRuleUnitDescription); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't love this cast, but at the same time, I did not want to expose this in the public API. Maybe we can introduce some other interface
@@ -30,6 +30,8 @@ static RuleUnitComponentFactory get() { | |||
|
|||
RuleUnitDescription createRuleUnitDescription( KiePackage pkg, Class<?> ruleUnitClass ); | |||
|
|||
RuleUnitDescription createRuleUnitDescription( KiePackage pkg, String ruleUnitSimpleName ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we should backport this, although it will be a no-op
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see DROOLS-4895
return null; | ||
} else { | ||
return ruleUnitDescription; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure this change should be backported, There is no way createRuleUnitDescription(pkg, String) != null
in the 7 series
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see DROOLS-4895
.ifPresent(m -> m.setBody(unit(unitName))); | ||
// factory.findFirst(MethodDeclaration.class, m -> m.getNameAsString().equals("unbind")) | ||
// .ifPresent(m -> m.setBody()); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is duplicated code, really. We should schedule a refactoring later KOGITO-828
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(the comment is there to show that the entire snippet is duplicated)
unitKieBaseModel.setEventProcessingMode( EventProcessingOption.STREAM ); | ||
unitKieBaseModel.addPackage(ruleUnitDescription.getPackageName()); | ||
|
||
// fixme config should go in the description as well |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these fixmes are now captured in KOGITO-827
Files.write(fpath, entry.contents()); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added this utility: when DEBUG mode is on, the files are also dumped to a temp directory
jbpm/jbpm-flow-builder/src/main/java/org/jbpm/compiler/canonical/RuleSetNodeVisitor.java
Outdated
Show resolved
Hide resolved
kogito-codegen/src/test/java/org/kie/kogito/codegen/tests/BusinessRuleUnitTest.java
Outdated
Show resolved
Hide resolved
<bpmn2:endEvent id="_B89C98A9-F577-4B07-BB72-52283EE38A77"> | ||
<bpmn2:incoming>_D8A8D35C-3BBE-461E-8C67-682A3CEE6ACD</bpmn2:incoming> | ||
</bpmn2:endEvent> | ||
<bpmn2:businessRuleTask id="_5293F325-A06A-469B-8C31-1E79EE36A3E2" drools:ruleFlowGroup="unit:ruletask.Generated" name="Rule2" implementation="http://www.jboss.org/drools/rule"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so this rule flow group value has to map to package and unit name defined in DRL or?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes it is not actually a ruleFlowGroup that's just special syntax that's interpreted as a rule unit identifier. I chose this so that it can be retrofitted for the designer without changes. However, an alternative syntax is to just use implemenation="ruletask.Generated" and language="http://.../rule-unit"
(don't remember the URI right now) but that requires a change in the designer UI
import org.kie.kogito.codegen.data.Person; | ||
|
||
rule singlePerson when | ||
p: /singlePerson[ age >= 18 ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you use standard (no oopath) syntax? I tried it with just Person(age >= 18) and it didn't work...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mswiderski
DS are named entry point so you can rewrite that OOPath expression as
p: Person( age >= 18 ) from singlePerson
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @danielezonca
rule singlePerson when | ||
p: /singlePerson[ age >= 18 ] | ||
then | ||
p.setAdult(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you also add or remove data which would result in setting or removing process variables?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can "clear" a process variable like this
singlePerson.remove(p)
if you mean declaring a new process variable or deleting... I don't think you can, but then again, you can't with processes either, as the model is now code-generated ahead of time, right? you can of course add new values to collections (e.g. collection.add(...)
). The process variable declarations become the source of truth here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I think you can also use remove(p)
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
singlePerson.remove(p)
does not seem to remove the value from process.
what I had in mind is that we should allow to set one process variable based on others that are evaluated as rules. So we have the person and string here so based on person we should be able to set the string - like if there is adult person then we should set "you can drink" as string.
similar we should be able to remove given value like if person is not adult we should set the string to null.
so it's not about adding new variables but more of changing values of defined variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh in that case, you can refer to any variable (as long as the process declares it), but it's turned into a data source so you always have to use this dot notation (variables are always wrapped in a data source of some kind). We may refine this further with syntactic sugar, though
e.g. if you have a variable string
of type String
you may (currently) write string.add("you can drink")
we could iteratively refine this by allowing "singleton" values and add syntactic sugar so that you can effectively write
string = "you can drink"
or something like that. Currently we only have "collection-like" data sources but we were already thinking about adding a "singleton" data source type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the reason why the process is not updated when you remove/add is probably because the unbind
part of the rule node is not implemented yet (the lines that were commented away), so that's why some changes are not reflected. That piece of code gets called when control is returned from the rule engine to the process engine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, made some implementation to provide support for it, sent PR to your branch evacchi#1 please have a look and see if it is of any use
SonarCloud Quality Gate failed. 0 Bugs |
It is now possible to declare RuleUnits implicitly. The DataSources (DataStores actually) are inferred from the process variables. e.g. if process variables are
the rule unit will declare:
mutation occurs in-place on the reference that is shared with the process variable.
Future work: