com.ibm.websphere.personalization
Class RuleTrigger

java.lang.Object
  extended by com.ibm.websphere.personalization.RuleTrigger
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
ContentSpot

public class RuleTrigger
extends java.lang.Object
implements java.io.Serializable

This class is used to trigger a Personalization rule.

Typically this class makes Resources available through an indexed Content property. RuleTrigger will initialize the triggering method, using the RequestContext it obtains from the PersonalizationContext. The Personalization Context is always used as the target object when triggering Personalization Rules.

Since:
8.5 CF08 Triggering of a WCM managed rule by name, e.g triggering a Segment Group by using the setRuleName method, is not supported. You must use the setRuleId method to indicate the rule to trigger if the rule is a WCM managed rule and you must use the UUID of the WCM managed rule item e.g. Segment Group. In this case you must enter the Id string in this format $[lib]UUID.
Examples

To execute a Segment Group called "mySegGroup" with a UUID of "d61d9ccb-8982-48c8-99cb-bf2aeb3b416a"in a WCM Library called "RulesHolder" in a JSP in Portal, the following series of calls would be issued.

 
      RuleTrigger ruleTrigger = new RuleTrigger();
      ruleTrigger.setRequest(portletRequest);
      ruleTrigger.setRuleId("$[lib]d61d9ccb-8982-48c8-99cb-bf2aeb3b416a");
      Object[] winingSegments = ruleTrigger.trigger();
 
 
See Also:
ContentSpot, Serialized Form

Field Summary
protected  Query additionalQuery
           
protected  java.lang.String asOfDate
           
protected  boolean audit
           
protected  java.lang.String campaignName
           
protected static com.ibm.websphere.personalization.campaigns.CampaignsFinder CAMPAIGNS_FINDER
           
protected  com.ibm.websphere.personalization.rules.PznOrderComparator categorizationOrder
           
protected  java.lang.Object[] content
           
protected  java.lang.String contentSpotUuid
           
static java.lang.String COPYRIGHT
           
protected static RuleExit defaultRuleExit
           
protected  java.lang.String displayName
           
static boolean includeRuntimeResultsInPreview
           
protected  java.lang.String limit
           
protected  java.lang.String name
           
protected  javax.servlet.http.HttpServletRequest req
          deprecated
protected  RequestContext requestContext
           
protected  java.lang.String resourceCollectionName
           
protected  RuleExit ruleExit
           
protected  java.lang.String ruleJSON
           
protected  com.ibm.websphere.personalization.campaigns.web.RuleMapping ruleMapping
           
protected  java.util.List ruleMappingsList
           
protected  java.lang.String ruleName
           
protected  java.lang.String ruleUuid
           
protected  java.lang.String scopeId
           
protected  boolean showErrors
           
protected  java.lang.String startIndex
           
 boolean useCascadingCampaigns
           
 
Constructor Summary
RuleTrigger()
           
 
Method Summary
static void addContentResourceCollectionName(java.lang.String collectionName, java.lang.String ruleName, RequestContext requestContext)
          .
protected  java.lang.String dateUsed()
          Determines the date being used.
protected  void findRule()
           
 boolean getAllItemsCached()
           
 boolean getAudit()
          Used to obtain the property which governs the collection of audit information
 int getCachedItems()
           
protected  com.ibm.websphere.personalization.campaigns.Campaign getCampaign(com.ibm.websphere.personalization.campaigns.Campaign[] campaigns, java.lang.String campaignName)
           
protected  int getCampaignIndex(com.ibm.websphere.personalization.campaigns.Campaign[] campaigns, java.lang.String campaignName)
           
 java.lang.String getCampaignName()
           
