Adding new business logic to a task command

Suppose there is an existing HCL Commerce task command, called ExistingTaskCmd. Following the HCL Commerce naming conventions, this task command would have an interface class named ExistingTaskCmd and an implementation class named ExistingTaskCmdImpl. Now assume that a business requirement arises and you must add new business logic to this existing command. One portion of the logic must be executed before the existing command logic and another portion must be executed after the existing command logic.

About this task

The first step in adding the new business logic is to create a new implementation class that extends the original implementation class. In this example, you would create a new ModifiedTaskCmdImpl class that extends the ExistingTaskCmdImpl class. The new implementation class should implement the original interface (ExistingTaskCmd).

Within the new command, you override the existing performExecute method and include the new logic before and after calling the super.performExecute method.

The following code snippet demonstrates how to add new business logic to an existing task command:


public class ModifiedTaskCmdImpl extends ExistingTaskCmdImpl 
     implements ExistingTaskCmd {


         /* Insert new business logic that must be 
            executed before the original command.
         */

         // Execute the original command logic.
         super.performExecute();

         /* Insert new business logic that must be 
            executed after the original command.
         */
}

You must also update the CMDREG table to associate the new implementation class with the existing interface. The following SQL statement shows an example update:


update CMDREG
set CLASSNAME='ModifiedTaskCmdImpl' 
where INTERFACENAME='ExistingTaskCmd'