When to use SystemEvents?
There can be various scenario to use system events such as:
1. Generating output of daily updates on the certain tables
2. Generating sitemap.xml
3. Call certain services such as creating assets from other systems
4. Call custom search like SOLR search
5. Call list of pages so that event works as crawler on delivery system. For e.g. on publish, pages are flushed, thus, pages are required to generated again. Thus, if those pages are calculated, then can be crawled with SystemEvents too.
There are 2 ways by which you can create SystemEvents: either via ContentServerExplorer/SitesExplorer or via programming
With SitesExplorer, it is very easy. You just need to add an entry within it manually with appropriate values and that's it. But certain clients don't allow access to SitesExplorer or CatalogMover and thus, it is difficult when such events are required. Hence, the need of a program which can create System Events whenever required as shown below:
Following SystemEventsUtility should provide an idea on how to create utility to perform all the tasks related to events: create, enable, disable and destroy.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@page import="org.apache.commons.lang.StringUtils" | |
%><%@page import="COM.FutureTense.Interfaces.Utilities" | |
%><%@page import="COM.FutureTense.Interfaces.ICS" | |
%><%@page import="COM.FutureTense.Interfaces.FTValList" | |
%><%@ taglib prefix="cs" uri="futuretense_cs/ftcs1_0.tld" | |
%><cs:ftcs><%-- | |
/** | |
* @author: fatwiredev | |
* Sample utility element to create / destroy / disable / enable System Events | |
* INPUT: task (required), eventpagename (required), eventname(required only for create task) , eventtarget(required only for create task), eventtime(required only for create task) | |
* OUTPUT: status - SUCCESS OR FAIL | |
*/ | |
--%><% | |
String taskToPerform = ics.GetVar("task"); //create, destroy, disable, enable | |
boolean proceed = checkParameters(ics, taskToPerform); | |
if(proceed){ | |
int taskstatus = performEventTask(taskToPerform, ics); | |
%><%= taskstatus == 0 ? "Success" : "Failed"%> to perform the task: <%= taskToPerform%><% | |
} else { | |
%>Missing required params for the task: <%= taskToPerform %><% | |
}%><%! | |
public String getTaskParams(String task) { | |
return "create".equals(task) ? "eventname,eventtarget,eventtime,eventpagename" : "eventpagename"; | |
} | |
public boolean checkParameters(ICS ics, String task){ | |
String params = getTaskParams(task); | |
boolean isParamPresent = false; | |
if(params.indexOf(",") != -1){ | |
String parameters[] = StringUtils.split(","); | |
for(String param: parameters){ | |
isParamPresent = Utilities.goodString(param); | |
if(!isParamPresent) break; | |
} | |
} else { | |
return Utilities.goodString(params); | |
} | |
return isParamPresent; | |
} | |
public int performEventTask(String task, ICS ics){ | |
int status = 1; | |
switch (task) { | |
case "create": | |
status = CreateEvent(ics.GetVar("eventname"), ics.GetVar("eventpagename"), ics.GetVar("eventtime"), ics.GetVar("eventtarget"), ics); | |
break; | |
case "destroy": | |
status = DestroyEvent(ics.GetVar("eventname"), ics); | |
break; | |
case "disable": | |
status = DisableEvent(ics.GetVar("eventname"), ics); | |
break; | |
case "enable": | |
status = EnableEvent(ics.GetVar("eventname"), ics); | |
break; | |
default: | |
throw new IllegalArgumentException("Invalid task: " + task); | |
} | |
return status; | |
} | |
public int EnableEvent(String eventname, ICS ics){ | |
return ics.EnableEvent(eventname) ? 0 : 1; | |
} | |
public int DisableEvent(String eventname, ICS ics){ | |
return ics.DisableEvent(eventname) ? 0 : 1; | |
} | |
public int DestroyEvent(String eventname, ICS ics){ | |
return ics.DestroyEvent(eventname) ? 0 : 1; | |
} | |
public int CreateEvent(String eventname, String eventpagename, String eventtime, String eventtarget, ICS ics){ | |
ics.ClearErrno(); | |
FTValList params = new FTValList(); | |
params.setValString( "pagename" , eventpagename ); | |
ics.AppEvent( eventname , eventtarget , eventtime , params ); | |
return ics.GetErrno(); | |
} | |
%></cs:ftcs> |
Information related to the methods are present in Oracle WebCenter Sites Tag library.
Disclaimer: The code and/or the configurations posted are not official recommendations and should be used at sole's discretion with proper testing before deploying on live WebCenter Sites systems. Cheers!!