Example: campaign element task command for a target

When creating a custom target for a marketing activity, you can refer to this sample when developing the target's task command.


Here is the implementation code for an example target. In this example, the target is to determine if the customer has paid to have gold, silver, or bronze level of support. This information is stored in a custom database table. The business user can then specify targets such as Customer has gold level support or Customer has silver level support.

This task command defines the performExecute method, which performs the evaluation work for the target and returns true or false. In addition this task command defines the validateParameters method to validate the target parameters and return any errors.

package com.mycompany.commerce.marketing.commands.elements;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

import com.ibm.commerce.foundation.common.exception.ApplicationError;
import com.ibm.commerce.foundation.common.util.logging.LoggingHelper;
import com.ibm.commerce.marketing.commands.elements.MarketingCampaignElementTaskCmdImpl;
import com.mycompany.commerce.marketing.logging.CustomMarketingMessageKeys;

public class CustomLevelOfSupportTargetTaskCmdImpl extends MarketingCampaignElementTaskCmdImpl implements CustomLevelOfSupportTargetTaskCmd {
	private final static String PARAM_SUPPORT_LEVEL = "supportLevel";
	private static final Logger LOGGER = LoggingHelper.getLogger(CustomLevelOfSupportTargetTaskCmdImpl.class);
	private final static String CLASSNAME = CustomLevelOfSupportTargetTaskCmdImpl.class.getName();

	public CustomLevelOfSupportTargetTaskCmdImpl() {}
	public void performExecute() {
	final String METHOD_NAME = "performExecute";
		if (LoggingHelper.isEntryExitTraceEnabled(LOGGER)) {
		boolean rc = false;
		// get the parameters set in the DMELEMENTNVP table
	 	Map parameters = getElementParameters();
		// example of getting one of the parameters
	  	String desiredSupportLevel = 

		// determine if the customer meets the criteria of the target
		String actualSupportLevel = 
	   	if (desiredSupportLevel.equals(actualSupportLevel)) {
	   		rc = true;

		// for a target, return true or false as is appropriate
		if (LoggingHelper.isEntryExitTraceEnabled(LOGGER)) {

	public String getSupportLevel(Long memberId) {
	// go to the custom database table
	// and return the support level for the customer
		// TODO…
		return "";

	public List validateParameters(Map elementParameters) {
		final String METHOD_NAME = "validateParameters";
		if (LoggingHelper.isEntryExitTraceEnabled(LOGGER)) {
			LOGGER.entering(CLASSNAME, METHOD_NAME, elementParameters);
		List validationErrors = new ArrayList();
		Object supportLevel = elementParameters.get(PARAM_SUPPORT_LEVEL);
		if (supportLevel == null || supportLevel.toString().length() == 0) {
			ApplicationError validateError = new ApplicationError(
					null, LOGGER.getResourceBundleName());
		if (LoggingHelper.isEntryExitTraceEnabled(LOGGER)) {
			LOGGER.exiting(CLASSNAME, METHOD_NAME, validationErrors);
		return validationErrors;