04 Mar 2016
comments powered by Disqus
Drools: example of named consequences
There are already theoretical explanations on the internet about named consequences. However, I can’t say I was very lucky when looking for practical examples, this is why I decided to share mine afterward.
Example
Hereunder is a sample of code from a project. It is about permissions on documents. A person asks if he can delete a document. Giving the following instructions:
- A document is associated to a list of persons who can delete it (same for read, write, etc.), a bit like rights in Linux. A person can only delete if he is in this list. One element of the list is called an ACE (Access Control Entry).
- A person can’t delete his own documents (to avoid any conflict of interest).
- If the document has been created more than a month ago the document can’t be deleted. The permission expired.
- If the person is an admin he can delete any documents at any time.
A person called “requester” is inserted in drools as a fact with a delete permission request for a specific document. ACEs have been generated for this document and this permission.