You are not logged in Log in Join
You are here: Home » Members » Phillip J. Eby's Zope Center » My Wikis » ZPatterns Wiki » RuleAgents

Log in
Name

Password

 
 
DynamicDataObjects » DataManagers »

RuleAgents

Rule Agents are PlugIns for DataManagers that supply "business rules" or "trigger" support. They are notified by their data manager of DataManagementEvents for the DataSkins associated with that data manager.

Unlike AttributeProviders and SheetProviders, which are notified right away of most events, RuleAgents usually receive only deferred notifications. DataManagers wait until the very last possible moment (a subtransaction or transaction commit) to inform RuleAgents of add/delete/change events. This is to avoid rules trying to fire on intermediate object states, such as when an object is added but not all of its fields are filled in yet. Thus, a Rule Agent only sees _objectAdded() and _objectChanged() events when a subtransaction or transaction commit occurs, and the object effectively has had all of the data adds/changes it's going to have.

Rule Agents are an interesting addition to the Zope development model, as they provide a declarative way of describing object behavior. Instead of extending an object's methods to detect conditions or states (and possibly missing a way that the object can get to that state), you simply declare in a Rule Agent that whenever an object is in a certain state at commit time, something is to happen.

Examples of rule agents could include such PTK matters as:

  • Member registration... upon a member _objectAdded() event, rule validates that all of member's data has been filled in, then generates a password and e-mails it to them.

    SteveA: How would a rule agent handle exceptions, such as the above validation failing?

    ../PhillipEby: However it wants to. :) If the exception is uncaught, it will cause the Zope transaction to abort safely (if that's not an oxymoron).

  • Content Review... rule notices that previously approved content has been changed, and notifies the reviewer
  • Interest profiles... rule notes addition of content and searches member interest profiles so as to provide them with e-mail notifications.

And of course, there are plenty of e-commerce and business rule applications. For example, combination discounts and shipping cost rules could apply themselves to shopping carts and orders.