diff --git a/easy-rules-archetype/src/main/resources/archetype-resources/src/main/java/HelloWorldRule.java b/easy-rules-archetype/src/main/resources/archetype-resources/src/main/java/HelloWorldRule.java index ef72295..ff18e70 100644 --- a/easy-rules-archetype/src/main/resources/archetype-resources/src/main/java/HelloWorldRule.java +++ b/easy-rules-archetype/src/main/resources/archetype-resources/src/main/java/HelloWorldRule.java @@ -27,28 +27,17 @@ import org.jeasy.rules.annotation.Action; import org.jeasy.rules.annotation.Condition; import org.jeasy.rules.annotation.Rule; -@Rule(name = "Hello World rule", description = "Say Hello to only duke's friends") +@Rule(name = "Hello World rule", description = "Always say hello world") public class HelloWorldRule { - /** - * The user input which represents the data that the rule will operate on. - */ - private String input; - @Condition - public boolean checkInput() { - //The rule should be applied only if the user's response is yes (duke friend) - return input.equalsIgnoreCase("yes"); + public boolean when() { + return true; } @Action - public void sayHelloToDukeFriend() throws Exception { - //When rule conditions are satisfied, prints 'Hello duke's friend!' to the console - System.out.println("Hello duke's friend!"); - } - - public void setInput(String input) { - this.input = input; + public void then() throws Exception { + System.out.println("hello world"); } } diff --git a/easy-rules-archetype/src/main/resources/archetype-resources/src/main/java/Launcher.java b/easy-rules-archetype/src/main/resources/archetype-resources/src/main/java/Launcher.java index 93620cc..0d753b0 100644 --- a/easy-rules-archetype/src/main/resources/archetype-resources/src/main/java/Launcher.java +++ b/easy-rules-archetype/src/main/resources/archetype-resources/src/main/java/Launcher.java @@ -23,46 +23,25 @@ */ package ${packageName}; +import org.jeasy.rules.api.Facts; +import org.jeasy.rules.api.Rules; import org.jeasy.rules.api.RulesEngine; +import org.jeasy.rules.core.DefaultRulesEngine; -import java.util.Scanner; - -import static org.jeasy.rules.core.RulesEngineBuilder.aNewRulesEngine; - -/** - * Launcher class of the Hello World sample. - */ public class Launcher { public static void main(String[] args) { - Scanner scanner = new Scanner(System.in); - System.out.println("Are you a friend of duke? [yes/no]:"); - String input = scanner.nextLine(); - - /** - * Declare the rule - */ - HelloWorldRule helloWorldRule = new HelloWorldRule(); - - /** - * Set business data to operate on - */ - helloWorldRule.setInput(input.trim()); - - /** - * Create a rules engine and register the business rule - */ - RulesEngine rulesEngine = aNewRulesEngine() - .named("Hello world rules engine") - .build(); + // create facts + Facts facts = new Facts(); - rulesEngine.registerRule(helloWorldRule); + // create rules + Rules rules = new Rules(); + rules.register(new HelloWorldRule()); - /** - * Fire rules - */ - rulesEngine.fireRules(); + // create a rules engine and fire rules on known facts + RulesEngine rulesEngine = new DefaultRulesEngine(); + rulesEngine.fire(rules, facts); } }