protected  com.ibm.websphere.personalization.campaigns.Campaign[] getCampaigns()
          This method returns a prioritized Array of active campaigns for this session.
 java.lang.String getClassification(int which)
          Deprecated. - use getProfile
 java.lang.String[] getClassifications()
          Deprecated. - Use getProfiles
 java.lang.Object[] getContent()
          Deprecated.  
 java.lang.Object getContent(int which)
          Deprecated.  
 java.lang.String getContentResourceCollectionName()
          Returns the name of the resource collection used by the rule executed in this content spot.
static java.lang.String getContentResourceCollectionName(java.lang.String ruleName, RequestContext requestContext)
          Returns the resource collection referenced by a rule that returns content from the request attribute keyed by the ruleName.
 java.lang.String getContentSpotId()
           
 java.lang.String getContentSpotName()
           
 RequestContext getContext()
          Return the PersonalizationContext.
 java.lang.String getDisplayName()
          Should be overriden by sub-classes to provide a name for instances of the RuleTrigger type.
 int getFirstPageRetrieved()
           
 java.lang.String[] getIds(java.lang.String resourceCollection)
          Deprecated. Warning: this call does not scale.
 int getMaxAvailableItems()
           
 java.lang.String getPreviewAnchorTag()
           
 java.lang.String getPreviewAnchorTag(javax.servlet.http.HttpServletResponse response)
           
 java.lang.String getProfile(int which)
          Provides access to the indexed profile property.
 java.lang.String[] getProfiles()
          Returns the full set of applicable profiles in an array.
 Resource getResource(java.lang.String id, java.lang.String resourceCollection)
          Deprecated.  
 java.lang.String getRuleId()
           
 java.lang.String getRuleJSON()
           
protected  com.ibm.websphere.personalization.campaigns.web.RuleMapping getRuleMapping()
           
 java.lang.String getRuleName()
           
 java.lang.Object[] getRuleResults()
          Returns the full set of content.
 java.lang.Object getRuleResults(int which)
          Used to obtain the indexed content object identified by which.
protected  java.lang.String getScopeId()
           
 boolean getShowError()
          Used to obtain the property which governs whether errors should be propagated or consumed.
protected  java.lang.String idOfUser()
          Determines the user being used.
 boolean isClassifiedAs(java.lang.String c)
          Deprecated.  
 boolean isProfiledAs(java.lang.String profile)
          Checks if the current user matches the given profile
 boolean isProfiledAsAll(java.lang.String[] profileNames)
          Checks if the Current user matches all of a list of profiles
 boolean isProfiledAsAny(java.lang.String[] profileNames)
          Checks if the Current user matches any of a list of profiles
 boolean isUsingCascadingCampaigns()
          Returns the useCascadingCampaigns.
static void resetContext(RequestContext context)
          Removes any information stored by the RuleTrigger on the context.
protected  com.ibm.websphere.personalization.campaigns.web.RuleMapping selectRule(com.ibm.websphere.personalization.campaigns.Campaign[] campaigns, java.util.List ruleMappings)
          This method selects the winning rule.
 void setAsOfDate(java.lang.String s)
          The date to be used in retrieving rules and in evalutating time based conditions.
 void setAudit(boolean se)
          Deprecated. Audit function is deprecated
