Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
http600 opened this issue Feb 22, 2024 · 0 comments
Open

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

http600 opened this issue Feb 22, 2024 · 0 comments

Comments

@http600
Copy link

http600 commented Feb 22, 2024

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!");
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant