public interface UserBehaviorRuleTaskCmd extends TaskCommand
Variable
has a type which is not one of the supported values
(CURRENTDATE, NVP, PARENTCATEGORY, REFERRAL, REFERRALNVP
). In this scenario,
the method getCustomVariableType()
will return the custom defined type.
The desired values specified by the Behavior Rule can be retrieved
from the method getRuleValues
. For the name
parameter
specified in the Variable
, the value from the current URL can be
retrieved with the method getCurrentValue
.comparison
value is not one of the supported values
(=, any, recordAll, containAll, start, end, contain
). In this scenario,
the method getCustomVariableType()
will return null. The desired values
specified by the Behavior Rule can be retrieved
from the method getRuleValues
and the actual value from the current request
can be retrieved from the method getCurrentValue
.getReturnValue
should return the entry from the behavior rule values that matched against the
current request. The complete definition of the Behavior Rule is available
from the other methods in this interface. The custom implementation should be
registered in the CMDREG database table.
For example, there is a command that allows a user to look at a file. We
want to have a behavior rule that detects when a user looks at files
in a particular folder. The behavior rule might look similar to the
following, where a custom Variable
type PARENTFOLDER is defined.
<BehaviorRule command="FileDisplay" action="record" maxSize="MARKETING_numberOfTimes"> <Variable name="fileId" value="MARKETING_folderId" type="PARENTFOLDER"/> </BehaviorRule>A customized implementation of the
UserBehaviorTaskCmd
is provided that can check the
behavior rule
when the FileDisplay URL is called. The code gets the file from the fileId parameter
on the FileDisplay URL, and checks if the file is in one of the folders specified
in the behavior rule. This UserBehaviorTaskCmd
implementation also supports a
custom comparison operator called MyCustomComparisonOperator. This code will get
called for comparing any NVP
or REFERRALNVP
Variable
s
when the behavior rule has
a comparison value of MyCustomComparisonOperator.
insert into cmdreg (STOREENT_ID, INTERFACENAME, CLASSNAME) values (0, 'com.ibm.commerce.marketing.dialog.util.UserBehaviorRuleTaskCmd', 'com.mycompany.commerce.marketing.MyUserBehaviorRuleTaskCmdImpl');
public class MyUserBehaviorRuleTaskCmdImpl extends UserBehaviorRuleTaskCmdImpl implements UserBehaviorRuleTaskCmd { .... public String getReturnValue() { final String METHOD_NAME = "getReturnValue"; String returnValue = null; if (LoggingHelper.isEntryExitTraceEnabled(LOGGER)) { LOGGER.entering(CLASSNAME, METHOD_NAME); } LOGGER.logp(Level.FINE, CLASSNAME, METHOD_NAME, "getCustomVariableType:" + getCustomVariableType()); if (getCustomVariableType() != null) { // called when a custom Variable type is specified if ("PARENTFOLDER".equals(getCustomVariableType())) { // this is the custom variable we have implemented // check if the fileId on the URL is in the one of the folders specified in the rule String fileId = getCurrentValue(); //an alternative way fileId = MarketingUtil.getDataFromTriggerParametersString(getTriggerParameters(), "fileId"); //the parameter you need to check may not be the one specified in the Variable name LOGGER.logp(Level.FINE, CLASSNAME, METHOD_NAME, "fileId:" + fileId); if (fileId != null) { // get the parent folder of the file String parentFolderId = ...... // check the parent folder is one of the folders specified in the rule if (getRuleValues().contains(parentFolderId)) { returnValue = parentFolderId; } } } } else { // called when a custom comparison is specified LOGGER.logp(Level.FINE, CLASSNAME, METHOD_NAME, "getComparison:" + getComparison()); if ("MyCustomComparisonOperator".equals(getComparison())) { String currentValue = getCurrentValue(); for (int i = 0; i < getRuleValues().size(); i++) { String ruleValue = getRuleValues().get(i).toString(); if (....COMPARE currentValue TO ruleValue....)) { returnValue = ruleValue; } } } } if (LoggingHelper.isEntryExitTraceEnabled(LOGGER)) { LOGGER.exiting(CLASSNAME, METHOD_NAME, returnValue); } return returnValue; } }
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
COPYRIGHT
IBM copyright notice field.
|
static java.lang.String |
defaultCommandClassName
Default implementation class for this command.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getReturnValue()
This method gets the value from the rules values that matched.
|
void |
setCaseSensitiveMatch(boolean newCaseSensitiveMatch)
This method sets if the rule is configured to perform a case sensitive match.
|
void |
setComparison(java.lang.String newComparison)
This method sets the comparison method to be used.
|
void |
setCurrentValue(java.lang.String newCurrentValue)
This method sets the value of the parameter in the current request which should be checked
against the values defined in the behavior rule.
|
void |
setCustomVariableType(java.lang.String newCustomVariableType)
This method sets the custom variable type defined.
|
void |
setReferralUrl(java.lang.String newReferralUrl)
This method sets the referral URL associated with the current request.
|
void |
setRuleValues(java.util.List newRuleValues)
This method sets the list of strings which are the values defined in the behavior rule
for which to check for a match against the current request.
|
void |
setTriggerParameters(java.util.Map newTriggerParameters)
This method sets the trigger parameters associated with the current request.
|
void |
setTriggerParameters(java.lang.String newTriggerParameters)
This method sets the trigger parameters associated with the current request.
|
void |
setUserBehaviorRule(UserBehaviorRule newUserBehaviorRule)
This method sets the
UserBehaviorRule business object associated with
the behavior rule being evaluated. |
executeFromCache, getCaller, getEntryInfo, getId, getSharingPolicy, postExecute, preExecute, setCaller, updateCache
getCommandTarget, getCommandTargetName, hasOutputProperties, performExecute, setCommandTarget, setCommandTargetName, setOutputProperties
checkIsAllowed, checkResourcePermission, createCommandExecutionEvent, getAccCheck, getCommandContext, getCommandIfName, getCommandName, getCommandStoreId, getDefaultProperties, getExceptionInvokeParameters, getPostInvokeParameters, getPreInvokeParameters, getResources, getStoreId, getUser, getUserId, performExecute, setAccCheck, setCommandContext, setCommandIfName, setCommandStoreId, setDefaultProperties, validateParameters
static final java.lang.String COPYRIGHT
static final java.lang.String defaultCommandClassName
void setRuleValues(java.util.List newRuleValues)
newRuleValues
- A list of strings.void setCurrentValue(java.lang.String newCurrentValue)
newCurrentValue
- The value of the applicable parameter.void setCaseSensitiveMatch(boolean newCaseSensitiveMatch)
newCaseSensitiveMatch
- The flag if the match should be case sensitive.void setComparison(java.lang.String newComparison)
newComparison
- The comparison method to be used. This can be any custom string
defined in the behavior rule.void setCustomVariableType(java.lang.String newCustomVariableType)
newCustomVariableType
- The custom variable type defined. This can be any custom string
defined in the behavior rule.void setUserBehaviorRule(UserBehaviorRule newUserBehaviorRule)
UserBehaviorRule
business object associated with
the behavior rule being evaluated.newUserBehaviorRule
- A UserBehaviorRule
business object.void setTriggerParameters(java.lang.String newTriggerParameters)
newTriggerParameters
- A string representing the trigger parameters.void setTriggerParameters(java.util.Map newTriggerParameters)
newTriggerParameters
- A map representing the trigger parameters.void setReferralUrl(java.lang.String newReferralUrl)
newReferralUrl
- A string representing the referral URL.java.lang.String getReturnValue()