Skip to content

How to get Rule with when(String) and then(Action)? #421

Description

@http600

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!");
        }

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