OIEP - Configuration Section for Business Rule Based Message Processor

The outbound Business Rule Based Message Processor allows you to compose the representation of STEP data to be exported using either JavaScript-based business actions or Java business actions developed via the Extension API.

For more information on JavaScript business actions, refer to the Business Action: Execute JavaScript topic in the Business Rules documentation. For information on the Extension API, refer to the Technical Documentation accessible at [system]/sdk or from the system Start Page.

As illustrated below, the Business Rule Based Message Processor in an OIEP uses two business actions:

  • A node handler is invoked once for each batch element to be exported and is responsible for producing the export representation of the node / event.
  • A joiner has access to all representations produced by the node handler and is responsible for joining these into a single message to be delivered from STEP.

Prerequisites

  1. Contact Stibo Systems to activate the Business Action Processor commercial license. This enables the event-based importer and exporter to process inbound messages in custom / generic formats using JavaScript-based business rules, and enables exports to custom / generic formats including JSON using JavaScript business rules.
  2. Business actions used by this processor should be configured to be valid for all object types.
  3. Review the Node Handler Business Action Details and Examples and the Joiner Business Action Details and Examples sections below for more information about the business actions expected for this processor.

Configuration

A second Configuration section is available when the Business Rule Based Message Processor is selected for an OIEP. For information on selecting a process engine, refer to the OIEP - Event-Based - Configure Endpoint topic (here) or the OIEP - Select Objects - Configure Endpoint topic (here).

This section includes the same parameters for both Event-Based and Select Objects endpoints. Each parameter is described below.

Set up the Business Rule Based Message Processor in the Configuration section:

  1. For the Node Handler parameter, click the ellipsis button () to select the business action responsible for producing the representation of each node / event in the batch to be exported.
  2. For the Joiner parameter, click the ellipsis button () to select the business action responsible for combining messages produced by the node handler into one message.
  3. For the Output file extension parameter, enter the extension for the files to be exported.
  4. The Collate nodes parameter is only applicable to event-based OIEPs, where a batch can contain multiple events for the same node. Select an option from the dropdown:
  • Yes - pass nodes to the node handler business action once per batch. Access is not available to information about the type of event that caused the node / event to be queued.
  • No - pass nodes /events as they occur, while having access to information about the type of event that caused the node / event to be queued.

Node Handler Business Action Details and Examples

The node handler business action is invoked once per node / event in the batch to be processed and is responsible for producing a textual representation of the data.

The OutboundBusinessProcessorNodeHandlerSource interface (for JavaScript business actions, the interface is available via the Outbound Node Handler Source bind option) provides the business action with access to the batch element. The interface has the following methods for accessing node / event information:

  • getNode(): Node: The node to export / the node related to the event to be processed. This will always be the node as it looks now in the system. That is to say, the node will not for event-based publishing be a historical version representing the data as it looked when the event was generated. This method can return null if the node has been purged (isPurged() returns true).
  • getSimpleEventType(): SimpleEventType: The event type. This is only available if the outbound integration endpoint is event-based and the 'Collate nodes' parameter is set to 'No.'
  • isDeleted(): boolean: Returns true if the node related to the batch element being processed has been deleted. This covers the case where the node has been deleted but still exists in the recycle bin, and also the case where the node has been purged from the system.
  • isPurged(): boolean: Returns true if the node no longer exists in the system.
  • getPurgedNodeID(): String: If the node has been purged (isPurged() returns true), it is possible to get the ID of the purged node via this method. It is not possible to get the 'type' of the purged node, meaning that this method primarily makes sense for setups where only nodes of a single super type are published (since, for example, a product and a classification can have the same ID).

The OutboundBusinessProcessorNodeHandlerResult interface (for JavaScript business actions, the interface is available via the Outbound Node Handler Result bind option) is used by the node handler business action to pass the output via the following methods:

  • addMessage(String messageGroup, String message) allows for messages to be added to what could be thought of as a named bucket. As the joiner business action (described below) can read messages from such named buckets. This allows, for example, all product 'upsert' messages (messages that 'update' or 'insert' as necessary) to be put into one bucket and all product 'delete' messages to be put into another, and the joiner can then add these messages to specific sections of the final combined message.
  • addMessage(String message) adds a message to a generic anonymous group. Use this option if all message should be treated the same way by the joiner.