protected  void setCampaignName(java.lang.String campaignName)
           
 void setCategorization(java.lang.String propertyName, boolean isDynamic, boolean isAscending)
          Request that an ordering be imposed on the content spot the next time trigger() is called.
 void setContentResourceCollectionName(java.lang.String resourceCollectionName)
          Save the name of the resource collection used by the rule executed in this content spot.
 void setContentSpotId(java.lang.String contentSpotId)
           
 void setContentSpotName(java.lang.String contentSpotName)
           
 void setContext(RequestContext context)
          Set the PersonalizationContext.
 void setDisplayName(java.lang.String displayName)
           
 void setLimit(java.lang.String s)
          The maximum number of content objects to retrieve.
 void setName(java.lang.String displayName)
          Deprecated. Use setDisplayName, setContentSpotName, or setRuleName instead.
 void setRequest(javax.servlet.http.HttpServletRequest sr)
          Invoked by the jsp/servlet/portlet to give us the servlet request so that we can obtain the RequestContext
 void setRequest(java.lang.Object o)
           
 void setRequest(PznPortletRequestObjectInterface proi)
          Invoked by the personalization application to give us the surrogate servlet request so that we can obtain the RequestContext
 void setRequest(PznRequestObjectInterface roi)
          Invoked by the personalization application to give us the surrogate servlet request so that we can obtain the RequestContext
 void setRuleExit(RuleExit ruleExit)
           
 void setRuleId(java.lang.String ruleId)
           
 void setRuleJSON(java.lang.String ruleJson)
           
 void setRuleMapping(com.ibm.websphere.personalization.campaigns.web.RuleMapping ruleMapping)
           
 void setRuleName(java.lang.String ruleName)
           
 void setShowError(boolean se)
          Used to set the property which governs whether errors should be propagated or consumed.
 void setStartIndex(java.lang.String s)
          The index to start with.
 void setUseCascadingCampaigns(boolean useCascadingCampaigns)
          Sets the useCascadingCampaigns.
 void trigger()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COPYRIGHT

public static final java.lang.String COPYRIGHT
See Also:
Constant Field Values

ruleExit

protected RuleExit ruleExit

additionalQuery

protected Query additionalQuery

defaultRuleExit

protected static RuleExit defaultRuleExit

includeRuntimeResultsInPreview

public static boolean includeRuntimeResultsInPreview

useCascadingCampaigns

public boolean useCascadingCampaigns

scopeId

protected java.lang.String scopeId

CAMPAIGNS_FINDER

protected static final com.ibm.websphere.personalization.campaigns.CampaignsFinder CAMPAIGNS_FINDER

resourceCollectionName

protected java.lang.String resourceCollectionName

categorizationOrder

protected com.ibm.websphere.personalization.rules.PznOrderComparator categorizationOrder

displayName

protected java.lang.String displayName

campaignName

protected java.lang.String campaignName

ruleMappingsList

protected java.util.List ruleMappingsList

ruleMapping

protected com.ibm.websphere.personalization.campaigns.web.RuleMapping ruleMapping

ruleName

protected java.lang.String ruleName

ruleJSON

protected java.lang.String ruleJSON

ruleUuid

protected java.lang.String ruleUuid

contentSpotUuid

protected java.lang.String contentSpotUuid

content

protected java.lang.Object[] content

name

protected java.lang.String name

asOfDate

protected java.lang.String asOfDate

startIndex

protected java.lang.String startIndex

showErrors

protected boolean showErrors

audit

protected boolean audit

limit

protected java.lang.String limit

requestContext

protected RequestContext requestContext

req

protected javax.servlet.http.HttpServletRequest req
deprecated

Constructor Detail

RuleTrigger

public RuleTrigger()
Method Detail

getCampaignName

public java.lang.String getCampaignName()

setCampaignName

protected void setCampaignName(java.lang.String campaignName)

setRuleMapping

public void setRuleMapping(com.ibm.websphere.personalization.campaigns.web.RuleMapping ruleMapping)

getRuleMapping

protected com.ibm.websphere.personalization.campaigns.web.RuleMapping getRuleMapping()

getRuleName

public java.lang.String getRuleName()

setRuleName

public void setRuleName(java.lang.String ruleName)

getRuleJSON

public java.lang.String getRuleJSON()

setRuleJSON

public void setRuleJSON(java.lang.String ruleJson)

getRuleId

public java.lang.String getRuleId()

setRuleId

public void setRuleId(java.lang.String ruleId)

getDisplayName

public java.lang.String getDisplayName()
Should be overriden by sub-classes to provide a name for instances of the RuleTrigger type.

Returns:
a name for this RuleTrigger type

setDisplayName

public void setDisplayName(java.lang.String displayName)

