com.ibm.commerce.marketing.dialog.trigger

Class SensorEventListener

  • java.lang.Object
    • com.ibm.commerce.event.EventComponentConfiguration
      • com.ibm.commerce.event.usertraffic.UserTrafficEventListener
        • com.ibm.commerce.marketing.dialog.trigger.SensorEventListener
  • All Implemented Interfaces:
    com.ibm.commerce.event.WCSEventListener, ComponentConfiguration, java.util.EventListener


    public class SensorEventListener
    extends com.ibm.commerce.event.usertraffic.UserTrafficEventListener
    This class listens for events being raised by the WebSphere Commerce Server and takes appropriate action for each of them.
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      static java.lang.String CLASSNAME
      The name of this class.
      static java.lang.String COMPONENT_NAME
      Component name "SensorEventListener"
      static java.lang.String COPYRIGHT
      IBM copyright notice field.
      static java.lang.String TYPE_COMMAND_EXIT
      Trigger on the successful exit of a command
      static java.lang.String TYPE_REQUEST_BEGIN
      Trigger on the beginning of a request
      static java.lang.String TYPE_REQUEST_END
      Trigger on the end of a request
      • Fields inherited from class com.ibm.commerce.event.usertraffic.UserTrafficEventListener

        SQL, TABLE_NAME
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      java.lang.String buildBehaviorRuleKey(java.lang.Integer elementTypeId, java.lang.String command, java.lang.Integer storeId)
      This method constructs a key to find UserBehaviorRule objects in the cache.
      void destroy()
      Destroys this event listener, and calls the marketing engine to persist the statistics.
      java.util.List getBehaviorRules(java.lang.String key)
      This method get the current active filter rules that match the given key.
      java.util.List getBehaviorRules(java.lang.String command, java.lang.Integer storeId, java.lang.String urlString, java.lang.String referralURL, java.lang.Integer elementTypeId, java.lang.String eventOccurrence)
      This method looks in the cache for activities that match the command, store and url string (i.e.
      static java.lang.String getCustomInformation(CommandContext commandContext, java.lang.String existingCustomInformation)
      This method gets the custom information from the current marketing context and returns a string to be placed in the user XML string.
      MarketingFacadeClient getMarketingFacadeClient()
      This method gets the marketing facade client to use when making web service calls.
      MarketingFacadeClient getMarketingFacadeClient(java.lang.Integer storeId, java.lang.String forUserId)
      This method gets the marketing facade client to use when making web service calls.
      java.lang.Integer[] getStorePath(java.lang.Integer storeId)
      This method gets the store IDs related to the specified store id by the campaigns store relationship type.
      void init(org.w3c.dom.Element node)
      Initializes this event listener, using the component attributes provided in the method parameter.
      boolean isDateValidForActivity(java.lang.Integer activityId)
      This method returns true if the current timestamp is in the range of valid dates for this activity.
      static void processActivityEvent(CommandContext commandContext, javax.servlet.http.HttpServletRequest httpServletRequest, java.lang.String eventOccurrence, java.lang.String commandName, java.lang.String forUserId)
      This method processes events sent at the beginning of every request, or when a command successfully exits.
      void processActivityEvent(com.ibm.commerce.event.usertraffic.UserTrafficData data, java.lang.String eventOccurrence, java.lang.String customInformation, java.lang.String forUserId)
      Processes events sent at the beginning of every request, or when a command successfully exits.
      void processActivityEvent(com.ibm.commerce.event.WCSEvent event)
      Processes events sent at the end of every request.
      • Methods inherited from class com.ibm.commerce.event.usertraffic.UserTrafficEventListener

        enable, flushCache, isRegistered, isTransactionRequired
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • COPYRIGHT

        public static final java.lang.String COPYRIGHT
        IBM copyright notice field.
        See Also:
        Constant Field Values
      • CLASSNAME

        public static final java.lang.String CLASSNAME
        The name of this class.
        See Also:
        Constant Field Values
      • COMPONENT_NAME

        public static final java.lang.String COMPONENT_NAME
        Component name "SensorEventListener"
        See Also:
        Constant Field Values
      • TYPE_REQUEST_BEGIN

        public static final java.lang.String TYPE_REQUEST_BEGIN
        Trigger on the beginning of a request
        See Also:
        Constant Field Values
      • TYPE_REQUEST_END

        public static final java.lang.String TYPE_REQUEST_END
        Trigger on the end of a request
        See Also:
        Constant Field Values
      • TYPE_COMMAND_EXIT

        public static final java.lang.String TYPE_COMMAND_EXIT
        Trigger on the successful exit of a command
        See Also:
        Constant Field Values
    • Constructor Detail

      • SensorEventListener

        public SensorEventListener()
    • Method Detail

      • init

        public void init(org.w3c.dom.Element node)
                  throws java.lang.Exception
        Initializes this event listener, using the component attributes provided in the method parameter.
        Specified by:
        init in interface ComponentConfiguration
        Overrides:
        init in class com.ibm.commerce.event.EventComponentConfiguration
        Parameters:
        node - the element object that contains detail of the component
        Throws:
        java.lang.Exception - Thrown when an error occurs while initializing this listener.
      • destroy

        public void destroy()
        Destroys this event listener, and calls the marketing engine to persist the statistics.
        Specified by:
        destroy in interface ComponentConfiguration
        Overrides:
        destroy in class com.ibm.commerce.event.usertraffic.UserTrafficEventListener
      • processActivityEvent

        public static void processActivityEvent(CommandContext commandContext,
                                                javax.servlet.http.HttpServletRequest httpServletRequest,
                                                java.lang.String eventOccurrence,
                                                java.lang.String commandName,
                                                java.lang.String forUserId)
        This method processes events sent at the beginning of every request, or when a command successfully exits. Check if there are any behavior rules that match the request, and if so, if the request matches the behavior rules parameters. The behavior rules are associated with events, so if the request matches, then send the event to the Marketing trigger handler. This method is called from the Campaigns Filter when the Sensor Event Listener component is enabled. This method is called from the ProcessCommandExitFactory when a command enabled under marketing behavior rule event type successfully exits.
        Parameters:
        commandContext - The command context of the event.
        httpServletRequest - The servlet request associated with the event.
        eventOccurrence - When did this event occur. Valid values are 0 (at the beginning of a request - TYPE_REQUEST_BEGIN), 1 (at the end of a request - TYPE_REQUEST_END), or 2 (when a command successfully exits - TYPE_COMMAND_EXIT).
        commandName - The name of the command being processed. This is passed in for when a command successfully exits.
        forUserId - An optional parameter that specifies that the Process MarketingTrigger request should be called in the context of the provided user ID.
      • processActivityEvent

        public void processActivityEvent(com.ibm.commerce.event.usertraffic.UserTrafficData data,
                                         java.lang.String eventOccurrence,
                                         java.lang.String customInformation,
                                         java.lang.String forUserId)
                                  throws ECException
        Processes events sent at the beginning of every request, or when a command successfully exits. Check if there are any behavior rules that match the request, and if so, if the request matches the behavior rules parameters. The behavior rules are associated with events, so if the request matches, then send the event to the Marketing trigger handler. This method is called from the Campaigns Filter when the Sensor Event Listener component is enabled. This method is called from the ProcessCommandExitFactory when a command enabled under marketing behavior rule event type successfully exits.
        Parameters:
        data - The user traffic data to process.
        eventOccurrence - When did this event occur. Valid values are 0 (at the beginning of a request - TYPE_REQUEST_BEGIN), 1 (at the end of a request - TYPE_REQUEST_END), or 2 (when a command successfully exits - TYPE_COMMAND_EXIT).
        customInformation - The custom information to include in the user identifier xml.
        forUserId - An optional parameter that specifies that the Process MarketingTrigger request should be called in the context of the provided user ID.
        Throws:
        ECException - Problem processing the event.
      • processActivityEvent

        public void processActivityEvent(com.ibm.commerce.event.WCSEvent event)
                                  throws ECException
        Processes events sent at the end of every request. Check if there are any behavior rules that match the request, and if so, if the request matches the behavior rules parameters. The behavior rules are associated with targets, so if the request matches, then send the information to the Marketing event handler to record the matching behavior. This method is called by the Commerce runtime event handling when the Sensor Event Listener is enabled.
        Specified by:
        processActivityEvent in interface com.ibm.commerce.event.WCSEventListener
        Overrides:
        processActivityEvent in class com.ibm.commerce.event.usertraffic.UserTrafficEventListener
        Parameters:
        event - The user traffic event to process.
        Throws:
        ECException - Problem processing the event.
      • getCustomInformation

        public static java.lang.String getCustomInformation(CommandContext commandContext,
                                                            java.lang.String existingCustomInformation)
        This method gets the custom information from the current marketing context and returns a string to be placed in the user XML string.
        Parameters:
        commandContext - The user's command context.
        existingCustomInformation - The custom information to include in the user identifier xml.
        Returns:
        This method returns the custom information from the current marketing context.
      • buildBehaviorRuleKey

        public java.lang.String buildBehaviorRuleKey(java.lang.Integer elementTypeId,
                                                     java.lang.String command,
                                                     java.lang.Integer storeId)
        This method constructs a key to find UserBehaviorRule objects in the cache.
        Parameters:
        elementTypeId - The ID of the type of the campaign element template.
        command - The current request command name.
        storeId - The ID of the store.
        Returns:
        This method returns the key constructed from the parameters passed in to the method.
      • isDateValidForActivity

        public boolean isDateValidForActivity(java.lang.Integer activityId)
        This method returns true if the current timestamp is in the range of valid dates for this activity. The method also checks if the activity is currently active and returns false if the state of the activity is inactive.
        Parameters:
        activityId - The ID of the activity to check.
        Returns:
        Returns true if the current timestamp is valid for this activity and the activity state is active, false otherwise.
      • getBehaviorRules

        public java.util.List getBehaviorRules(java.lang.String command,
                                               java.lang.Integer storeId,
                                               java.lang.String urlString,
                                               java.lang.String referralURL,
                                               java.lang.Integer elementTypeId,
                                               java.lang.String eventOccurrence)
        This method looks in the cache for activities that match the command, store and url string (i.e. NVPs) passed in. It returns a List where the keys are the set of matching elementIds, the values are a Map of the data for each element that needs to be included in the ActivityTrigger.
        Parameters:
        command - The command to look if there are matching behavior rules for.
        storeId - The store to look for behavior rules for.
        urlString - A URL string containing the parameters.
        referralURL - The referral URL for the current request.
        elementTypeId - The type of the element.
        eventOccurrence - When did this event occur. Valid values are 0 (at the beginning of a request - TYPE_REQUEST_BEGIN), 1 (at the end of a request - TYPE_REQUEST_END), or 2 (when a command successfully exits - TYPE_COMMAND_EXIT).
        Returns:
        A List which contains two List objects is returned. The two Lists encapsulated contain:
        • At index INDEX_UBRS is a List of UserBehaviorRule objects that are waiting to record this command.
        • At index INDEX_NVPS is a List of Maps where each map contains the Name/Value pairs that need to be detected for the UserBehaviorRule.
        The name-value pairs to record for the UserBehaviorRule at matches.get(INDEX_UBRS).get(i) are found at matches.get(INDEX_NVPS).get(i).
      • getBehaviorRules

        public java.util.List getBehaviorRules(java.lang.String key)
        This method get the current active filter rules that match the given key. The key has the format of either: DM_BHVRTRIG_commandstoreId or DM_BHVRTARG_commandstoreId. Some examples are: DM_BHVRTRIG_Logon10101, DM_BHVRTARG_*10101.
        Parameters:
        key - The key for the filter rule.
        Returns:
        A list of UserBehaviorRule objects that match the given key.
      • getStorePath

        public java.lang.Integer[] getStorePath(java.lang.Integer storeId)
                                         throws javax.naming.NamingException,
                                                java.sql.SQLException
        This method gets the store IDs related to the specified store id by the campaigns store relationship type. The related store IDs are sorted in ascending order of the store relationship sequence. When there are no related stores, this store's ID is returned.
        Parameters:
        storeId - The store ID
        Returns:
        This method returns an Integer array of store IDs.
        Throws:
        javax.naming.NamingException
        java.sql.SQLException
      • getMarketingFacadeClient

        public MarketingFacadeClient getMarketingFacadeClient()
        This method gets the marketing facade client to use when making web service calls.
        Returns:
        The marketing facade client.
      • getMarketingFacadeClient

        public MarketingFacadeClient getMarketingFacadeClient(java.lang.Integer storeId,
                                                              java.lang.String forUserId)
        This method gets the marketing facade client to use when making web service calls. This method is used to set the correct store ID in the context when making the web service call.
        Parameters:
        storeId - The ID of the store to set in the business context.
        forUserId - An optional parameter that specifies that the Process MarketingTrigger request should be called in the context of the provided user ID.
        Returns:
        The marketing facade client.