update example in the quick start archetype

pull/94/head
Mahmoud Ben Hassine 8 years ago
parent bb24be898f
commit 8b2a89bba9

@ -27,28 +27,17 @@ import org.jeasy.rules.annotation.Action;
import org.jeasy.rules.annotation.Condition; import org.jeasy.rules.annotation.Condition;
import org.jeasy.rules.annotation.Rule; 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 { public class HelloWorldRule {
/**
* The user input which represents the data that the rule will operate on.
*/
private String input;
@Condition @Condition
public boolean checkInput() { public boolean when() {
//The rule should be applied only if the user's response is yes (duke friend) return true;
return input.equalsIgnoreCase("yes");
} }
@Action @Action
public void sayHelloToDukeFriend() throws Exception { public void then() throws Exception {
//When rule conditions are satisfied, prints 'Hello duke's friend!' to the console System.out.println("hello world");
System.out.println("Hello duke's friend!");
}
public void setInput(String input) {
this.input = input;
} }
} }

@ -23,46 +23,25 @@
*/ */
package ${packageName}; package ${packageName};
import org.jeasy.rules.api.Facts;
import org.jeasy.rules.api.Rules;
import org.jeasy.rules.api.RulesEngine; 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 class Launcher {
public static void main(String[] args) { public static void main(String[] args) {
Scanner scanner = new Scanner(System.in); // create facts
System.out.println("Are you a friend of duke? [yes/no]:"); Facts facts = new Facts();
String input = scanner.nextLine();
/** // create rules
* Declare the rule Rules rules = new Rules();
*/ rules.register(new HelloWorldRule());
HelloWorldRule helloWorldRule = new HelloWorldRule();
/** // create a rules engine and fire rules on known facts
* Set business data to operate on RulesEngine rulesEngine = new DefaultRulesEngine();
*/ rulesEngine.fire(rules, facts);
helloWorldRule.setInput(input.trim());
/**
* Create a rules engine and register the business rule
*/
RulesEngine rulesEngine = aNewRulesEngine()
.named("Hello world rules engine")
.build();
rulesEngine.registerRule(helloWorldRule);
/**
* Fire rules
*/
rulesEngine.fireRules();
} }
} }

Loading…
Cancel
Save