We are trying to build a generic Alert Registration Service for consumers. Here is the problem we are trying to solve :
- An alert can have 'N' templates registered.Each template would be picked up based on a rule match
The rule is going to be something like this :
{"rule1":{"fieldName":"field1","operator":">","value":"100"}
FieldName could be something like - accountBal, status etc. Operator could be arithmetic operators like ("+","-","/","*") or logical operations like (&&, == , ||) We are planning to define a /registration service and an /execute service.
Let us take a rule say : rule1 = field1 > 100 --> choose Template 1 rule2 = field1 >=100 && field2 <150 - Choose Template 2
Basically I am envisioning it like this :
abstract class Rule
{
private String field;
private Operator symbol;
private String fieldValue
}
A Rule --> can resolve to N Templates and the system should send me the list of templates back.
I did start looking at the Interpreter pattern and the Rule pattern, but I have not found I am looking at.
Basically I need a way to configure rules (will be sent as json) from service API and stored in DB. At runTime , based on the applicationId, bunch of rules will be fired and will return List<Template>
Any help would be appreciated
I was planning to use a custom Rule Engine with StandardEvaluationContext, but an example would help me get going.