deliveredtechnologies / rulebook

100% Java, Lambda Enabled, Lightweight Rules Engine with a Simple and Intuitive DSL
http://www.deliveredtechnologies.com
Apache License 2.0
716 stars 124 forks source link

Help : How to execute CoRRuleBook rules using SpringAwareRuleBookRunner #176

Open asasisekar opened 4 years ago

asasisekar commented 4 years ago

Hi,

We have defined the rules by extending the CoRRuleBook as below and created the bean using SpringAwareRuleBookRunner. When executing the rule, results are set as null. Within the CoRRuleBook, results was set as expected but AbstractRuleBookRunner was not considering the results.

public class TestRuleBook extends CoRRuleBook<String> {
  @Override
  public void defineRules() {
    addRule(
        RuleBuilder.create()
            .withFactType(ValidationRequest.class)
            .withResultType(String.class)
            .when(InsertIdRuleBook::isInvalid)
            .then((facts, result) -> result.setValue("Invalid")))
            .build());
  }
}
@Configuration
public class ApplicationConfig {
  @Bean
  RuleBook testRuleBook() {
    return new SpringAwareRuleBookRunner(
        TestRuleBook.class, "package name");
  }
}

Is SpringAwareRuleBookRunner only supports the POJO rules? Is there a way to execute the CoRRuleBook rules using runner class?

Clayton7510 commented 4 years ago

Not with the runner class. The runner's function is to create a RuleBook from annotated pojo rules.

Clayton7510 commented 4 years ago

Did that response answer your question?