In this five part series part I will be elaborating the gateway control flow components and how we can use them to define the flow of our process.
Gateways are very similar to a flowchart decision element. Using a gateway you can define the control points within your process by splitting and merging paths. At runtime a gateway will determine based on the control points defined at design time the path that a token will take through a process.
There are five gateway types; Exclusive Gateway (XOR), Inclusive Gateway (OR), Parallel Gateway, Event Based Gateway and Complex Gateway.
Exclusive and Inclusive gateways consist of two outbound sequence flows; a default sequence flow representing the normal path between two objects and a conditional sequence flow to control the process flow based on the evaluation of an expression.
The "Exclusive Gateway" is one of the most commonly used gateways where you can split your process into two or more paths. When a token reaches an exclusive gateway each of the conditional outbound sequence flows is evaluated in the order that you specified during design time when configuring the exclusive gateway and the first conditional flow that is evaluated to true is taken. If none of the conditional outbound sequence flows evaluates to true then then token moves down the default sequence flow. Please note that if you do not specify a default outbound sequence flow on an "Exclusive Gateway" you will get an error at design time and will not be able to compile and deploy your process.
So let's see how you use an "Exclusive Gateway" to control the flow of a process. I have created a new BPM application using the "BPM Application" JDeveloper template and in the "Project SOA Settings" step i have selected "Composite with BPMN Process".
In the arguments step I have created two input arguments, OrderId of type int and OrderAmount of type decimal, and an output argument, Status of type string.
When you click finish it will open the process. Using the structure window I have created three process data objects to store the input arguments I have created above and hold the output argument value (orderId of type int, orderTotal of type decimal and status of type string).
Next I assigned the two input arguments (OrderId and OrderTotal) to the process data objects (orderId, orderTotal) by double-clicking on the "Start" activity, going to the "Implementation" tab and selecting "Data Associations".
Please note that i did the same thing for the "End" activity but this time i have mapped the status process data object to the Status output argument.
Just for demo purpose I came up with a very simple scenario where I will use an exclusive gateway to auto approve an order if the order total is less than 100 and to set the status to pending if the order total is greater than 100. I would like to stress that this is just for demo purposes as I would highly recommend that you use a business rules component to store the order total threshold rather than hard-coding it in the process.
Furthermore I dropped two script tasks, one between the exclusive gateway and the end activity and one just above the first script task and mapped the two status values (auto approved and pending) respectively using the "Data Associations" on each of the script tasks.
When you dropped the exclusive gateway between the start and end activity it automatically joined the exclusive gateway with the end activity using a default outbound sequence flow. Next I have created a conditional outbound sequence flow from the exclusive gateway to the "Set Order Status to Pending" script task and defined an XPath expression to check whether the orderTotal is greater than 100.
I finally provided some labels on the two outbound flow to make them better readable and joined the second script task with the end activity as follows.
Deploy your process on the integrated Weblogic server and run a test using a small order (having an order total of less than 100). The process should follow the default outbound flow and the order should be auto-approved.
Now run another test with an order having an order total of greater than 100. The process should follow the conditional outbound flow and the order should be flagged as pending.
An exclusive gateway can also be used to define a loop to check for conditions and re-executing previous steps. So to define a loop using an exclusive gateway just connect a sequence flow to a previous object.
Download sample application: Exclusive Gateway
very informative
ReplyDeletetechnasir.blogspot.com