Example: campaign element task command for a trigger (customer event type)
Sample
Here is the task command implementation code for an example trigger. In this example, an external system detects credit fraud. The external system can detect credit card fraud, or credit account fraud. The external system sends a message to the marketing services that one of these occurrences of fraud occurred for a customer. By using this customized trigger, a Marketing Manager would be able to create a Dialog activity to specify how to follow up with the customer in this situation (for example, send a mobile text message or an email, depending on their level of coverage, and then send a follow-up message after a certain time). The eventType parameter can be one of (CreditCard, CreditAccount) to allow different handling, depending on the type of fraud that occurred.
This task command example defines the validateParameters method to validate the trigger 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 CustomFraudDetectedTriggerTaskCmdImpl
extends MarketingCampaignElementTaskCmdImpl
implements CustomFraudDetectedTriggerTaskCmd {
private final static String PARAM_EVENT_TYPE = "eventType";
private final static String PARAM_CREDIT_CARD = "CreditCard";
private final static String PARAM_CREDIT_ACCOUNT = "CreditAccount";
private static final Logger LOGGER = LoggingHelper.getLogger(CustomFraudDetectedTriggerTaskCmdImpl.class);
private final static String CLASSNAME = CustomFraudDetectedTriggerTaskCmdImpl.class.getName();
public CustomFraudDetectedTriggerTaskCmdImpl() {}
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 eventType = elementParameters.get(PARAM_EVENT_TYPE);
if (eventType == null || eventType.toString().length() == 0) {
ApplicationError validateError = new ApplicationError(
ApplicationError.TYPE_GENERIC_ERROR,
CustomMarketingMessageKeys._APP_ACTIVITY_FRAUD_EVENT_TYPE_IS_MISSING,
null, LOGGER.getResourceBundleName());
validationErrors.add(validateError);
} else {
if (PARAM_CREDIT_CARD.equals(eventType.toString()) == false &&
PARAM_CREDIT_ACCOUNT.equals(eventType.toString()) == false) {
ApplicationError validateError = new ApplicationError(
ApplicationError.TYPE_GENERIC_ERROR,
CustomMarketingMessageKeys._APP_ACTIVITY_FRAUD_EVENT_TYPE_IS_INVALID,
null, LOGGER.getResourceBundleName());
validationErrors.add(validateError);
}
}
if (LoggingHelper.isEntryExitTraceEnabled(LOGGER)) {
LOGGER.exiting(CLASSNAME, METHOD_NAME, validationErrors);
}
return validationErrors;
}
}