com.ibm.commerce.marketing.dialog.util

Interface UserBehaviorRuleTaskCmd

  • All Superinterfaces:
    com.ibm.websphere.command.CacheableCommand, com.ibm.commerce.command.CacheableECCommand, com.ibm.websphere.command.Command, com.ibm.websphere.command.CommandCaller, ECCommand, java.io.Serializable, com.ibm.websphere.command.TargetableCommand, TaskCommand
    All Known Implementing Classes:
    UserBehaviorRuleTaskCmdImpl


    public interface UserBehaviorRuleTaskCmd
    extends TaskCommand
    This interface should be implemented by a customization that wants to have specific checking of a Behavior Rule to see if the current request matches the definition of the rule. The custom implementation will be called in the following situations:
    • If a 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.
    • If the 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.
    If the custom check determines that the rule criteria has been matched, then the method 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 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;
            }
     }
     
    • Field Detail

      • COPYRIGHT

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

        static final java.lang.String defaultCommandClassName
        Default implementation class for this command.
    • Method Detail

      • setRuleValues

        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.
        Parameters:
        newRuleValues - A list of strings.
      • setCurrentValue

        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.
        Parameters:
        newCurrentValue - The value of the applicable parameter.
      • setCaseSensitiveMatch

        void setCaseSensitiveMatch(boolean newCaseSensitiveMatch)
        This method sets if the rule is configured to perform a case sensitive match.
        Parameters:
        newCaseSensitiveMatch - The flag if the match should be case sensitive.
      • setComparison

        void setComparison(java.lang.String newComparison)
        This method sets the comparison method to be used.
        Parameters:
        newComparison - The comparison method to be used. This can be any custom string defined in the behavior rule.
      • setCustomVariableType

        void setCustomVariableType(java.lang.String newCustomVariableType)
        This method sets the custom variable type defined.
        Parameters:
        newCustomVariableType - The custom variable type defined. This can be any custom string defined in the behavior rule.
      • setUserBehaviorRule

        void setUserBehaviorRule(UserBehaviorRule newUserBehaviorRule)
        This method sets the UserBehaviorRule business object associated with the behavior rule being evaluated.
        Parameters:
        newUserBehaviorRule - A UserBehaviorRule business object.
      • setTriggerParameters

        void setTriggerParameters(java.lang.String newTriggerParameters)
        This method sets the trigger parameters associated with the current request. It is preferable to use the Map representation of the trigger parameters than the String representation.
        Parameters:
        newTriggerParameters - A string representing the trigger parameters.
      • setTriggerParameters

        void setTriggerParameters(java.util.Map newTriggerParameters)
        This method sets the trigger parameters associated with the current request. It is preferable to use the Map representation of the trigger parameters than the String representation.
        Parameters:
        newTriggerParameters - A map representing the trigger parameters.
      • setReferralUrl

        void setReferralUrl(java.lang.String newReferralUrl)
        This method sets the referral URL associated with the current request.
        Parameters:
        newReferralUrl - A string representing the referral URL.
      • getReturnValue

        java.lang.String getReturnValue()
        This method gets the value from the rules values that matched. If a match was not made, then null should be returned. If a match is made, then the rule value should be returned, and not the value from the current request that satisfied the rule.
        Returns:
        The value from the rules that satisfied the rule definition.