Exemple : commande de tâche d'élément de campagne pour une action

Lors de la création d'une action personnalisée pour une activité marketing, vous pouvez vous reporter à cet exemple lorsque vous développez la commande de tâche de l'action.

Exemple

Ci-dessous figure le code d'implémentation de commande de tâche d'un exemple d'action. Dans cet exemple, l'action consiste à envoyer un message à un système dorsal pour qu'il envoie par la poste un catalogue papier spécifique au client.

Cette commande de tâche définit la méthode performExecute, laquelle indique au système dorsal d'envoyer le catalogue au client. De plus, cette commande de tâche définit la méthode validateParameters pour valider les paramètres de l'action et renvoie les erreurs éventuelles.

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

Renvoyer des informations à un emplacement e-Marketing

Si l'action consiste à renvoyer des informations à un emplacement e-Marketing, la méthode performExecute doit créer un objet EMarketingSpotDataBean et appeler la méthode addEMarketingSpotDataBean. Par exemple, pour renvoyer une recommandation de catégorie :

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