47 Asset and Publish Events in WebCenter Sites

WebCenter Sites's event framework enables developers to write custom business logic to execute upon certain specific events in WebCenter Sites. The custom business logic needs to be implemented in the form of Java classes in the classpath that implements a pre-defined interface. This tutorial takes you through the process of creating listeners.

This chapter takes you through the process of creating event listeners and contains the following sections:

47.1 Types of Events

Two types of events are currently supported by WebCenter Sites: Asset events and Publishing events.

  • Asset events are the events that happen when assets are added, modified or deleted, either by a user or programmatically. Upon these events, the event framework looks up and executes the set of configured events.

  • Publishing events are events that the RealTime publishing framework generates at each step of the publishing process. This feature is intended to facilitate system monitoring (such as SNMP) and other housekeeping processes.

47.2 Asset Events

This section contains the following topics:

47.2.1 Writing an Asset Event Listener

Asset listeners need to extend AssetEventListener in order to be notified of asset changes. A convenient base class AbstractAssetEventListener comes with WebCenter Sites. Extending from this class makes it easy to recognize the specific type of action that led to the event (add/modify/delete).

The following sample code implements a custom asset listener. All it does is print the asset IDs; however, it is easy to see how one could plug in custom business logic.

package com.mycompany
public final class CustomAssetEventListener extends AbstractAssetEventListener
{
    public void assetAdded(AssetId id)
    {
        System.out.println("Asset " + id + " added");
    }
    public void assetUpdated(AssetId id)
    {
        System.out.println("Asset " + id + " added");
    }
    public void assetDeleted(AssetId id)
    {
        System.out.println("Asset " + id + " added");
    }
}

Asset event listeners are invoked after the asset operation has taken place, but before committing the data.

47.2.2 Registering an Asset Event Listener

Note:

WebCenter Sites ships with a standard listener that is used for search indexing. Do not alter or delete it.

Asset event listeners are registered in the AssetListener_reg database table. Here is the structure of the table:

Table 47-1 AssetListener_reg Database Table

ID (integer) Unique Identifier for the Row

listener(String)

Fully qualified class name that implements AssetEventListener. For example: com.mycompany.CustomAssetEventListener

blocking(Y or N)

'Y' indicates that the listener is blocking (runs synchronously with the thread that generated the event).

'N' indicates that the listener is non blocking (runs in a separate thread).


47.3 Publishing Events

This section contains the following topics:

47.3.1 Writing a Publishing Event Listener

Publishing listeners need to implement PublishingEventListener. A PublishingEvent passed into the listener indicates the specific event that caused the invocation.

The following example shows a custom implementation that prints the pubsession ID to the console

package com.mycompany;
public class CustomPublishingEventListener implements PublishingEventListener
{
    public void onEvent( PublishingEvent event ) throws EventException
    {
        System.out.println( "Publishing event fired for     pubsession: " + event.getPubSessionId());
        System.out.println( "Publishing task : " + event.getTaskName());
        System.out.println( "Status of the task :  " + event.getStatus());
        System.out.println( "Message associated with the task : " + event.getMessage() );
    }
}

Publishing consists of multiple tasks (data gathering, packaging, transport, and so on), and each of them generates events. The PublishingEvent class represents an event in the publishing task. An implementation can query the task and its status from the event as shown above.

Each task generates events when the following states are reached:

  • STARTED

  • DONE

  • CANCELLED

  • SUBTASK_FINISHED

  • FAILED

47.3.2 Registering a Publishing Event Listener

Publish event listeners are registered in the FW_PublishingEventRegistry database table. Here is the structure of the table:

Table 47-2 FW_PublishingEventRegistry Database Table

ID (integer) Unique Identifier for the Row

listener(String)

Fully qualified class name that implements AssetEventListener. For example com.mycompany.CustomPublishingEventListener

blocking(Y or N)

'Y' indicates that the listener is blocking (runs synchronously with the thread that generated the event).

'N' indicates that the listener is non blocking (runs in a separate thread).