Mega Menu

Showing posts with label controller command. Show all posts
Showing posts with label controller command. Show all posts

Tuesday, January 15, 2013

ECException & isRetriable() | WCS Commands

All the exceptions that occur in commands are wrapped into ECException and thrown back. This is of two types :
1. ECApplication Exception : Exception due to any application parameters.
2. ECSystem Exception : Exception due to any system issues.

isRetriable() method of a Command

The isRetriable method returns a Boolean value which specifies whether the command can be retried on a transaction rollback exception. The isRetriable method of the new controller command's superclass returns a value of false. You should override this method and return a value of true, if your command can be retried on a transaction rollback exception.






Simple Steps to create a controller Command

Steps:
a. Create an interface (MyNewControllerCmd) extending com.ibm.commerce.command.ControllerCommand.

b. Create the class (MyNewControllerCmdImpl) extending com.ibm.commerce.command.ControllerCommandImpl and implementing the interface MyNewControllerCmd.

c. Create a CMDREG entry.
Eg:
insert into CMDREG (STOREENT_ID, INTERFACENAME, DESCRIPTION, CLASSNAME, TARGET)
values (storeent_ID,'com.ibm.commerce.sample.commands.MyNewControllerCmd', 
'This is a new controller command for the business logic tutorial.', 
'com.ibm.commerce.sample.commands.MyNewControllerCmdImpl','Local');
 
d.  Make the struts entry for the command.
Eg: 
com.ibm.commerce.sample.commands.MyNewControllerCmd" path="/MyNewCmd" type="com.ibm.commerce.struts.BaseAction"/> 
 
e.  Create the access control policy
Eg:

  CommandName="Execute">
  
 
   ResourceBeanClass="com.ibm.commerce.sample.commands.MyNewControllerCmd">
 
  
 
f. Stop server and load access control policies into database using acpload.bat file.
 
g.  Basic methods to be implemented in the implementation class
     i. setRequestProperties () - Method to set the request parameters.
     ii  validateParameters () - Method to perform validations of request parameters.
     iii  performExecute () - Method holds the business logic. 

h. The command can now be executed with the following url
http:///webapp/wcs/stores/servlet/MyNewCmd?storeId=
 
 
 
 
 

Controller Command (vs) Task Command

WCS Commands

Any business logic that should be executed on server is written in the form of commands in WCS.
Basic command types:
1. Controller Command
2. Task Command


Controller Command
Task Command
Holds the complete business logic for an action.

Holds a part of logic involved in an action i.e; to execute a specific task.
Can be executed as an independent request.
Cannot be executed as an independent request but should be invoked from another command.
Needs resource level access control policies to be defined and executed.
Does not need access control as this is executed from a controller command which already has the policies defined.
Can be defined specific to a store.
Can be defined specific to a store.

Can be cached
Can be cached
Example:
UserRegistrationAddCmd is used to Register a user.
Example:
UpdateCredentialsCmd is invoked from UserRegistrationAddCmd to encrypt and update the credentials of the user.