Ejemplo: mandato de tarea de elemento de campaña para una acción

Al crear una acción personalizada para una actividad de marketing, puede hacer referencia a este ejemplo cuando desarrolle el mandato de la tarea de la acción.

Ejemplo

A continuación se muestra el código de implementación del mandato de tarea para una acción de ejemplo. En este ejemplo, la acción consiste en enviar un mensaje a un sistema de fondo para enviar un catálogo impreso específico al cliente utilizando el correo ordinario.

Este mandato de tarea define el método performExecute, que indica al sistema de fondo que envíe el catálogo al cliente. Además, este mandato de tarea define el método validateParameters para validar los parámetros de acción y devolver posibles errores.

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;
	}
	}	

Devolver información a una zona de e-Marketing

Si la acción consiste en devolver información a una zona de e-Marketing, el método performExecute debería crear un EMarketingSpotDataBean y llamar al método addEMarketingSpotDataBean. Por ejemplo, para devolver una recomendación de categoría:

EMarketingSpotDataBean emsDataBean = new EMarketingSpotDataBean(
EMarketingSpotDataBean.DISPLAY_TYPE_CATEGORY,
categoryId,
getActivity(), getElementId(), getExperimentTestElements());
addEMarketingSpotDataBean(emsDataBean);