getContentSpotName

public java.lang.String getContentSpotName()

setContentSpotName

public void setContentSpotName(java.lang.String contentSpotName)

setName

public void setName(java.lang.String displayName)
Deprecated. Use setDisplayName, setContentSpotName, or setRuleName instead.

Parameters:
contentSpotName - the name of the content spot represented by this RuleTrigger

getContentSpotId

public java.lang.String getContentSpotId()

setContentSpotId

public void setContentSpotId(java.lang.String contentSpotId)

resetContext

public static void resetContext(RequestContext context)
Removes any information stored by the RuleTrigger on the context.

Parameters:
context -

dateUsed

protected java.lang.String dateUsed()
Determines the date being used. This is either the input as-of date, or is the request date available form the Personalization Context


getAudit

public boolean getAudit()
Used to obtain the property which governs the collection of audit information


getContentResourceCollectionName

public java.lang.String getContentResourceCollectionName()
                                                  throws java.lang.Throwable
Returns the name of the resource collection used by the rule executed in this content spot. It may return null. Not all rules reference a resource collection. Primarily used for select or binding rules.

Returns:
The name of the resource collection referenced by the rule
Throws:
java.lang.Throwable

setContentResourceCollectionName

public void setContentResourceCollectionName(java.lang.String resourceCollectionName)
Save the name of the resource collection used by the rule executed in this content spot. Primarily used for select or binding rules.

Parameters:
resourceCollectionName - The name of the resource collection referenced by the rule

setCategorization

public void setCategorization(java.lang.String propertyName,
                              boolean isDynamic,
                              boolean isAscending)
Request that an ordering be imposed on the content spot the next time trigger() is called. The results that are returned are guaranteed to be sorted by the categorization property.

Parameters:
propertyName - The property to categorize by
isDynamic - Whether this property has a fixed getter like get*() or is only available through the get(String) method
isAscending - The sort is in ascending order if true and in descending order if false

getClassification

public java.lang.String getClassification(int which)
                                   throws java.lang.ArrayIndexOutOfBoundsException
Deprecated. - use getProfile

Provides access to the indexed classification property. Invokes the trigger point if this hasn't been done yet.

Parameters:
which - The index of the applicable classification that is desired.
Returns:
The classification at the position identified by which.
Throws:
java.lang.ArrayIndexOutOfBoundsException

getClassifications

public java.lang.String[] getClassifications()
Deprecated. - Use getProfiles

Returns the full set of applicable classifications in an array. Invokes the trigger point if this hasn't been done yet.

Returns:
Array of applicable classificaitons

getProfile

public java.lang.String getProfile(int which)
                            throws java.lang.Throwable
Provides access to the indexed profile property. Invokes the rule if this hasn't been done yet.

Parameters:
which - The index of the applicable profile that is desired.
Returns:
The profile at the position identified by which.
Throws:
java.lang.Throwable

getProfiles

public java.lang.String[] getProfiles()
                               throws java.lang.Throwable
Returns the full set of applicable profiles in an array. Invokes the rule if this hasn't been done yet.

Returns:
Array of applicable profiles
Throws:
java.lang.Throwable

getContent

public java.lang.Object[] getContent()
Deprecated. 

Returns the full set of content.

Returns:
Array of content objects obtained through the firing of rules associated with the trigger point name. Node that derived classes that need to cast to a particular kind of content, must do so one at a time -- casting the entire array in one go won't work.

getContent

public java.lang.Object getContent(int which)
Deprecated. 

Used to obtain the indexed content object identified by which. Overridden to cast the returned content Object to a particular type.

Parameters:
which - The index of the content object that is desired.
Returns:
The nth content object, where n is determined by which.
Throws:
java.lang.ArrayIndexOutOfBoundsException - thrown when which does not refer to a valid index of content. Typically used by the jsp to know that there are no more content objects to query

getRuleResults

