Skip to content
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

Can't add new facts in POJO rule #172

Open
holken1 opened this issue Sep 12, 2019 · 3 comments
Open

Can't add new facts in POJO rule #172

holken1 opened this issue Sep 12, 2019 · 3 comments
Labels

Comments

@holken1
Copy link

holken1 commented Sep 12, 2019

Hi.
When using POJO rules, how can I add facts in one rule that can be used by a subsequent rule in the same ruleset?

I saw in the FAQ that "If a fact is changed or added in a Rule then that change or addition is present for other Rules down the rule chain." But if I specify a @given for something that is not yet defined, it throws an error*. And it's not clear how I could create a new NameValueReferable that is then picked up and stored in the fact map.

*Error on undefined @given:

[main] ERROR com.deliveredtechnologies.rulebook.model.runner.RuleAdapter - Unable to access test.rules.myrules.CatRule when converting then to Consumer java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.deliveredtechnologies.rulebook.model.runner.RuleAdapter.lambda$getThenMethodAsConsumer$14(RuleAdapter.java:292) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.deliveredtechnologies.rulebook.model.GoldenRule.lambda$invoke$8(GoldenRule.java:174) at java.util.Optional.ifPresent(Optional.java:159) at com.deliveredtechnologies.rulebook.model.GoldenRule.invoke(GoldenRule.java:171) at com.deliveredtechnologies.rulebook.model.runner.RuleAdapter.invoke(RuleAdapter.java:180) at com.deliveredtechnologies.rulebook.model.AuditableRule.invoke(AuditableRule.java:94) at com.deliveredtechnologies.rulebook.model.rulechain.cor.RuleHandler.handleRequest(RuleHandler.java:30) at com.deliveredtechnologies.rulebook.model.rulechain.cor.CoRRuleBook.lambda$run$2(CoRRuleBook.java:46) at java.util.Optional.ifPresent(Optional.java:159) at com.deliveredtechnologies.rulebook.model.rulechain.cor.CoRRuleBook.run(CoRRuleBook.java:44) at com.deliveredtechnologies.rulebook.model.runner.AbstractRuleBookRunner.run(AbstractRuleBookRunner.java:69) at test.rules.Test.main(Test.java:19) Caused by: java.lang.NullPointerException at test.rules.myrules.CatRule.then(CatRule.java:22) ... 20 more

@holken1
Copy link
Author

holken1 commented Sep 16, 2019

Could this be a bug? I noticed that declaring a fact works but as soon as I try to get or set it, it fails. I'm attaching a very simple example that shows this behavior, and fails even though I think it should run.
non-working-example.tar.gz

@holken1 holken1 changed the title Question: Adding facts from POJO rule Can't add new facts from POJO rule Sep 16, 2019
@holken1 holken1 changed the title Can't add new facts from POJO rule Can't add new facts in POJO rule Sep 16, 2019
@Clayton7510
Copy link
Collaborator

I think you are correct. I don’t think a given for a fact not defined is propagated down the rule chain - seems like an oversight.

@Clayton7510 Clayton7510 added the bug label Feb 4, 2020
@RicardoRdzG
Copy link

RicardoRdzG commented Sep 9, 2020

even when it should be fixed you can add facts for other rules down the evaluation chain by having the facts map as a given

@Given NameValueReferableMap facts;

It should be shown in one of the examples since it is a useful feature and not everybody is using lambda style

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants