Example: campaign element task command for an action
When creating a custom action for a marketing activity, you can refer to this sample when developing the action's task command.
Sample
Here is the task command implementation code for an example action. In this example, the action is to send a message to a back-end system to send a specific hardcopy catalog to the customer using regular mail.
This task command defines the performExecute method, which tells the back-end system to send the catalog to the customer. In addition this task command defines the validateParameters method to validate the action 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 CustomSendCatalogActionTaskCmdImpl extends MarketingCampaignElementTaskCmdImpl implements CustomSendCatalogActionTaskCmd {
private final static String PARAM_CATALOG_NAME = "catalogName";
private static final Logger LOGGER = LoggingHelper.getLogger(CustomSendCatalogActionTaskCmdImpl.class);
private final static String CLASSNAME = CustomSendCatalogActionTaskCmdImpl.class.getName();
public CustomSendCatalogActionTaskCmdImpl() {}
public void performExecute() {
final String METHOD_NAME = "performExecute";
if (LoggingHelper.isEntryExitTraceEnabled(LOGGER)) {
LOGGER.entering(CLASSNAME, METHOD_NAME);
}
// to get the parameters set in the DMELEMENTNVP table
Map parameters = getElementParameters();
// example of getting one of the parameters
String catalogName =
(String)parameters.get(PARAM_CATALOG_NAME);
// Perform the action for the customer.
// Tell the back-end system to send the catalog to the customer.
// This will get the guest or registered member id, and exclude generic users.
Long memberId = getMemberId(true);
// for an action, return true
setReturnValue(true);
if (LoggingHelper.isEntryExitTraceEnabled(LOGGER)) {
LOGGER.exiting(CLASSNAME, METHOD_NAME);
}
}
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 catalogName = elementParameters.get(PARAM_CATALOG_NAME);
if (catalogName == null || catalogName.toString().length() == 0) {
ApplicationError validateError = new ApplicationError(
ApplicationError.TYPE_GENERIC_ERROR,
CustomMarketingMessageKeys._APP_ACTIVITY_SEND_CATALOG_NAME_IS_MISSING,
null, LOGGER.getResourceBundleName());
validationErrors.add(validateError);
}
if (LoggingHelper.isEntryExitTraceEnabled(LOGGER)) {
LOGGER.exiting(CLASSNAME, METHOD_NAME, validationErrors);
}
return validationErrors;
}
}
Returning information to an e-Marketing Spot
If the action is to return information to an e-Marketing Spot, the performExecute method should create an EMarketingSpotDataBean and call the method addEMarketingSpotDataBean. For example, to return a category recommendation:
EMarketingSpotDataBean emsDataBean = new EMarketingSpotDataBean(
EMarketingSpotDataBean.DISPLAY_TYPE_CATEGORY,
categoryId,
getActivity(), getElementId(), getExperimentTestElements());
addEMarketingSpotDataBean(emsDataBean);