Event-Based Example Business Rules for Derived Events

Problem: A different output format is required for each derived event type.

Solution: Use JavaScript-based business rules in an event-based OIEP to:

  • Create a business condition to filter out (discard) Republish events.
  • Create a business action to generate derived events when products are linked, removed, or modified in a specific classification hierarchy and distinguishes if the products have been created, modified, or deleted in the classification structure.
  • Apply the business rules to the OIEP on the Event Triggering Definitions tab, in the Triggering Object Types table.

Important: The following scripts are only an example and should not be used as-is without thorough testing, including updating to match object and link types that exist on your system.

The following derived event types are used in this example:

  • A product is linked into a classification and approved for the first time. In this case, a derived event with the event type 'website create' is generated.
  • A product is approved and linked into a classification, but data on the product is approved with modifications. In this case, a derived event with event type 'website modify' is generated.
  • A product is approved and linked into a classification, but approved with a deletion of the product to classification link. In this case, a derived event with event type 'website delete' is generated.

Event Filter - Using a bulk update or business action could generate Republish events, but they would be registered as core 'create' events. Instead, generate a derived event and then configure the relevant OIEP to discard all events that are not of this type.

Create a new business condition and make it valid for the appropriate object types. Use the Evaluate JavaScript operation and add a bind for the Current Event Type.

Use the following JavaScript code to identify the derived event types:

if (currentEventType.getID() == "website modify" || 
    currentEventType.getID() == "website create" ||
    currentEventType.getID() == "website delete"){
	return true;	
}

return false;

Event Generator - Only standard derived event types can be used with JavaScript-based business actions. For additional information on JavaScript syntax for STEP, access the Technical Documentation, available at [system]/sdk or from the Start Page.

Create a new business action and make it valid for the appropriate object types. Use the Execute JavaScript operation and add the following binds, including binds for the derived events:

Use the following JavaScript code to create a derived event based on the approved change on the product:

Copy
if (approveContext){
   var linkType = manager.getLinkTypeHome().getClassificationProductLinkTypeByID("Web Classification");

var links = node.getClassificationProductLinks().get(linkType);
var linkedToWebsite = links.size() > 0;
var linkChanged = false;
var partObjects = approveContext.getPartObjects();

       var iter = partObjects.iterator();
while (iter.hasNext()) {
var part = iter.next();
      if (part instanceof com.stibo.core.domain.partobject.ClassificationLinkPartObject){
      if (part.getLinkTypeID() == "Web Classification"){
      linkChanged = true;    
      }
      } 
     }

if (linkedToWebsite && linkChanged){
     queue.queueDerivedEvent(webCreate, node);
     } else if (!linkedToWebsite && linkChanged) {
     queue.queueDerivedEvent(webDelete, node);
     } else if (linkedToWebsite && !linkChanged){
     queue.queueDerived
Event(webModify, node);
     }
}   

Output Template - Using the configuration described above, you will need an output template for each different type of event. This can be one or multiple lines, dependent on the need for different messages for the different events. Refer to OIEP - Event-Based - Output Templates Section topic (here) for more information.