public java.lang.Object[] getRuleResults()
                                  throws java.lang.Throwable
Returns the full set of content.

Returns:
Array of content objects obtained through the firing of rules associated with the trigger point name. Node that derived classes that need to cast to a particular kind of content, must do so one at a time -- casting the entire array in one go won't work.
Throws:
java.lang.Throwable

getRuleResults

public java.lang.Object getRuleResults(int which)
                                throws java.lang.Throwable
Used to obtain the indexed content object identified by which. Overridden to cast the returned content Object to a particular type.

Parameters:
which - The index of the content object that is desired.
Returns:
The nth content object, where n is determined by which.
Throws:
java.lang.Throwable

getPreviewAnchorTag

public java.lang.String getPreviewAnchorTag()
                                     throws java.lang.Throwable
Throws:
java.lang.Throwable

getPreviewAnchorTag

public java.lang.String getPreviewAnchorTag(javax.servlet.http.HttpServletResponse response)
                                     throws java.lang.Throwable
Throws:
java.lang.Throwable

selectRule

protected com.ibm.websphere.personalization.campaigns.web.RuleMapping selectRule(com.ibm.websphere.personalization.campaigns.Campaign[] campaigns,
                                                                                 java.util.List ruleMappings)
This method selects the winning rule. The winning rule is chose randomly from the campaign with the lowest priority. For the winning rule to be consistent for this session, the ruleMappings array list must be the same order of rule mappings each time.


findRule

protected void findRule()

setRuleExit

public void setRuleExit(RuleExit ruleExit)

getShowError

public boolean getShowError()
Used to obtain the property which governs whether errors should be propagated or consumed.


getCampaigns

protected com.ibm.websphere.personalization.campaigns.Campaign[] getCampaigns()
This method returns a prioritized Array of active campaigns for this session. Active campaigns are campaigns which have a state of active and start time <= current time < end time. The results should be sorted by priority. The campaigns with the same priority should be in random order.

Returns:
Array Active campaigns

getScopeId

protected java.lang.String getScopeId()

getCampaign

protected com.ibm.websphere.personalization.campaigns.Campaign getCampaign(com.ibm.websphere.personalization.campaigns.Campaign[] campaigns,
                                                                           java.lang.String campaignName)
Returns:
Campaign from campaigns array which has campaignName and scopeId

getCampaignIndex

protected int getCampaignIndex(com.ibm.websphere.personalization.campaigns.Campaign[] campaigns,
                               java.lang.String campaignName)
Returns:
Index from campaigns array which has campaignName and scopeId

idOfUser

protected java.lang.String idOfUser()
Determines the user being used. Obtains the user id from the user object which the PersonalizationContext holds


isClassifiedAs

public boolean isClassifiedAs(java.lang.String c)
                       throws java.lang.Throwable
Deprecated. 

Returns true if the designated classification is applicable in the business context captured in the named classifier. Invokes the trigger point if this hasn't been done yet.

Parameters:
c - The classification that's being asked about.
Returns:
boolean true if the c is in the set of applicable classifications.
Throws:
java.lang.Throwable

isProfiledAs

public boolean isProfiledAs(java.lang.String profile)
                     throws java.lang.Throwable
Checks if the current user matches the given profile

Parameters:
profile - The profile that's being asked about.
Returns:
boolean true if the profile is in the set of profiles returned
Throws:
java.lang.Throwable

isProfiledAsAll

public boolean isProfiledAsAll(java.lang.String[] profileNames)
                        throws java.lang.Throwable
Checks if the Current user matches all of a list of profiles

Parameters:
profileNames - String[ ] - the names of the profiles to match against
Returns:
boolean true/false if the current user matches all the supplied profile names.
Throws:
java.lang.Throwable

isProfiledAsAny

public boolean isProfiledAsAny(java.lang.String[] profileNames)
                        throws java.lang.Throwable
Checks if the Current user matches any of a list of profiles

