Tuesday, April 30, 2013

Adding Custom Actions For Scenario : ATG



Adding Custom Actions


You can extend the Scenario Manager to support custom scenario actions. The procedure has the following steps:

1.Add the new action to the Scenario Manager configuration file.

2.Implement the action interface (atg.process.action.Action).

The example in this section adds an action that simply logs some information about its parameters and its evaluation context to the Dynamo information log. Such an action is very handy for debugging purposes, among other things, and it illustrates some of the general principles of custom scenario actions.


Adding the Action to the Scenario Manager Configuration File


The Scenario Manager’s configuration file is located in your config path at /atg/scenario/scenarioManager.xml. You can add a new action to this configuration by creating a file with the same name in your localconfig directory. Below is an example of a scenarioManager.xml file that you would have to define in order to add the test action.

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE process-manager-configuration
        PUBLIC "-//Art Technology Group, Inc.//DTD Process Manager//EN"
        'http://www.atg.com/dtds/processmanager/processmanager_1.0.dtd'>

<process-manager-configuration>

  <action-registry>
    <action>
      <action-name>
        Log Info
      </action-name>
      <action-class>
        test.scenario.LogAction
      </action-class>
      <description>
        prints out information about the action's context and parameters
      </description>
      <action-execution-policy>
        individual
      </action-execution-policy>
      <action-error-response>
        continue
      </action-error-response>
      <action-parameter>
        <action-parameter-name>
          logString
        </action-parameter-name>
        <action-parameter-class>
          java.lang.String
        </action-parameter-class>
        <required>
          true
        </required>
        <description>
          a string value to evaluate and display
        </description>
      </action-parameter>
      <action-parameter>
        <action-parameter-name>
          logInteger
        </action-parameter-name>
        <action-parameter-class>
          java.lang.Integer
        </action-parameter-class>
        <required>
          true
        </required>
        <description>
          an integer value to evaluate and display
        </description>
      </action-parameter>
    </action>
  </action-registry>

</process-manager-configuration>


The action specification contains the action’s name, its class (which must implement the atg.process.action.Action interface), and its description. In addition, you must set two other important properties for your action in these tags:

1.<action-execution-policy>

2.<action-error-response>



Adding Parameters to a Scenario Action


You can also specify any number of action parameters for an action. Each parameter declares a name and the parameter value type. Our test action, for example, has two parameters, one of type String (with name “logString”), and another of type Integer (with name “logInteger”).

To require users to specify a given parameter, include a <required> tag for that parameter and set it to true (see the example above). This tag is optional. If you include it, the ACC displays an error message if users do not specify the parameter.

Users can specify action parameters as either explicit values or expressions when they create scenarios in the ACC. For example, for a parameter of type Integer, they can type an explicit integer value, such as “249,” or select an expression that evaluates to an integer, such as “Person’s age.” When the system executes the action, it evaluates the parameter expressions in the current scenario context; thus the expression “Person’s age” is evaluated to the age in the profile of the person going through the scenario.

For action parameters of type String or String[], you can include the optional tags <action-parameter-repository-name> and <action-parameter-repository-item-type>. Without these tags, users must manually type the repository ID for the item they want when they fill in a parameter. With these tags, however, the ACC displays a dialog box from which users can choose the appropriate item by its display name. The system then passes the repository ID to the action. The following example is from the Give Promotions action in Commerce; it shows how the Promotions action parameter is set up to use these tags:

<action>
.....
<action-parameter>
        <action-parameter-name>
          promotions
        </action-parameter-name>
        <action-parameter-class>
          java.lang.String[]
        </action-parameter-class>
        <action-parameter-repository-name>
          ProductCatalog
        </action-parameter-repository-name>
        <action-parameter-repository-item-type>
          promotion
        </action-parameter-repository-item-type>
        <description>
          the promotions to be added to the profile
        </description>
      </action-parameter>
.....
</action>


Implementing the Action Interface:



1.atg.process.expression.Expression

2.atg.process.action.Action

3.atg.process.action.ActionImpl

4.atg.process.ProcessExecutionContex





No comments:

Popular Posts