How to get Rule with when(String) and then(Action) in easy-rules?

16 Views Asked by At

In a programmatic way with a fluent API:

Rule weatherRule = new RuleBuilder()
        .name("weather rule")
        .description("if it rains then take an umbrella")
        .when(facts -> facts.get("rain").equals(true))
        .then(facts -> System.out.println("It rains, take an umbrella!"))
        .build();

Or using an Expression Language:

Rule weatherRule = new MVELRule()
        .name("weather rule")
        .description("if it rains then take an umbrella")
        .when("rain == true")
        .then("System.out.println(\"It rains, take an umbrella!\");");

How to get:

...
        .when("rain == true")
        .then(facts -> System.out.println("It rains, take an umbrella!"))
...

Currently, I have to take it in:


        MVELRule weatherMvelRule = new MVELRule()
                .name("weather rule")
                .description("if it rains then take an umbrella")
                .when("rain == true");
        Facts facts = new Facts();
        facts.put("rain", true);
        if (weatherMvelRule.evaluate(facts)) {
            System.out.println("It rains, take an umbrella!");
        }
0

There are 0 best solutions below