Create custom activity in WebCenter Activity Stream

person Bijeshfolder_openOracle, WebCenteraccess_time January 30, 2015

WebCenter provides an out-of-the-box activity stream that is leveraged to log user activities like add documents, posting messages, modifying space/portal settings, etc. The Activity Stream module also exposes an API that may be used to add custom activity events to the stream.

I couldn’t find a single source for all the information about publishing custom activities and so I decided to log my experience using the APIs. The post also includes sample code for publishing an activity.

At a high level, these are the steps

  1. Define a service via service-definition.xml. The main details include
    • A unique serviceId
    • resource bundle for the activity message, etc.
    • activity types
    • object types
    • resource view and resource mini view if applicable
  2. Java code to use the ActivityStreamingService and associated API to publish the event
  3. Deploy to  WebCenter Portal as an ADF Library Jar within a shared library

The sample demonstrates publishing a “Create purchase order” activity to the stream. The README file and the screenshots should give an idea of the what and the how. Here’s a peak at the code

    1. service-definition.xml
<?xml version="1.0" encoding="utf-8" ?>
<definitions xmlns="http://xmlns.oracle.com/webcenter/framework/service">
 <service-definition id="com.uxcredrock.purchaseorder" version="11.1.1.0.0">
     <resource-view 
            taskFlowId="/WEB-INF/taskflows/po-resource-viewer-tf.xml#po-resource-viewer-tf"/>
     <resource-mini-view 
            taskFlowId="/WEB-INF/taskflows/po-resource-viewer-tf.xml#po-resource-viewer-tf" 
                                 preferredHeight="400" preferredWidth="640"/>
     <name>Purchase Order Viewer</name>
     <name-key>SERVICE_NAME</name-key>
     <description>Purchase Order Viewer</description>
     <description-key>SERVICE_DESCRIPTION</description-key> 
     <resource-bundle-class>com.uxcredrock.view.po.resource.POMessageBundle</resource-bundle-class>
     <activity-types>
         <generic-activity-category name="CREATE">
             <activity-type name="createPO" displayName="Create Purchase Order"
                                 description="mydescription"
                                 descriptionKey="ACTIVITY_POST_DESC_KEY"
                                 messageFormatKey="ACTIVITY_POST_MSG"/>
         </generic-activity-category>
     </activity-types>
     <object-types>
         <object-type name="purchaseOrder" displayName="Purchase Order"
                 description="Purchase Order"/>
     </object-types>
 </service-definition>
</definitions>
    1. Instantiate and use ActivityStreamingService API
ActivityStreamingService service = 
                     ActivityStreamingServiceFactory.getInstance().getActivityStreamingService();
//requires the GUID of the user in WebCenter Portal
ActivityActor actor = service.createActor(userGUID); 
ServiceObjectType objectType =  service.findObjectType(serviceId, "purchaseOrder");
ActivityObject activityObject = service.createObject(purchaseOrderId
                                                   , objectType
                                                   , purchaseOrderSummary);
ActivityType activityType = service.findActivityType(serviceId, activityTypeName);
ActivityElement  activityElement = 
                           service.createActivityElement(Utility.getApplicationName()
                                                      , serviceContext.getScope(), serviceId
                                                      , activityType , activityActors
                                                      , activityObjects, ActivityPermission.SHARED
                                                      , new Date());
service.publish(activityElement);

The source code is here: ActivityStreamingSample.7z

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>