public interface UserBehaviorRuleTaskCmd extends TaskCommand
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 Variables 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.
|
static final java.lang.String COPYRIGHT
static final java.lang.String defaultCommandClassName
void setRuleValues(java.util.List newRuleValues)
void setCurrentValue(java.lang.String newCurrentValue)
void setCaseSensitiveMatch(boolean newCaseSensitiveMatch)
void setComparison(java.lang.String newComparison)
void setCustomVariableType(java.lang.String newCustomVariableType)
void setUserBehaviorRule(UserBehaviorRule newUserBehaviorRule)
void setTriggerParameters(java.lang.String newTriggerParameters)
void setTriggerParameters(java.util.Map newTriggerParameters)
void setReferralUrl(java.lang.String newReferralUrl)
java.lang.String getReturnValue()