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

@ -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();
// create facts
Facts facts = new Facts();
/**
* Declare the rule
*/
HelloWorldRule helloWorldRule = new HelloWorldRule();
// create rules
Rules rules = new Rules();
rules.register(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();
rulesEngine.registerRule(helloWorldRule);
/**
* Fire rules
*/
rulesEngine.fireRules();
// create a rules engine and fire rules on known facts
RulesEngine rulesEngine = new DefaultRulesEngine();
rulesEngine.fire(rules, facts);
}
}

Loading…
Cancel
Save