Oracle Portal Actions and CMEF Events

16-16 Oracle Fusion Middleware Developers Guide for Oracle Portal message.raw_event = INSERT and message.state = PUBLISHED then . . . end if;

16.3.7.2.2 Adding an Item That Requires Approval If approvals and notifications are

enabled for a page or page group, and a user with Manage Items With Approval privileges, adding an item to a page produces the following message payload: If you want your subscriber to respond to this action, perform the following check: if message.action = SUBMIT_ITEM_FOR_APPROVAL and message.object_class = ITEM and message.raw_event = INSERT and message.state = NOT_PUBLISHED then . . . end if;

16.3.7.2.3 Approving an Item Approving an item triggers either an INSERT or UPDATE

event, which may also be followed by either a DELETE or UPDATE event depending upon whether or not versioning is enabled. Item approved; versioning disabled This is the simplest case. If the item still has approval steps to pass through, then an UPDATE event is triggered: If the item has completed all approval steps, then an INSERT event is triggered: Item approved; versioning enabled; current version overwritten If item versioning is set to Simple at the page or page group level, and a user selects Overwrite Current Version when editing an item, on approval of the item, two events are generated. The first event is for the item that is approved, and a second DELETE event for the item that is overwritten as a result of the item being approved: Action Event State Object Class SUBMIT_ITEM_FOR_ APPROVAL INSERT NOT_PUBLISHED ITEM Action Event State Object Class APPROVE_ITEM_ STEP UPDATE GENERAL ITEM Action Event State Object Class APPROVE_ITEM INSERT PUBLISHED ITEM Action Event State Object Class APPROVE_ITEM INSERT PUBLISHED ITEM APPROVE_ITEM DELETE PURGED ITEM Using the Content Management Event Framework 16-17 Item approved; versioning enabled; new and current version If item versioning is set to Audit at the page or page group level, or it is set to Simple and a user selects Add Item As New And Current Version, on approval of the item an INSERT event is generated. An UPDATE event is also generated that is related to marking the previous version of the item as UNPUBLISHED: If you are writing a subscriber that sends a notification when an item is approved or has passed through a stage of being approved, you should perform the following check: -- If an item is approved. if message.action = APPROVE_ITEM and message.object.class = ITEM and message.raw_event = INSERT and message.state = PUBLISHED then . . . -- If an item has passed an approval step. elsif message.action = APPROVE_ITEM_STEP and message.object_class = ITEM and message.raw_event = UPDATE and message.state = PUBLISHED then . . . end if; Item approved, versioning enabled; new but not current version An INSERT event occurs for the item that is added, but the state of the item is marked as NOT_PUBLISHED to indicate that it is not published as the current version:

16.3.7.2.4 Applying a Category or Perspective to an Item Applying a different category or

perspective to an item produces the same message payload as editing an item: If you want your subscriber to respond to this action, perform the following check: if message.action = EDIT_ITEM and message.object_class = ITEM and message.raw_event = UPDATE and message.state = GENERAL then Action Event State Object Class APPROVE_ITEM INSERT PUBLISHED ITEM APPROVE_ITEM UPDATE UNPUBLISHED ITEM Action Event State Object Class APPROVE_ITEM INSERT NOT_PUBLISHED ITEM Action Event State Object Class EDIT_ITEM UPDATE GENERAL ITEM Note: No specific event is generated when the category or perspectives applied to an item are changed, and no additional information is provided. 16-18 Oracle Fusion Middleware Developers Guide for Oracle Portal . . . end if;

16.3.7.2.5 Deleting an Item Deleting an item from a page group that retains deleted

items that is, items are marked for deletion, but not actually deleted produces the following message payload: Deleting an item from a page group that does not retain deleted items that is, deleted items are immediately and permanently removed produces the following message payload: Your subscriber can use the state value within the message payload to determine what type of delete action occurred: if message.action = DELETE_ITEM and message.object_class = ITEM and message.raw_event = DELETE then . . . -- If item is in a page group that does not actually delete items. if message.state = MARKED_FOR_DELETE then . . . -- If item is in a page group that actually deletes items. elsif message.state = PURGED then . . . end if; end if;

16.4 Installing the Examples

If you would like to deploy and use the examples within the next few sections, we recommend that you create them in a separate schema, called CMEFSAMPLES. To create this schema, use the following steps:

1. Create the database schema CMEFSAMPLES. You need to do this as the SYS user,

since you need to grant permissions packages to which only SYS has access. This database schema must be in the same database as that in which the Oracle Portal repository resides. For example: connect as sysdba drop user cmefsamples cascade; create user cmefsamples identified by oracle1 default tablespace users temporary tablespace temp; grant connect, resource to cmefsamples;

2. As the SYS schema, grant the following privileges to CMEFSAMPLES:

