I have many rules to be evaluated against the data in our database, i am planning on using easyrules api. I dont prefer programming or hardcoding the rules within my code. It should be easy to change the rule criteria once the code is built. Pls assist me on how can i make it dynamic and readable. Easyrules api insists on having a separate class for each rule as below: I want the below code to be dynamically built based on easily modifiable rule input: I was thinking of the below but not sure which one is best: 1. DB table - a rule table with rule conditions. (I can use an update query to change the rules) 2. JSON or XML.
I am flexible on other tools too not confined to easyrules. https://github.com/j-easy/easy-rules/wiki/hello-world
/**
* Hello World rule class.
*
* @author Mahmoud Ben Hassine ([email protected])
*/
@Rule(name = "Hello World rule", description = "Say Hello to duke's friends only")
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");
}
@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;
}
I would probably suggest you go with java + groovySrcipt engine. You can provide your rules in GroovyScripts and can dynamically execute them using GroovyEngine. it just a thought.