looking to build a java dynamic rule engine using easy rules api
Solution 1
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.
Solution 2
This is an old question but by the end of 2017, Easy Rules can have dynamic rules by external files.
From their website:
name: "alcohol rule"
description: "children are not allowed to buy alcohol"
priority: 2 condition: "person.isAdult() == false"
actions: - "System.out.println(\"Shop: Sorry, you are not allowed to buy alcohol\");"
yellolion
Updated on June 08, 2022Comments
-
yellolion about 2 years
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; }