Creating a task command for the customer segment attribute

Create a task command implementation class for your new customer segment attribute and register the class in the CMDREG table. The task command validates whether a customer belongs to a customer segment specified in a promotion or marketing activity.

About this task

In the Management Center Marketing tool, business users can specify a customer segment as a target for a promotion, a Web or Dialog activity, or an email activity. When the promotion or activity is running, the marketing services call the CheckUserInMemberGroupCmdImpl command to determine whether a customer belongs to the specified customer segment. The command looks up the data that is related to the attributes defined in the customer segment. In the appropriate WebSphere Commerce database tables. For example, the customer's age and gender. The command then performs the evaluation and returns true or false. You must extend the CheckUserInMemberGroupCmdImpl class so that the marketing services can include your new customer segment attribute in the validation process.

Procedure

  1. Open WebSphere Commerce Developer and switch to the Enterprise Explorer view.
  2. Create a package for your task command files:
    1. Navigate to WebSphereCommerceServerExtensionsLogic > src.
    2. Right-click the src folder; then click New > Package.
    3. In the Name field, type a package name.
      For example, com.mycompany.membergroup.commands.
    4. Ensure that WebSphereCommerceServerExtensionsLogic/src is specified in the Source Folder field.
    5. Click Finish.
  3. In the new package, create a task command implementation that extends from CheckUserInMemberGroupCmdImpl class. Give the class a name.
    For example, ExtCheckUserInMemberGroupCmdImpl.

    The following example is a task command implementation for a new customer segment attribute. This attribute allows business users to specify that customers must have a certain number of loyalty points to be in the customer segment.

    /**
     * This class extends the CheckUserInMemberGroupCmdImpl class to implement
     * the evaluation programming logic that handles the loyalty points
     * simple condition.
     */
    
    package com.mycompany.membergroup.commands;
    
    import com.ibm.commerce.condition.ConditionUtil;
    import com.ibm.commerce.condition.SimpleCondition;
    import com.ibm.commerce.membergroup.commands.CheckUserInMemberGroupCmdImpl;
    import com.ibm.commerce.tools.segmentation.SegmentUtil; 
    
    
    public class ExtCheckUserInMemberGroupCmdImpl
    	extends CheckUserInMemberGroupCmdImpl {
    
    	/**
    	 * For this example, the simple condition variable name is defined as
    	 * a string of "loyalty". In practice, this constant should be defined in
    	 *  a separate constant class.
    	 */
    	public static final String VARIABLE_LOYALTY_POINTS = "loyalty";
    
    
    	/**
    	 * Override the parent's method to evaluate the loyalty points
    	 * simple condition.
    	 * @return  <code>true</code> if the condition evaluates to true.
    	 */
    	public boolean evaluate(
    		String variable,
    		String operator,
    		String value,
    		SimpleCondition.Qualifier[] qualifiers) {
    
    		boolean result = false;
    
    		if (VARIABLE_LOYALTY_POINTS.equals(variable)) {
    			// If the simple condition is for loyalty points,
    			// invoke the specific loyalty points evaluation
    			// method to handle the case.
    			result = evaluateLoyaltyPointsCondition(operator, value, qualifiers);
    		} else {
    			// Since we override this evaluate() method from
    			// the parent class to take care of the new loyalty
    			// points condition, call the parent's
    			// evaluate() method to handle all the other simple
    			// conditions.
    			result = super.evaluate(variable, operator, value, qualifiers);
    		}
    		return result;
    	}
    
    
    	/**
    	 * Evaluate the loyalty points condition.
    	 */
    	protected boolean evaluateLoyaltyPointsCondition(
    		String operator,
    		String value,
    		SimpleCondition.Qualifier[] qualifiers) {
    
    		Integer numOfPoints = null;
    		try {
    			// To simplify this example, assume the loyalty points
    			// value is stored in the table USERDEMO in the
    			// customizable column FIELD6. We can use the parent's
    			// class method getDemographics() to retrieve the access
    			// bean that contains the USERDEMO information.
    			if (getDemographics() != null) {
    				// uncomment one of the lines below depending on whether the environment is v7, v8, or v91+
    				   numOfPoints = getDemographics().getField6InEJBType();    // v7 and v8 code
    				// numOfPoints = getDemographics().getField6InEntityType(); // v91+ code code
    				// numOfPoints = getDemographics().getField6InEntityType(); // v91+ code code
    			}
    		}
    		catch (Exception e) {
    			// Handle the exception here.
    		}
    
    		// Call the ConditionUtil helper class's evaluateInteger()
    		// method to evaluate the loyalty points integer value
    		// with the given operator.
    		return ConditionUtil.evaluateInteger
    				(numOfPoints, operator, SegmentUtil.toInteger(value));
    	}
    
    }//end-ExtCheckUserInMemberGroupCmdImpl
  4. Save and close the new implementation class file.
  5. Register the task command in the CMDREG table:
    1. Run the following SQL statement:
      INSERT INTO cmdreg (STOREENT_ID, INTERFACENAME, DESCRIPTION, CLASSNAME, PROPERTIES, LASTUPDATE, TARGET) 
      VALUES (0, 'com.ibm.commerce.membergroup.commands.CheckUserInMemberGroupCmd', 
      null, 'com.mycompany.membergroup.commands.ExtCheckUserInMemberGroupCmdImpl', null, null, 'Local');

      In the SQL, adjust the fully qualified custom implementation class name com.mycompany.membergroup.commands.ExtCheckUserInMemberGroupCmdImpl as required, if necessary.

    2. Restart the WebSphere Commerce server so that the changes take effect.