Wednesday, July 16, 2008

Business State Machine

Business State Machine How to

Websphere Integration Developer v612

Contact us...

Business State Machine

How to generate a State Machine implementation
How to add a state
How to transition from one state to another state

How to add a variable-State Machine

How to setup the initial state

How to add an operation to a transition

How to add an action to a transition

How to add an Entry element to a State

How to add a condition to a transition

How to add a Visual Snippet - State Machine

How to add a correlation set - State Machine

How to use the business state machine editor to create a business process component (including events, guards, actions and correlation sets)

Related links

Business State Machine Editor example

This is a business state machine editor window with a completed business state machine.

Receive activity

A receive activity is an entry point to a process; it is the point where the process starts or continues.

Using the Business State Machine Editor

Here are some of the functions you can do with the business state machine editor.

How to generate a State Machine implementation
How to add a state
How to transition from one state to another state

How to add a variable-State Machine

How to setup the initial state

How to add an operation to a transition

How to add an action to a transition

How to add an Entry element to a State

How to add a condition to a transition

How to add a Visual Snippet - State Machine

How to add a correlation set - State Machine

How to generate a state machine implementation

Generated state machine implementation

WID generates a basic state machine implementation that you can modify as required.

As you can see, the related partners (Interfaces and Reference) are defined based on the Assembly diagram, the wiring done, and the interfaces/references defined for each component.

This basic state machine implementation was generated by following the steps below.

Assembly Diagram

ProcessOrder interface (ProcessOrder component)

Step 1

Generate State Machine implementation

In the Assembly Diagram editor, right-click the component you want to implement and select Generate Implementation > State Machine.

Step 2
Select the folder where the state machine implementation will be generated and click OK.

How to add a state

Add a state

  1. Right-click the canvas and select Add > State.
  2. Click the mouse where you want to drop the new state.
  3. Rename the state as required.

New state added

A new state (OrderBeingShipped) has been added.

How to add a correlation set - State Machine

Add a correlation set

  1. Click anywhere on an empty area of the state machine editor canvas
  2. Select Properties tab
  3. Select Correlation
  4. Select New button

Create Correlation Property

  1. Enter a name (i.e OrderNumber).
  2. Click Browse button

Select Data Type

  1. Select int data type
  2. Click OK button

Create an Alias

Click New button (next to Aliases)

Select Property Alias for placeOrder input

  1. In the Select a data type box, expand placeOrder input/order and select orderNumber.
  2. Click Add
  3. Click OK.

Create another Correlation property

A correlation property has been added to placeOrder.

Create another correlation property for orderShipped. To do this, click New button.

Select Property Alias for orderShipped input

  1. In the Select a data type box, expand orderShipped input/order and select orderNumber.
  2. Click OK.

Correlation Property set

Correlation Property has been set for placeOrder and orderShipped.

Correlation set has been setup

The orderNumber attribute of the Order business object used as input to either operation is now an alias for the OrderNumber correlation.

How to add an Action to a transition

Variables to define
  1. myOrder type Order
  2. myCustomerID type string

Add an Action

Right-click the transition between WaitingForOrder and CustomerBeingChecked and select Add > Action.

Rename the action to Print info and set variables.

Configure the Action

  1. Select the Action (Print info and set variables)
  2. Select Properties tab
  3. Select Details
  4. Select Visual implementation

Save the project.

How to add a Condition to a transition

Adding Conditions

We will add conditions on the two transitions coming coming from CustomerBeingChecked (GoodCustomer and BadCustomer).

What is a Condition?

When a state (i.e CustomerBeingChecked) has transition choices (i.e it can transition to one state or another state), you must have procedures in place to control which transition to follow.

Otherwise, WID will flag this as an error (This transition will not occur because another transition will always occur) as is the case with the state machine (right column) which currently has no conditions in place.

For example, if it is a good customer, you ship the order (transition to OrderBeingShipped). Else, you reject the order (transition to OrderComplete).

To do this, you must set a condition to guard the transition.

Variables to define isCustomerOK type boolean

Add a Condition for Good Customer

First define a variable (isCustomerOK of type boolean).

