Search in sources :

Example 1 with DefaultRulesEngine

use of org.jeasy.rules.core.DefaultRulesEngine in project easy-rules by j-easy.

the class SuspiciousRequestFilter method init.

@Override
public void init(FilterConfig filterConfig) {
    rulesEngine = new DefaultRulesEngine();
    rules = new Rules();
    rules.register(new SuspiciousRequestRule());
}
Also used : DefaultRulesEngine(org.jeasy.rules.core.DefaultRulesEngine) Rules(org.jeasy.rules.api.Rules)

Example 2 with DefaultRulesEngine

use of org.jeasy.rules.core.DefaultRulesEngine in project easy-rules by j-easy.

the class Launcher method main.

public static void main(String[] args) throws Exception {
    // create a person instance (fact)
    Person tom = new Person("Tom", 14);
    Facts facts = new Facts();
    facts.put("person", tom);
    // create rules
    MVELRule ageRule = new MVELRule().name("age rule").description("Check if person's age is > 18 and mark the person as adult").priority(1).when("person.age > 18").then("person.setAdult(true);");
    MVELRuleFactory ruleFactory = new MVELRuleFactory(new YamlRuleDefinitionReader());
    String fileName = args.length != 0 ? args[0] : "easy-rules-tutorials/src/main/java/org/jeasy/rules/tutorials/shop/alcohol-rule.yml";
    Rule alcoholRule = ruleFactory.createRule(new FileReader(fileName));
    // create a rule set
    Rules rules = new Rules();
    rules.register(ageRule);
    rules.register(alcoholRule);
    // create a default rules engine and fire rules on known facts
    RulesEngine rulesEngine = new DefaultRulesEngine();
    System.out.println("Tom: Hi! can I have some Vodka please?");
    rulesEngine.fire(rules, facts);
}
Also used : DefaultRulesEngine(org.jeasy.rules.core.DefaultRulesEngine) MVELRuleFactory(org.jeasy.rules.mvel.MVELRuleFactory) DefaultRulesEngine(org.jeasy.rules.core.DefaultRulesEngine) RulesEngine(org.jeasy.rules.api.RulesEngine) MVELRule(org.jeasy.rules.mvel.MVELRule) FileReader(java.io.FileReader) Rule(org.jeasy.rules.api.Rule) MVELRule(org.jeasy.rules.mvel.MVELRule) YamlRuleDefinitionReader(org.jeasy.rules.support.reader.YamlRuleDefinitionReader) Rules(org.jeasy.rules.api.Rules) Facts(org.jeasy.rules.api.Facts)

Example 3 with DefaultRulesEngine

use of org.jeasy.rules.core.DefaultRulesEngine in project tutorials by eugenp.

the class Launcher method main.

public static void main(String... args) {
    // create facts
    Facts facts = new Facts();
    // create rules
    Rules rules = new Rules();
    rules.register(new HelloWorldRule());
    // create a rules engine and fire rules on known facts
    RulesEngine rulesEngine = new DefaultRulesEngine();
    rulesEngine.fire(rules, facts);
}
Also used : DefaultRulesEngine(org.jeasy.rules.core.DefaultRulesEngine) DefaultRulesEngine(org.jeasy.rules.core.DefaultRulesEngine) RulesEngine(org.jeasy.rules.api.RulesEngine) Rules(org.jeasy.rules.api.Rules) Facts(org.jeasy.rules.api.Facts)

Example 4 with DefaultRulesEngine

use of org.jeasy.rules.core.DefaultRulesEngine in project easy-rules by j-easy.

the class Launcher method main.

public static void main(String[] args) {
    // define facts
    Facts facts = new Facts();
    facts.put("rain", true);
    // define rules
    WeatherRule weatherRule = new WeatherRule();
    Rules rules = new Rules();
    rules.register(weatherRule);
    // fire rules on known facts
    RulesEngine rulesEngine = new DefaultRulesEngine();
    rulesEngine.fire(rules, facts);
}
Also used : DefaultRulesEngine(org.jeasy.rules.core.DefaultRulesEngine) DefaultRulesEngine(org.jeasy.rules.core.DefaultRulesEngine) RulesEngine(org.jeasy.rules.api.RulesEngine) Rules(org.jeasy.rules.api.Rules) Facts(org.jeasy.rules.api.Facts)

Example 5 with DefaultRulesEngine

use of org.jeasy.rules.core.DefaultRulesEngine in project easy-rules by j-easy.

the class FizzBuzzWithEasyRules method main.

public static void main(String[] args) {
    // create rules engine
    RulesEngineParameters parameters = new RulesEngineParameters().skipOnFirstAppliedRule(true);
    RulesEngine fizzBuzzEngine = new DefaultRulesEngine(parameters);
    // create rules
    Rules rules = new Rules();
    rules.register(new FizzRule());
    rules.register(new BuzzRule());
    rules.register(new FizzBuzzRule(new FizzRule(), new BuzzRule()));
    rules.register(new NonFizzBuzzRule());
    // fire rules
    Facts facts = new Facts();
    for (int i = 1; i <= 100; i++) {
        facts.put("number", i);
        fizzBuzzEngine.fire(rules, facts);
        System.out.println();
    }
}
Also used : DefaultRulesEngine(org.jeasy.rules.core.DefaultRulesEngine) DefaultRulesEngine(org.jeasy.rules.core.DefaultRulesEngine) RulesEngine(org.jeasy.rules.api.RulesEngine) RulesEngineParameters(org.jeasy.rules.api.RulesEngineParameters) Rules(org.jeasy.rules.api.Rules) Facts(org.jeasy.rules.api.Facts)

Aggregations

Rules (org.jeasy.rules.api.Rules)6 DefaultRulesEngine (org.jeasy.rules.core.DefaultRulesEngine)6 Facts (org.jeasy.rules.api.Facts)5 RulesEngine (org.jeasy.rules.api.RulesEngine)5 FileReader (java.io.FileReader)1 Rule (org.jeasy.rules.api.Rule)1 RulesEngineParameters (org.jeasy.rules.api.RulesEngineParameters)1 MVELRule (org.jeasy.rules.mvel.MVELRule)1 MVELRuleFactory (org.jeasy.rules.mvel.MVELRuleFactory)1 YamlRuleDefinitionReader (org.jeasy.rules.support.reader.YamlRuleDefinitionReader)1