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

Migration From version 3 to Version 4 breaking the already working relavance rules #400

Open
junaidwarsivd opened this issue Nov 16, 2022 · 1 comment

Comments

@junaidwarsivd
Copy link

hi I've Followed the instruction mentioned in the migration guide but seems like the relevance rules are breaking. my question is do we need to change anything in the yaml files as well or this is just a bug in the library ? i've attached Example rule below which is working in version 3 but not in version 4

---
name: step1_danger_signs
description: danger_signs
priority: 1
condition: "!step1_contact_reason.isEmpty()"
actions:
  - "isRelevant = true"
@ikoesun
Copy link

ikoesun commented Jul 14, 2023

3.2.0升级到4.1.0有BUG,替换使用RuleBuilder生成Rule。
Demo:

// Build a rule.
Rule rule = new RuleBuilder()
                .name("rule name")
                .when(new MVELCondition("condition", new ParserContext()))// "condition" like "x == 1" or "x >= 10 && x <= 100" or custom by your business.
                .then(facts -> facts.put(key, value))// add or update fact's key-value in facts.
                .build();

// Fire rules.
DefaultRulesEngine rulesEngine = new DefaultRulesEngine();// Only create once in program runtime.

Facts facts = new Facts();
facts.put("x", value);// "x" is define by rule .when() param "condition".
rulesEngine.fire(rules, facts);
Object obj = facts.get(key);
if (obj == null) {
    // not fire.
} else {
    // fire! obj = value which be define by rule .then().
}

Because of in org.jeasy.rules.mvel.MVELAction.class:

public void execute(Facts facts) {
    try {
          // Facts.asMap() retuen a new Map,but not update facts's fact after MVEL.executeExpression(). That is why you can got a result in version 3.2.0, but null in version 4.1.0. 目前只能使用@Rule注解自定义Rule或通过RuleBuilder生成Rule解决。
        MVEL.executeExpression(this.compiledExpression, facts.asMap());
    } catch (Exception var3) {
        LOGGER.error("Unable to evaluate expression: '" + this.expression + "' on facts: " + facts, var3);
        throw var3;
    }
}

Hoping this helps.

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

No branches or pull requests

2 participants