I'm working on allowing my users to create their own ruleset for data that's coming in. All of the data below is sample mock data and not in relation to our product. Example of a rule (there can be many):
CONDITIONS: (IF)
1) title = 'some*'
2) user = 'john'
OUTCOME: (THEN)
1) e-mail me
2) deny request
so in the rule above if a request is made input?title='something'&user='john'&...
it would deny the request and e-mail the user since it matches the condition. if the request is input?title='blah'&user='john'
it would allow it to pass since it doesn't match any rules.
I found two ways of doing this but I'm not too happy with it and hoping someone else might have a better solution.
First method
- When a user creates a rule it generates a temp file where it writes that rule into a programming language of IF THEN statements
- When a new request comes in, it goes through that user's rule-list in the programming language and does the appropriate actions
Second method
- When a new request comes in, it gets written into a db
- We pull all the conditionals from the db for different rules and run a query against that one row to see if it matches the conditions. If it does, we pass along the outcomes to the script to do the rest
I'm not happy with either of these days. Any insight or help here is much appreciated.
-
1You are looking at implementing a rules engine from scratch. You will likely find it easier to use one of the existing ones.user40980– user409802016年02月26日 17:42:03 +00:00Commented Feb 26, 2016 at 17:42
-
what this has to do with c++?BЈовић– BЈовић2016年02月26日 18:11:00 +00:00Commented Feb 26, 2016 at 18:11
-
@MichaelT do you know of one that I can look at? I had a tough time searching and finding oneJason K– Jason K2016年02月26日 18:22:06 +00:00Commented Feb 26, 2016 at 18:22
-
Category:Rule engines from Wikipedia.user40980– user409802016年02月26日 19:04:00 +00:00Commented Feb 26, 2016 at 19:04