Tutorials > Management Center > Track and displaying the most viewed recipes

< Previous | Next >


Create a new Task Command to display the top viewed recipes

In this lesson, you create a new task command to associate with the new action you customized and make the most viewed recipes displayable.

Each trigger, target, and action has an associated task command called a campaign element task command. The task command performs the work associated with the campaign element. The campaign element template definition must specify which task command to use.


Procedure

  1. Create the server-side error message key class and properties file.

    1. Right-click the WebSphereCommerceServerExtensionsLogic project.

    2. Click New > Package, enter com.mycompany.commerce.project.marketing.logging as the package name and click Finish.

    3. Right-click the com.mycompany.commerce.project.marketing.logging package and select Import. Expand General and select File system.

    4. Click Next, then click Browse and navigate to RecipeTopBrowsedSource\WebSphereCommerceServerExtensionsLogic\src\com\ mycompany\commerce\project\marketing\logging. Select the RecipeTopViewedMessageKeys.java file. Click Finish to import the files.

    5. Right-click the WebSphereCommerceServerExtensionsLogic project.

    6. Click New > Package, enter com.mycompany.commerce.project.marketing.logging.properties as the package name and click Finish.

    7. Right-click the com.mycompany.commerce.project.marketing.logging.properties package and select Import. Expand General and select File system.

    8. Click Next, then click Browse and navigate to RecipeTopBrowsedSource\WebSphereCommerceServerExtensionsLogic\src\com\ mycompany\commerce\project\marketing\logging\properties. Select the WcRecipeTopViewedMessages.properties file. Click Finish to import the files.

  2. Create the Recipe Ranking display task command.

    1. In the Enterprise Explorer view, expand WebSphereCommerceServerExtensionsLogic > src.

    2. Right-click the com.mycompany.commerce.project.marketing package and select Import. Expand General and select File system.

    3. Click Next, then click Browse and navigate to RecipeTopBrowsedSource\WebSphereCommerceServerExtensionsLogic\src\com\mycompany\commerce\project\marketing, where RecipeTopBrowsedSource is the location where you extracted the tutorial sample source code. Select the DisplayTopViewedRecipesActionTaskCmd.java and DisplayTopViewedRecipesActionTaskCmdImpl.java files. Click Finish to import the files.

      There are some errors in the DisplayTopViewedRecipesActionTaskCmdImpl.java class.

      To resolve these errors:

      1. Press Ctrl+Shift+O to import related packages.

      2. Import the Project-Client and Project-DataObjects project from the Java project build path:

        1. Right-click WebSphereCommerceServerExtensionsLogic and select Properties.

        2. Click Java Build Path from the left panel.

        3. Click the Projects tab from the right panel.

        4. Click Add, then select the Project-Client and Project-DataObjects projects in the new window. Click OK to close the window.

        5. Press Ctrl+Shift+O to import related packages.

        6. If the errors remain, restart WebSphere Commerce Developer.

  3. Open DisplayTopViewedRecipesActionTaskCmd.java. The following sample code shows the task command:

    package com.mycompany.commerce.project.marketing; 
    import com.ibm.commerce.marketing.commands.elements.DisplayProductRankingActionTaskCmd; 
    public interface DisplayTopViewedRecipesActionTaskCmd extends DisplayProductRankingActionTaskCmd{ 
    String defaultCommandClassName = "com.mycompany.commerce.project.marketing.DisplayTopViewedRecipesActionTaskCmdImpl"; 
    } 
    

    A campaign element task command must implement the MarketingCampaignElementTaskCmd interface. Displaying recipes is similar to displaying products, therefore the interface and implementation are extended for displaying products. In the interface, the default command class name is overridden to point to the new implementation, DisplayTopViewedRecipesActionTaskCmdImpl. The new implementation extends the product implementation.

  4. Open DisplayTopViewedRecipesActionTaskCmdImpl.Java. The following sample code shows the task command implemented:

    package com.mycompany.commerce.project.marketing; 
    
    import java.util.Iterator; 
    import java.util.List; 
    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.DisplayProductRankingActionTaskCmdImpl; 
    import com.ibm.commerce.marketing.facade.server.entity.datatypes.Dmrankingitem; 
    import com.ibm.commerce.marketing.internal.runtime.persistence.TriggerHandlerPersistenceManager; 
    import com.ibm.commerce.marketing.runtime.engine.Activity; 
    import com.ibm.commerce.marketing.runtime.util.EMarketingSpotDataBean; 
    import com.mycompany.commerce.project.facade.ProjectFacadeConstants; 
    import com.mycompany.commerce.project.facade.client.ProjectFacadeClient; 
    import com.mycompany.commerce.project.facade.datatypes.ProjectCollectionType; 
    import com.mycompany.commerce.project.facade.datatypes.ShowProjectCollectionType; 
    import com.mycompany.commerce.project.marketing.logging.RecipeTopViewedMessageKeys; 
    import com.mycompany.commerce.project.facade.ProjectFacadeConstants; 
    import com.mycompany.commerce.project.facade.client.ProjectFacadeClient; 
    import com.mycompany.commerce.project.facade.datatypes.ProjectCollectionType; 
    import com.mycompany.commerce.project.facade.datatypes.ShowProjectCollectionType;
    
    public class DisplayTopViewedRecipesActionTaskCmdImpl extends 
    DisplayProductRankingActionTaskCmdImpl implements 
    DisplayTopViewedRecipesActionTaskCmd { 
    
    private static final Logger LOGGER = LoggingHelper 
    .getLogger(DisplayTopViewedRecipesActionTaskCmdImpl.class); 
    private final static String CLASSNAME = DisplayTopViewedRecipesActionTaskCmdImpl.class.getName(); 
    private ProjectFacadeClient projectServiceClient = null; 
    
    public DisplayTopViewedRecipesActionTaskCmdImpl() { 
    super(); 
    
    // construct the facade client 
    projectServiceClient = new ProjectFacadeClient(); 
    } 
    
    @Override 
    public void validateCategory(String categoryId, List validationErrors) { 
    
    final String METHOD_NAME = "validateCategory"; 
    if (LoggingHelper.isEntryExitTraceEnabled(LOGGER)) { 
    LOGGER.entering(CLASSNAME, METHOD_NAME, categoryId); 
    } 
    
    boolean flag = true; 
    List proCollectionsList = null; 
    
    try { 
    ShowProjectCollectionType showProjectCollection = projectServiceClient 
    .getProjectCollectionAll(ProjectFacadeConstants.ACCESS_PROFILE_STORE_DETAILS_INFORMATION); 
    proCollectionsList = showProjectCollection.getDataArea().getProjectCollection(); 
    } catch (Exception e) { 
    e.printStackTrace(); 
    } 
    if (proCollectionsList != null) { 
    for (Iterator iterator = proCollectionsList.iterator(); iterator.hasNext();) { 
    ProjectCollectionType proCollection = (ProjectCollectionType) iterator 
    .next(); 
    if (categoryId.equals(proCollection 
    .getProjectCollectionIdentifier().getUniqueID())) { 
    flag = false; 
    } 
    
    } 
    } 
    if (flag) { 
    ApplicationError validateError = new ApplicationError( 
    ApplicationError.TYPE_GENERIC_ERROR, 
    RecipeTopViewedMessageKeys._APP_ELEMENT_RECIPE_COLLECTION_SPECIFIED_NOT_FOUND, 
    null, LOGGER.getResourceBundleName()); 
    validationErrors.add(validateError); 
    } 
    if (LoggingHelper.isEntryExitTraceEnabled(LOGGER)) { 
    LOGGER.exiting(CLASSNAME, METHOD_NAME, validationErrors); 
    } 
    } 
    
    public void populateRankingList(Integer elementId, String groupId) { 
    Activity activity = getActivity(); 
    try { 
    List dmRankingItemList = TriggerHandlerPersistenceManager 
    .findRankingItemListByElementIdAndGroupId(elementId 
    .toString(), groupId); 
    if (dmRankingItemList != null) { 
    //"businessObjectType" is identification when ScrollingRecipeESpot.jsp retrieve the 
    //ranking data from EMarketingSpotDataBean on storefront 
    String businessObjectType = "Recipe"; 
    for (int i = 0; i
    < dmRankingItemList.size(); ++i) { 
    Dmrankingitem rankingItem = (Dmrankingitem) dmRankingItemList 
    .get(i); 
    EMarketingSpotDataBean emsDataBean = new EMarketingSpotDataBean( 
    businessObjectType, Long.toString(rankingItem 
    .getObject_id()), activity, elementId, 
    getExperimentTestElements()); 
    emsDataBean.setNVP("amount", rankingItem.getAmount() 
    .toString()); 
    addEMarketingSpotDataBean(emsDataBean); 
    } 
    } 
    } catch (Exception e) { 
    e.printStackTrace(); 
    } 
    } 
    } 
    

    • The validateCategory(String categoryId, List validationErrors) method validates whether the recipe collection belongs to the recipe collection table when the marketing activity is activated.

    • The populateRankingList(Integer elementId, String groupId) method populates the list of most viewed recipes to be returned by the e-marketing spot associated with this activity. The data is retrieved from the DMRANKINGITEM database table and added to the EMarketingSpotDataBean for displaying on the storefront.


Related concepts

Campaign element task commands

Rank list framework for marketing actions


Related tasks

Create the campaign element task command

< Previous | Next >


+

Search Tips   |   Advanced Search