Right-click the transition between CustomerBeingChecked and OrderBeingShipped and select Add > Condition.

Rename the condition to GoodCustomer.

Configure the Condition

  1. Select the Condition (GoodCustomer)
  2. Select Properties tab
  3. Select Details
  4. Select Visual implementation
  5. Set visual snippet as shown.
    A condition must return either true (condition is met and transition occurs) or false (transition is blocked).

Save the project.

Notice that an error now points to the un-guarded transition.

In the same manner, put a condition on the unguarded transition (the transition between CustomerBeingChecked and OrderComplete) to fix the new error.

Conditions (Guards) in place

Both transitions are now conditional (guarded).

For example, if isCustomerOK is true, the GoodCustomer transition will be followed.

If false, the BadCustomer transition will be followed.

Note:

The BadCustomer visua snippet inverts the the result of the return.

How to add a Visual Snippet - State Machine

How to add a Visual Snippet

In the state machine editor, do the following:

  1. Click the condition (GoodCustomer).
  2. Click the properties tab
  3. Click Details
  4. Click Visual as the implementation

Drag a variable

Select isCustomerOK and drag/drop it to the visual snippet editor canvas.

Add Return

Right-click on the visual snippet editor canvas and select Add > Return.

Drop Return

Drop Return under the isCustomerOK visual snippet.

Connect Visual Snippets

Snag the link coming out of isCustomerOK and drag it to Return.

Visual Snippet is complete

How to add an operation to a transition

Add an operation

In the State Machine editor, right-click a transition and select Add > Operation.

Note:

An Operation can only be added to a Transition.

Select the interface/operation

  1. From the Interface drop-down listbox, select an Interface (i.e ProcessOrder).
  2. From the Operation drop-down listbox, select an Operation (i.e placeOrder).

An Operation is added

An Operation (i.e placeOrder) is added.

How to setup the initial state

The initial state

The transition from the main state machine's initial state must have an operation. The error icon indicates that an operation is not currently defined for the initial state transition.

Note:

The initial state is the the first state and starting point of any state machine. It is where things begin.

An operation enters the machine, and attempts to initiate a move to the next logical state.

Add an operation

Right-click the transition from the initial state and select Add > Operation.

Select the interface/operation

  1. From the Interface drop-down listbox, select ProcessOrder.
  2. From the Operation drop-down listbox, select placeOrder.

Note:

The ProcessOrder state machine uses the ProcessOrder interface.

Assembly Diagram

ProcessOrder interface (ProcessOrder component)

The Initial State transition has been setup properly

How to transition from one state to another state

Select a "source" state

Right-click the 'source' state (i.e CustomerBeingChecked) and select Add > Transition.

Note:

A transition connects one state to another in a state machine. It transitions execution from one state to the next by recognizing the triggering event (operation), evaluating the conditions necessary for execution to flow through it, and determining what actions can occur should execution be allowed.

Connect the "source" state to a "target" state

Drag and drop the transition from the "source" state (i.e CustomerBeingChecked) to a "target" state (i.e OrderBeingShipped).

A connection has been made

A connection (transition) has been made from CustomerBeingChecked to OrderBeingShipped.

How to add a variable-State Machine

Add a Variable

Click the + in the Variables section.

Set the data type

  1. Rename the default Variable name as required (i.e myOrder).
  2. Select the required data type (i.e Order).
  3. Click OK.

Variable defined

A new variable (myOrder) is defined.

How to add an Entry Element to a State

Add an Entry

Right-click the CustomerBeingChecked state and select Add > Entry.

Rename the default entry name to Check Customer.

Configure the Entry

  1. Select the Entry (Check Customer)
  2. Select Properties tab
  3. Select Details
  4. Select Invoke (implementation)
  5. Select CustomerCheckPartner (Reference)
  6. Select checkCustomer (Operation)
  7. Select Input (parameter)
  8. Select myCustomerID (variables)
  9. Select customerID (Operation input)
  10. click Set

Save the project.

Configure the output

  1. Select Output (parameter)
  2. Select customerOK (Operation output)
  3. Select isCustomerOK (Variables)
  4. Click Set

Save the project.

No comments: