Introduced in Feature Pack 1

Extending the Atom feed Java class to support the new parameter

Create a Java class that extends from the MarketingSpotData Java class. To add the business logic required to support your custom parameter, you must override the buildMarketingTriggerParameters method in the class. The new class must detect the custom parameter in the URL. If the parameter is present, the new class must add the parameter and value to the list of trigger parameters passed to the marketing services.

Before you begin

Review the com.ibm.commerce.marketing.rest.resources.MarketingSpotData class.

Procedure

  1. Open WebSphere Commerce Developer and switch to the Enterprise Explorer view.
  2. Add the Rest project to your build path:
    1. Right-click the WebSphereCommerceServerExtensionsLogic project; then click Properties.
    2. From the navigation pane, click Java Build Path.
    3. Click the Projects tab; then click Add.
    4. Click the Rest project; then click OK.
    5. Click OK to save and close the Properties page.
  3. Create a package for your new class:
    1. Navigate to WebSphereCommerceServerExtensionsLogic > src.
    2. Right-click the src folder; then click New > Package.
    3. In the Name field, type:

      com.your_company_name.commerce.marketing.rest.resources

    4. Click Finish.
  4. In the new package, create a Java class called MarketingSpotDataExt that extends from MarketingSpotData.

    To add logic to support the custom URL parameters, override the buildMarketingTriggerParameters method. See the example at the end of this procedure.

  5. Save the new class file.
  6. Register the new Java class to the RESTful framework for Web service feeds:
    1. Open the properties file at this path:

      WCDE_installdir/workspace/Rest/WebContent/WEB-INF/config/resources-ext.properties

    2. In the properties file, add the fully qualified name of the Java class you created, for example:

      com.mycompany.commerce.marketing.rest.resources.MarketingSpotDataExt

    3. Save and close the file.
    4. Restart the WebSphere Commerce server.

Example

The following is an example Java class created to support a custom loyaltyId parameter:
package com.mycompany.commerce.marketing.rest.resources;

import java.util.Map;
import javax.ws.rs.core.MultivaluedMap;
import com.ibm.commerce.marketing.rest.resources.MarketingSpotData;

public class MarketingSpotDataExt extends MarketingSpotData {

  private static final String PARAM_LOYALTY_ID = "loyaltyId";

    protected String buildMarketingTriggerParameters(Map<String, String> parameters) {

        // Get all parameters from the URI.
        MultivaluedMap<String, String> map = uri.getQueryParameters();

        // Prepare all the additional parameters for the expression.
        String loyaltyIdValue = map.getFirst(PARAM_LOYALTY_ID);

        if (loyaltyIdValue != null && loyaltyIdValue.length() > 0) {
        parameters.put(PARAM_LOYALTY_ID, loyaltyIdValue);
  }

return super.buildMarketingTriggerParameters(parameters);
}
}