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.your_company_name.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.yourcompanyname.membergroup.commands;
    
    import com.ibm.commerce.condition.ConditionUtil;
    import com.ibm.commerce.condition.SimpleCondition;
    import com.ibm.commerce.membergroup.commands.CheckUserInMemberGroupCmdImpl;
    
    
    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) {
    				numOfPoints = getDemographics().getField6InEJBType();
    			}
    		}
    		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, OPTCOUNTER) 
      VALUES (0, 'com.ibm.commerce.membergroup.commands.CheckUserInMemberGroupCmd', 
      null, 'IMPL_CLASS_FULL_NAME', null, null, 'Local', null);
      Where IMPL_CLASS_FULL_NAME is the full name of your extended implementation class, for example:
      com.yourcompanyname.membergroup.commands.ExtCheckUserInMemberGroupCmdImpl
    2. Restart the WebSphere Commerce server so that the changes take effect.
  6. Optional: Business users might want the option to view a list of customers in a customer segment that uses your new attribute. Viewing this type of list is not supported in the Management Center Marketing tool; however it is supported in WebSphere Commerce Accelerator.
    1. To support viewing this type of list in WebSphere Commerce Accelerator, you can extend the ListUsersInMemberGroupCmdImpl class. Here is an example:
      /**
       * This class extends the ListUsersInMemberGroupCmdImpl class to implement
       * the query programming logic that lists all of the customers who belong to
       * a specified customer segment with the loyalty points condition.
       */
      
      package com.yourcompanyname.membergroup.commands;
      
      import com.ibm.commerce.condition.SimpleCondition;
      import com.ibm.commerce.membergroup.commands.ListUsersInMemberGroupCmdImpl;
      
      public class ExtListUsersInMemberGroupCmdImpl
      	extends ListUsersInMemberGroupCmdImpl {
      
      	/**
      	 * 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";
      
      	/**
      	 * Default constructor
      	 */
      	public ExtListUsersInMemberGroupCmdImpl() {
      		super();
      	}
      
      	/**
      	 * Override the parent's method to convert the loyalty
      	 * points simple condition to SQL.
      	 * @param condition SimpleCondition
      	 * @return SQL string.
      	 */
      	protected String convertToSQL(SimpleCondition condition) {
      
      		String sql = null;
      
      		if (condition != null) {
      			String variable = condition.getVariable();
      			String operator = condition.getOperator();
      			String value = condition.getValue();
      
      			SimpleCondition.Qualifier[] qualifiers = condition.getQualifiers();
      
      			if (VARIABLE_LOYALTY_POINTS.equals(variable)) {
      				// If the simple condition is for loyalty points,
      				// invoke the specific convertLoyaltyPointsCondition()
      				// method to handle the case.
      				sql = convertLoyaltyPointsCondition(operator, value, qualifiers);
      			} else {
      				// Since we override this convertToSQL() method from
      				// the parent class to take care of the new loyalty
      				// points condition, we should call the parent's
      				// convertToSQL() method to handle all the other
      				// simple conditions.
      				sql = super.convertToSQL(condition);
      			}
      		}
      
      		return sql;
      	}
      
      	/**
      	 * Converts the loyalty points condition to an SQL query.
      	 *
      	 * @param operator - The name of the operator.
      	 * @param value - The data for the value.
      	 * @param qualifiers -  An array of qualifiers.
      	 *
      	 * @return An SQL string.
      	 */
      	protected String convertLoyaltyPointsCondition(
      		String operator,
      		String value,
      		SimpleCondition.Qualifier[] qualifiers) {
      
      			// To simplify this example, assume the loyalty points
      			// value is stored in the table USERDEMO in the
      			// customizable column FIELD6. 
      
      		String sql = "MEMBER.MEMBER_ID = any ("
      			+ "select USERS_ID from USERDEMO where FIELD6"
      			+ operator
      			+ value
      			+ ")";
      
      		return sql;
      	}
      
      }//end-ExtListUsersInMemberGroupCmdImpl
    2. To register the task command in the CMDREG table, run the following SQL statement:
      INSERT INTO cmdreg (STOREENT_ID, INTERFACENAME, DESCRIPTION, CLASSNAME, PROPERTIES, LASTUPDATE, TARGET, OPTCOUNTER) 
      VALUES (0, 'com.ibm.commerce.membergroup.commands.ListUsersInMemberGroupCmd', 
      null, 'IMPL_CLASS_FULL_NAME', null, null, 'Local', null);

      Where IMPL_CLASS_FULL_NAME is the full name of your extended implementation class.

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