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

Read Rules from multiple Json or Yaml Files #425

Open
TheMohitShrivastava opened this issue Mar 28, 2024 · 0 comments
Open

Read Rules from multiple Json or Yaml Files #425

TheMohitShrivastava opened this issue Mar 28, 2024 · 0 comments

Comments

@TheMohitShrivastava
Copy link

TheMohitShrivastava commented Mar 28, 2024

Hi,

How can MVELRuleFactory read rules from multiple files. Since we have a large ruleset we want to split them into multiple files so it can be managed easily.

I tried something like this

    MVELRuleFactory mvelRuleFactory = new MVELRuleFactory(new JsonRuleDefinitionReader());
    File dir = new File("./batch/src/main/resources/rules");
    log.info(dir.getAbsolutePath());
    File[] files = dir.listFiles((d, f) -> f.endsWith(".json"));
    Rules rules = null;
    for (File file : files) {
      if (rules == null) {
        rules = mvelRuleFactory.createRules(new FileReader(file));
      } else {
        Rules rules1 = mvelRuleFactory.createRules(new FileReader(file));
        rules.register(rules1);
      }
    }

but this fails with the below error

Exception in thread "main" java.lang.IllegalArgumentException: Rule 'org.jeasy.rules.api.Rules' is not annotated with 'org.jeasy.rules.annotation.Rule'
	at org.jeasy.rules.core.RuleDefinitionValidator.checkRuleClass(RuleDefinitionValidator.java:57)
	at org.jeasy.rules.core.RuleDefinitionValidator.validateRuleDefinition(RuleDefinitionValidator.java:49)
	at org.jeasy.rules.core.RuleProxy.asRule(RuleProxy.java:81)
	at org.jeasy.rules.api.Rules.register(Rules.java:84)

It seems rules.register() can only accept Java Rules & not MVEL Rules. Is there a way to read rules from multiple files.

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

1 participant