connect as sysdba grant create table to cmefsamples; Action Event State Object Class DELETE_ITEM DELETE MARKED_FOR_ DELETE ITEM Action Event State Object Class DELETE_ITEM DELETE PURGED ITEM Using the Content Management Event Framework 16-19 grant create sequence to cmefsamples; grant create view to cmefsamples; grant create procedure to cmefsamples; grant create trigger to cmefsamples; grant create indextype to cmefsamples; grant create synonym to cmefsamples; grant create public synonym to cmefsamples; grant create database link to cmefsamples; grant create public database link to cmefsamples; grant execute on dbms_utility to cmefsamples; grant aq_administrator_role to cmefsamples; grant aq_user_role to cmefsamples; grant execute on dbms_aqadm to cmefsamples; grant execute on dbms_aq to cmefsamples; grant execute on aq_agent to cmefsamples; grant execute on dbms_job to cmefsamples; execute dbms_aqadm.grant_type_accesscmefsamples; execute dbms_aqadm.grant_system_privilegeENQUEUE_ANY,cmefsamples,FALSE; execute dbms_aqadm.grant_system_privilegeDEQUEUE_ANY,cmefsamples,FALSE; execute dbms_aqadm.grant_system_privilegeMANAGE_ANY, cmefsamples, FALSE; EXECUTE DBMS_AQADM.GRANT_QUEUE_PRIVILEGEENQUEUE,portal.WWSBR_EVENT_ Q,cmefsamples, FALSE; EXECUTE DBMS_AQADM.GRANT_QUEUE_PRIVILEGEDEQUEUE,portal.WWSBR_EVENT_ Q,cmefsamples, FALSE; 3. Grant the CMEFSAMPLES schema the permission to call the Oracle Portal PLSQL APIs. For information about how to do this, refer to Section 9.3, Providing Access to the APIs and Secure Views . 4. Log in to the portal schema and grant permissions on the following: EXECUTE DBMS_AQADM.GRANT_QUEUE_PRIVILEGEDEQUEUE,WWSBR_EVENT_ Q,cmefsamples, FALSE; grant execute on wwsbr_event_q_access to cmefsamples; grant execute on wwpob_page_util to cmefsamples; grant select on wwsbr_all_folders to cmefsamples; grant execute on wwsbr_thing_types to cmefsamples; grant execute on wwv_thingdb to cmefsamples; grant execute on wwsbr_event to cmefsamples; 5. Log in to the CMEFSAMPLES schema and run the following: sqlplus cmefsamplespassword create synonym aq_agent for sys.aq_agent; You can download the code for the following examples from OTN: http:www.oracle.comtechnologyproductsiasportalfilescm_overview_ 10g1014_cmef_samples.zip

16.5 Example: Portal Object Event Logging

The LOG_PORTAL_EVENT subscriber in Example 16–9 listens to CMEF events and then writes them to a log database table called CMEF_LOG_TABLE Example 16–8 . 16-20 Oracle Fusion Middleware Developers Guide for Oracle Portal Example 16–8 The CMEF_LOG_TABLE create table cmef_log_table action varchar230, event varchar230, state varchar230, object_type varchar230, object_id number, object_site_id number, object_language varchar230, page_id number, page_site_id number, performed_by varchar230 Example 16–9 The LOG_PORTAL_EVENT Subscriber create or replace procedure log_portal_event as agent_list dbms_aq.aq_agent_list_t; wait_time integer := 5; agent_w_message sys.aq_agent; dequeue_options dbms_aq.dequeue_options_t; message_properties dbms_aq.message_properties_t; message_handle raw16; message portal.wwsbr_event; l_subscriber varchar230 := CMEF_LOG_PORTAL_EVENT; l_queue varchar230 := PORTAL.WWSBR_EVENT_Q; l_mode binary_integer := dbms_aq.REMOVE; begin agent_list1 := sys.aq_agentl_subscriber, l_queue, null; loop -- Wait for messages. dbms_aq.listen agent_list = agent_list, wait = wait_time, agent = agent_w_message ; if agent_w_message.name = l_subscriber then dequeue_options.wait := dbms_aq.NO_WAIT; dequeue_options.consumer_name := l_subscriber; dequeue_options.navigation := dbms_aq.FIRST_MESSAGE; dequeue_options.dequeue_mode := l_mode; dbms_aq.dequeue queue_name = l_queue, dequeue_options = dequeue_options, message_properties = message_properties, payload = message, msgid = message_handle ; insert into cmef_log_table values message.action, message.raw_event, message.state, message.object_class, message.object_id, message.object_site_id, message.object_language, message.page_id, message.page_site_id, message.events_user Using the Content Management Event Framework 16-21 ; commit; end if; end loop; end; The LOG_PORTAL_EVENT subscriber continuously listens for events on the WWSBR_EVENT_Q queue until the wait time of 5 seconds as specified in the wait_ time variable is reached. It then dequeues CMEF events in REMOVE mode and then inserts the message payload values into the log table. You could use the code in Example 16–9 to build an HTML page that displays the results of the log table. For example, the table in Figure 16–6 shows the CMEF message payload for an edit item action: Figure 16–6 HTML Table Displaying CMEF Message Payload Values The properties of the CMEF message payload for example, message.raw_event are described in Section 16.3.6, CMEF Message Payload . If you want the LOG_PORTAL_EVENT subscriber to continually remove messages off the WWSBR_EVENT_Q queue, then you need to remove the following from Example 16–9 : dbms_aq.listen agent_list = agent_list, wait = wait_time, agent = agent_w_message ; if agent_w_message.name = l_subscriber then dequeue_options.wait := dbms_aq.NO_WAIT; dequeue_options.consumer_name := l_subscriber; dequeue_options.navigation := dbms_aq.FIRST_MESSAGE; dequeue_options.dequeue_mode := l_mode; END IF; Example 16–10 shows how to add the LOG_PORTAL_EVENT subscriber created in the previous section to the WWSBR_EVENT_Q queue. Example 16–10 Adding the LOG_PORTAL_EVENT Subscriber to WWSBR_EVENT_Q declare subscriber sys.aq_agent; begin subscriber := sys.aq_agentCMEF_LOG_PORTAL_EVENT, null, null; dbms_aqadm.add_subscriber queue_name = portal.wwsbr_event_q, subscriber = subscriber ; end; To run the LOG_PORTAL_EVENT subscriber, issue the command shown in Example 16–11 .