Search in sources :

Example 1 with MVELRule

use of org.jeasy.rules.mvel.MVELRule in project easy-rules by j-easy.

the class Launcher method main.

public static void main(String[] args) throws FileNotFoundException {
    // 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 marks the person as adult").priority(1).when("person.age > 18").then("person.setAdult(true);");
    MVELRule alcoholRule = MVELRuleFactory.createRuleFrom(new File("src/main/java/org/jeasy/rules/tutorials/shop/alcohol-rule.yml"));
    // 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) DefaultRulesEngine(org.jeasy.rules.core.DefaultRulesEngine) RulesEngine(org.jeasy.rules.api.RulesEngine) MVELRule(org.jeasy.rules.mvel.MVELRule) File(java.io.File) Rules(org.jeasy.rules.api.Rules) Facts(org.jeasy.rules.api.Facts)

Aggregations

File (java.io.File)1 Facts (org.jeasy.rules.api.Facts)1 Rules (org.jeasy.rules.api.Rules)1 RulesEngine (org.jeasy.rules.api.RulesEngine)1 DefaultRulesEngine (org.jeasy.rules.core.DefaultRulesEngine)1 MVELRule (org.jeasy.rules.mvel.MVELRule)1