Skip to content

Read Rules from multiple Json or Yaml Files #425

@TheMohitShrivastava

Description

@TheMohitShrivastava

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions