[rules-users] How to do validation of facts in a Stateful Session?

Stephen Mcgruer s0840449 at sms.ed.ac.uk
Thu Aug 12 04:08:25 EDT 2010


Hi there,

My project uses Drools to (among other things) validate new  
facts/updates to old facts, according to a set of rules. (For example,  
we might have a rule that says "No two people can be named the same  
thing".) Our method of validation and error reporting was originally  
chosen for a stateless session (before we had the requirement of doing  
checks like the above), and I feel I've had to hack it a bit much to  
get it working with stateful sessions. The current methodology is:

1. (Website) The user inserts/updates a fact.
2. (Java) If the fact is new, an object is created for it. If it is an  
update, the pre-existing object is fetched from the object repository  
(the interface to the database) and a backup copy of the object is  
taken.
3. (Java) This fact is either inserted into the KnowledgeBase (KB) or  
a pre-existing fact in the KB is updated depending.
4. (Rules) If the new/updated object fails a validation rule, it will  
be retracted and a ValidationError object will be inserted into the KB.
5. (Java) The code then searches for ValidationError objects that  
match the just inserted/updated object. If it finds any it records  
them and then retracts them from the KB.
6. (Java) If there are no errors, then that's it - a success report is  
generated and passed back to the website.
7. (Java) If there were errors, then if the user was updating a fact  
the backup of it (before the changes) is inserted back into the KB.  
The website is then passed a failure report.


It just feels very hacky to do so much manual insertion/retracting  
from the Java side of the code.

So, is there a 'correct' way to do stateful validation? And does our  
current way even work, or are there hidden problems that we've not  
spotted?

Cheers,
Stephen

-- 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.






More information about the rules-users mailing list