Further, the action has access to a standard Logger, a Manager and an OutboundBusinessProcessorExecutionReportLogger.

Notice that the node handler is not run in a transaction meaning that it is not possible to modify STEP data from the node handler.

JSON Message Node Handler JavaScript Business Action Example

This example shows how a simple JSON messages can be constructed and messages for 'upserts' and 'deletions' added to different message groups.

Note: JSON.stringify() cannot handle Java Strings and these therefore are converted to JavaScript strings when values are set for 'mesg' object properties.

// Node Handler Source bound to nodeHandlerSource
// Node Handler Result bound to nodeHandlerResult
// ExecutionReportLogger bound to executionReportLogger

var simpleEventType = nodeHandlerSource.getSimpleEventType();
if (simpleEventType == null) {
  executionReportLogger.logInfo("No event information available in node handler");
} else {
  executionReportLogger.logInfo("Event with ID '" + simpleEventType.getID()+ "' passed to node handler");
}
var node = nodeHandlerSource.getNode();
if (node != null && node instanceof com.stibo.core.domain.Product) {
  executionReportLogger.logInfo("Node handler handling product with URL: " + node.getURL());
  var mesg = {};
  mesg.stepid = node.getID() + "";
  mesg.ean = node.getValue("EAN").getSimpleValue() + "";
  if (nodeHandlerSource.isDeleted()) {
    nodeHandlerResult.addMessage("delete", JSON.stringify(mesg));	
  } else {
    mesg.category = node.getParent() == null ? null : node.getParent().getID() + "";
    mesg.shortDescription = node.getValue("ShortDescription").getSimpleValue() + "";
    mesg.manufacturerName = node.getValue("ManufacturerName").getSimpleValue()+ "";
    mesg.color = node.getValue("Color").getSimpleValue()+ "";
    nodeHandlerResult.addMessage("upsert", JSON.stringify(mesg));	
  }
}

Joiner Business Action Details and Examples

The joiner business action is responsible for combining the messages produced by the node handler into a single message that can be delivered to downstream systems.

The OutboundBusinessProcessorJoinerSource interface (for JavaScript business actions, the interface is available via the Outbound Joiner Source bind option) provides the business action access to the messages.

The OutboundBusinessProcessorJoinerResult interface appendToMessage(String) method (for JavaScript business actions, this interface is available via the Outbound Joiner Result bind option) allows the business action to deliver its output. The appendToMessage(String) does not automatically apply any new lines or formatting.

The business action also has access to a standard Logger and an OutboundBusinessProcessorExecutionReportLogger.

Notice that the joiner is not run in a transaction meaning that it is not possible to modify STEP data from the node joiner.

JSON Message Joiner JavaScript Business Action Example

This example shows how messages from different message groups can be combined to a single message and further shows how duplicates can be avoided (there can be several elements in an event batch representing the same node).

// Joiner Source bound joinerSource
// Joiner Result bound to joinerResult

function appendFromGroup(messageGroup) {
  var seen = [];
  var first = true;
  while(joinerSource.hasNext(messageGroup)) {
    var messageString = joinerSource.getNextMessage(messageGroup);
    var hash = messageString.hashCode();
    if (seen.indexOf(hash) == -1) {
      seen.push(hash);
      if (first) {
        first = false;
      } else {
        joinerResult.appendToMessage(",");
      }
      joinerResult.appendToMessage(messageString);
    }
  }
}

joinerResult.appendToMessage("{\"products\":{\"upsert\":[");
appendFromGroup("upsert");
joinerResult.appendToMessage("],\"delete\":[");
appendFromGroup("delete");
joinerResult.appendToMessage("]}}");