2. Creating an Operation

PROBLEM

A service defines a set of related functions, called Operations that define the specific functions of a Service and the implementation.

SOLUTION

Service functions are specified as Operations, which represent stateless application logic. In addition to a name and description, the operation definition consists of an operation interface and operation resources. The application logic of an operation is implemented using a sequence of Actions, which represent a single thread of execution.

The operation interface defines the formal contract between the operation and the consumers of the operation, which consists of an operation name, inputs, outputs, and exceptions.

Operation resources are the set of resources needed in an operation to implement the desired functionality. Operation resources are not part of the operation interface, and the consumers of the operation don't have any visibility into the operation resources.

HOW IT WORKS

Operation Interface

The operation name is the name that consumers use to refer to the operation; a general guideline is to define Operations using a functional verb and noun expression. This usually is a great starting point for determining the appropriate level of granularity, and the consumers of the Operation more easily understand the specific functionality provided by the Operation.

Inputs are a mechanism for exchanging data with the consumer of the operation, and they define part of the operation contract. When a consumer calls an operation, they must provide all the input variables defined by the operation. Input variables are exactly like operation variables, which means any action steps may access the input variable the same way they access operation variables.

Outputs are another mechanism for exchanging data with the consumer of the operation, and they also define part of the operation contract. When a consumer calls an operation, they must accept all the output variables defined by the operation. Output Variables cannot be manipulated directly by the Operation steps. The output variables are assigned their value by selecting the Assigned To value on the Output sub-tab. Any variable from either the Variables tab or Inputs tab can be assigned to the output variables.

Exceptions defines exceptions that can be exposed by the operation. If any exception occurs and it is not listed in the operation interface, the exception will be ignored.

Operation Resources

The variables defined in an Operation are available to all actions in the operation. These variables are used to store data needed by the Operation. Operations are stateless, so the scope of operation variables is limited to operation invocation. Operation variables aren't maintained across calls.

Operation variables are declared to hold:

An operation constant is a fixed variable whose value is defined at design-time. An operation constant functions like Project constants and Model constants, except the operation constants are only accessible to operation actions. This is a great place to keep constants that are only needed in the operation.

The application logic for an operation is implemented using Actions. The Entry Point Action represents the starting point of the operation. An operation will consist of at least one or more Actions, and the operation must be configured with the Action that should be called first upon invocation of the operation.

Steps for creating an operation:

  1. Right click the on a Service, and select New-->Operation.

  2. From the New Operation Wizard, enter a common name for the operation. The common name is for referencing the operation from other artifacts.

  3. Click Next to configure the Entry Point Action. From here you can specify whether an entry point action should be created to implement the operation. If so, you can also specify the action name (default: Default Action).

  4. When done, click Finish to open the Operation Editor

  5. From the Operation Editor you can add Inputs, Outputs, Variables and Constants to the Operation.

RELATED RECIPES

  1. Creating a Service or Business Facade

  2. Implementing an Operation using Actions and Steps

  3. Using Java Code, Spring Beans and Groovy with Services