To implement business rules as Java™ code, write the class that implements the com.dwl.base.externalrule.Rule interface. Event Manager provides an abstract Java class that already implements the rule interface; therefore, when writing Java business rules for Event Manager, simply extend com.dwl.commoncomponents.eventmanager.test.BaseRule class.
To implement a custom Java business rule, extend BaseRule class, providing implementation for the following method:
public abstract void executeRules(EventTaskObject task)
Java business rules can obtain all necessary information from the EventTaskObject, passed as an input parameter of the executeRules() method. EventTaskObject contains information about the business entity itself, events that have already occurred for this business entity and additional information such as today's date, event horizon, and others (see the figure below).
To obtain list of the occurred events, use the getOccurredEvents() method, which returns a vector of EventObj objects. Each EventObj object contains information such as the name of predefined events if the event is not user explicit, date when the event occurred, and others.
To obtain the business data object or transaction object, use methods getDataObj() and getTransactionObj(), respectively.
EventTaskObject can provide today's date when getToday() method is called. Also, to write the rules designed to determine future data of the event occurrence, it is important to know how far in the future the rule is supposed to look. The getToDate() method returns today's date increased by the number of days specified as the event horizon in the CDEVENTCAT table. For example, if today is May 10, and the value of the EVENT_HORIZON field in CDEVENTCAT table is 365, the getToDate() method returns the date of May 10 next year. This date can then be used to determine the time of the occurrence of events in the future.
When current or future events are detected by the rule, it is important to communicate that information to Event Manager. Rules must add the newly-detected events to the list of the pending events on the EventTaskObject using the addPendingEventObject(EventObj eventObject) method. If the event is a current occurred event, then the creation date of the EventObj should be set to the time this event is going to occur in the future. For tracking purposes, the events created by rules should have the event trigger property set to EventTriggered. Use the constant EventManagerConstants.TRIGGER_EVENT_TRIGGERED to set this value.