Exemple : commande de tâche d'élément de campagne pour une cible
Lors de la création d'une cible personnalisée pour une activité marketing, vous pouvez vous reporter à cet exemple lorsque vous développez la commande de tâche de la cible.
Exemple
Ci-dessous figure le code d'implémentation d'un exemple de cible. Dans cet exemple, la cible consiste à déterminer si le client a acheté une assistance de niveau or, argent ou bronze. Ces informations sont stockées dans une table de base de données personnalisée. Le professionnel peut ensuite spécifier des cibles, telles que Le client possède une assistance de niveau or ou Le client possède une assistance de niveau argent.
Cette commande de tâche définit la méthode performExecute, laquelle procède à une évaluation de la cible et renvoie true ou false. De plus, cette commande de tâche définit la méthode validateParameters pour valider les paramètres de la cible 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 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)) {
LOGGER.entering(CLASSNAME, METHOD_NAME);
}
boolean rc = false;
// get the parameters set in the DMELEMENTNVP table
Map parameters = getElementParameters();
// example of getting one of the parameters
String desiredSupportLevel =
(String)parameters.get(PARAM_SUPPORT_LEVEL);
// determine if the customer meets the criteria of the target
String actualSupportLevel =
getSupportLevel(getRegisteredMemberIdForPersonalizationId());
if (desiredSupportLevel.equals(actualSupportLevel)) {
rc = true;
}
// for a target, return true or false as is appropriate
setReturnValue(rc);
if (LoggingHelper.isEntryExitTraceEnabled(LOGGER)) {
LOGGER.exiting(CLASSNAME, METHOD_NAME, rc);
}
}
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(
ApplicationError.TYPE_GENERIC_ERROR,
CustomMarketingMessageKeys._APP_ACTIVITY_LEVEL_OF_SUPPORT_TYPE_IS_MISSING,
null, LOGGER.getResourceBundleName());
validationErrors.add(validateError);
}
if (LoggingHelper.isEntryExitTraceEnabled(LOGGER)) {
LOGGER.exiting(CLASSNAME, METHOD_NAME, validationErrors);
}
return validationErrors;
}
}