Parameters:
profileNames - String[ ] - the names of the profiles to match against
Returns:
boolean true/false if the current user matches any the supplied profile names.
Throws:
java.lang.Throwable

setAsOfDate

public void setAsOfDate(java.lang.String s)
The date to be used in retrieving rules and in evalutating time based conditions. Application controlled.

Parameters:
s - String representing the date to be used when evaluating time-based conditions. Format is YYYY-MM-DD

setAudit

public void setAudit(boolean se)
Deprecated. Audit function is deprecated

Used to set the property which governs the colleciton of audit information


setContext

public void setContext(RequestContext context)
Set the PersonalizationContext.

Parameters:
context - PersonalizationContext

getContext

public RequestContext getContext()
Return the PersonalizationContext.


setLimit

public void setLimit(java.lang.String s)
The maximum number of content objects to retrieve.

Parameters:
s - Maximum number of content objects to retrieve.

setRequest

public void setRequest(PznRequestObjectInterface roi)
Invoked by the personalization application to give us the surrogate servlet request so that we can obtain the RequestContext

Parameters:
roi - com.ibm.websphere.personalization.PznRequestObjectInterface

setRequest

public void setRequest(PznPortletRequestObjectInterface proi)
Invoked by the personalization application to give us the surrogate servlet request so that we can obtain the RequestContext

Parameters:
proi - com.ibm.websphere.personalization.PznPortletRequestObjectInterface

setRequest

public void setRequest(javax.servlet.http.HttpServletRequest sr)
Invoked by the jsp/servlet/portlet to give us the servlet request so that we can obtain the RequestContext

Parameters:
sr - javax.servlet.http.HttpServletRequest

setRequest

public void setRequest(java.lang.Object o)

setShowError

public void setShowError(boolean se)
Used to set the property which governs whether errors should be propagated or consumed.


setStartIndex

public void setStartIndex(java.lang.String s)
The index to start with.


getFirstPageRetrieved

public int getFirstPageRetrieved()

getCachedItems

public int getCachedItems()

getAllItemsCached

public boolean getAllItemsCached()

getMaxAvailableItems

public int getMaxAvailableItems()
                         throws java.lang.Throwable
Throws:
java.lang.Throwable

trigger

public void trigger()
             throws java.lang.Throwable
Throws:
java.lang.Throwable

getContentResourceCollectionName

public static java.lang.String getContentResourceCollectionName(java.lang.String ruleName,
                                                                RequestContext requestContext)
Returns the resource collection referenced by a rule that returns content from the request attribute keyed by the ruleName.

Parameters:
ruleName - The name of the rule that is returning content and references a resource collection.
requestContext - The context where the referenced collection names are stored.
Returns:
Returns the name of the collection referenced by the rule

addContentResourceCollectionName

public static void addContentResourceCollectionName(java.lang.String collectionName,
                                                    java.lang.String ruleName,
                                                    RequestContext requestContext)
. Stores the resource collection referenced by a rule that returns content in the request attribute keyed by the ruleName.

Parameters:
ruleName - The name of the rule that is returning content and references a resource collection.
collectionName - The name of the collection referenced by the rule
requestContext - The context where the referenced collection names are stored.

isUsingCascadingCampaigns

public boolean isUsingCascadingCampaigns()
Returns the useCascadingCampaigns.

Returns:
boolean

setUseCascadingCampaigns

public void setUseCascadingCampaigns(boolean useCascadingCampaigns)
Sets the useCascadingCampaigns.

Parameters:
useCascadingCampaigns - The useCascadingCampaigns to set

getIds

public java.lang.String[] getIds(java.lang.String resourceCollection)
                          throws java.lang.Exception
Deprecated. Warning: this call does not scale.

Throws:
java.lang.Exception

getResource

public Resource getResource(java.lang.String id,
                            java.lang.String resourceCollection)
Deprecated.