Oracle BPM provides us with various components to control the flow of a process such as gateways, timer events, errors, message events, send and receive tasks, loop markers and multi-instance markers. In this article 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 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 the 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".

Gateway1

This will bring up the "BPMN 2.0 Process Wizard" where you are prompted to specify a process name and the service type. In this demo I have selected "Asynchronous Service".

gateway2

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.

gateway3

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).

gateway4

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".

Gateway5

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.

Gateway6

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.

Gateway7

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.

Gateway8

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.

Gateway9

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.

Gateway10

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.

Gateway11

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.

Gateway12

Download sample application: Exclusive Gateway

Inclusive Gateway

The inclusive gateway, just like the exclusive gateway, enables you to split your process into two or more paths. The intrinsic difference between an exclusive gateway and an inclusive gateway is that in an exclusive gateway, the process only continues down one of several paths (if multiple outgoing sequence flows are present) while in an inclusive gateway a process will follow all conditional paths whose expressions are evaluated to true.

Furthermore, in an inclusive gateway a process will only follow the default path only if no conditional expressions evaluate to true. Because of this particular characteristic the notation of an inclusive gateway consist of a split and a merge inclusive gateway.

Gateway13

An inclusive gateway can consist multiple outgoing conditional sequence flows for an inclusive gateway split. However, an inclusive gateway must define a default sequence flow. All conditional expressions that evaluate to true are executed; otherwise the default sequence flow is executed.

At run time, the BPM engine generates a token for each conditional sequence that evaluates to true. If none of the conditional sequence flows evaluate to true then a token gets generated for the default sequence flow. The process will pause and will resume only when all tokens have reached the merge


So let's see how you can use an inclusive gateway in 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".

Gateway14

This will bring up the "BPMN 2.0 Process Wizard" where you are prompted to specify a process name and the service type. In this demo I have selected "Asynchronous Service".

Gateway15

In this demo I will be simulating a Banking Supervision process where a specific department of a Central Bank is responsible for over-sighting it's financial institutions and based on certain decision points various documents are required to be generated.
Gateway16
Therefore I will create two input arguments, NonComplianceLetter and LetterToCentralBank, both of type boolean to denote whether these two type of documents are required to be generated and an output string argument, DocumentsGenerated, to act as a confirmation of which documents where generated.

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 (nonComplianceLetter and letterToCentralBank both of type boolean and documentsGenerated of type string).

Gateway17 

Next I assigned the two input arguments (NonComplianceLetter and LetterToCentralBank) to the process data objects (nonComplianceLetter, letterToCentralBank) by double-clicking on the "Start" activity, going to the "Implementation" tab and selecting "Data Associations".

Gateway18 

Please note that i did the same thing for the "End" activity but this time i have mapped the documentsGenerated process data object to the DocumentsGenerated output argument.

As already mentioned I will be simulating a Banking Supervision process where based on the two boolean input arguments I will generate either both documents (Non-Compliance Letter and Letter to Central Bank), one of the documents (Non-Compliance Letter or Letter to Central Bank) or will not generated any documents at all. And to implement such a scenario I will use an inclusive gateway. Please pay attention how JDeveloper automatically adds an inclusive merge gateway with every inclusive split gateway.

Gateway19 

Furthermore I dropped three script tasks, one between the inclusive split and merge gateway, one above the inclusive gateway and one below the inclusive gateway.

Gateway20 

On each script task, using the "Data Associations" provided some static text to the documentsGenerated process data object to display whether a document is generated (please note that in the second script task I used the concat function to concatenate the string value from the first script task).

Gateway21 

Because I want to have the third script task (Do not Generate Any Letters) marked as the default sequence flow I will delete the default sequence flow from the second script task (Generate Letter to Central Bank) and redefine the sequence flows.

Gateway22 

For the first two conditional outbound sequence flows I have defined an XPath expression to check whether its marching document is selected. For the "Generate Non-Compliance Letter" conditional flow you should have an XPath condition similar to "xp20:matches(string(bpmn:getDataObject('nonComplianceLetter')), '\s*(?i:true|1)\s*')". For the "Generate Letter to Central Bank" conditional outbound sequence flow your XPath should be similar to "xp20:matches(string(bpmn:getDataObject('letterToCentralBank')), '\s*(?i:true|1)\s*')".

Gateway23 

Deploy your process on the integrated Weblogic server and run a test with just one of the documents selected (let's say LetterToCentralBank set to true). The second conditional sequence flow is evaluated to true and if you inspect the "End" message DocumentsGenerated output element you should see that the Letter to Central Bank document has been generated.

Gateway24 

Switch to graphical view to see the execution path highlighted.

Gateway25 

Now test your process without selecting any of the two documents. The process should have followed the default sequence flow. You can confirm this by inspecting the "End" message DocumentsGenerated output element; it should read "No documents generated".

Gateway26 

If you switch to graphical view you will see that the process followed the default outbound sequence flow.

Gateway27 

Download sample application: Inclusive Gateway

Parallel Gateway

The parallel gateway enables you to perform multiple tasks simultaneously, allowing your process to follow several unconditional paths in parallel. When your process token reaches a parallel gateway activity, the parallel gateway will create a token for each outgoing parallel sequence flow. Your process will wait until all tokens have arrived at the parallel gateway merge activity before resuming with the rest of the activities.

You should be very careful with the parallel gateway activity because if one of the tokens that have been created by the parallel gateway doesn't arrive at the parallel gateway merge activity, then your process will freeze.

So let's see how you can use the parallel gateway in a process. Let's assume that you are implementing an order process and that at some point in your process you want to request for quotations from two different suppliers. Once you have received both quotations your process should resume (ideally pick the lowest quotation but I will not be implementing this part).

I created a BPM application with a default BPM project (named both application and project "ParallelGatewayDemo") having an empty composite.

Gateway28

Next I created an asynchronous BPMN process and named it OrderProcess without any arguments.

Gateway29

As already stated above in this demo I will be simulating an order process where I need to send two supplier quotation. So I will use the parallel gateway. Please note how JDeveloper automatically adds a parallel gateway merge activity when you drop a parallel activity on your process.

Gateway30

To simulate a supplier's request for quotation I used a human task component. I created a single human task for both suppliers accepting all the defaults and just changing the human task title for each case.

Gateway31 

For simplicity reasons I changed the human task assignment type from "Lane Participants" to "Names and expressions" and assigned the "weblogic" user as a new user participant.

Gateway32

So let's test our process. Since we didn't specify any arguments you can directly invoke your process. If you open the flow trace you will see that two human tasks have been created and are pending.

Gateway33

Go to the BPM workspace, login using the weblogic user and if you followed my exact steps and you should see two tasks. Approve one of them.

Gateway34

If you go back to the flow trace you should see that there process is waiting for the second human task.

Gateway35

Approve the second human task (from the BPM workspace) and go back to the flow trace; you process should be completed.

Gateway36

Both tokens from both outgoing parallel sequence flow have reached the parallel gateway merge activity which signaled to the process that all parallel activities have been completed.

Download sample application: Parallel Gateway

Complex Gateway

In this fourth article of a five-part series we will go through the complex gateway, a gateway that is similar to an inclusive gateway but at the same time allows you to define a voting pattern to determine whether your instance should continue execution even if not all outgoing sequence flows have been completed.

As with all the other gateways that we've seen till now, the complex gateway involves a split activity which can be either an inclusive gateway (see "Inclusive and Complex" pattern) or an exclusive gateway and a complex merge gateway (see "Parallel and Complex" pattern).

Similar to an inclusive gateway, a process implementing the "Inclusive and Complex" pattern will follow all conditional paths whose expressions are evaluated to true. All conditional expressions that evaluate to true are executed; otherwise the default sequence flow is executed.

Gateway37

A process implementing the "Parallel and Complex" pattern will follow all unconditional paths defined at design time.

Gateway38

What is really interesting with the complex gateway is that it allows you to define a condition on the complex gateway merge activity to control whether the instance should continue even if not all of the complex gateway paths have been completed.

When a process reaches a complex gateway activity it will create a token for each outgoing sequence flow that evaluates to true. You can configure the complex gateway merge activity to continue execution even if not all of the tokens have arrived at the complex gateway merge activity. For example, if you have three parallel sequence flows executed you can configure the complex gateway to continue after two or more tokens have arrived at the merge activity. This is really handy when you want to implement a voting based pattern on process activities.

Let's see how you can use the complex activity in a demo process. I will base my demo on the process I created in part three of my five-part series, Oracle BPM 12c Gateways (Part 3 of 5): Parallel Gateway. Let's assume that you are implementing an order process and that at some point in your process you want to request for quotations from three different suppliers. Your process shouldn't wait for a response from all three suppliers; it is sufficient that you receive quotations from just two suppliers. Once you have received quotations from any two out of the three suppliers your process should continue (ideally pick the lowest quotation but I will not be implementing this part).

So let's start with creating a BPM application with a default BPM project (named both application and project "ComplexGatewayDemo") having an empty composite.

Gateway39

I created next an asynchronous BPMN process and named it OrderProcess (without any arguments).

Gateway40

As already mentioned, in this demo I will be simulating an order process where I need to send three supplier quotations. The process shouldn't wait for all three quotations but just any two. So I will use the complex gateway and please notice how JDeveloper will automatically use the "Inclusive and Complex" pattern, adding an inclusive gateway split activity and a complex gateway merge activity.

Since I want to send a request to all three suppliers I will change the complex gateway pattern to "Parallel and Complex". You can do so by right-clicking on the inclusive split activity and choosing from the context menu "Change Gateway configuration to -> Parallel and Complex".

Gateway41

To simulate a supplier's request for quotation I used a human task component. I created a single human task for all three suppliers accepting all the defaults and just changing the human task title for each case. I created three user tasks on the process creating default sequence flows from the parallel split activity to all three user tasks and from each user task a default activity to the complex gateway merge activity.

Gateway42

You should notice that there is a warning on the complex gateway merge activity that the expression from node is empty. If you go to the implementation details of the complex gateway activity you will see that you can define either a simple or an xpath expression to control, by selecting the "Abort pending flows" check box when the process should continue even if not all tokens have reached the complex gateway.

There is a special predefined variable in a complex gateway called "activationCount" that will return you the number of tokens that have arrived to the merge gateway. You can use this with other custom data objects to form complex expressions.
In my demo, I only care for any two quotations so I will just use the activationCount variable to count the number of tokens that have reached the complex gateway. If two or more tokens have reached the complex gateway merge activity then my process shouldn't wait for the third token but instead continue with its 

execution.

Gateway43

For simplicity reasons I changed the human task assignment type from "Lane Participants" to "Names and expressions" and assigned the "weblogic" user as the new user participant.

Gateway44

Let's test our process. Since we didn't specify any arguments you can directly invoke your process. If you open the flow trace you will see that three human tasks have been created and are pending.

Gateway45

Go to the BPM workspace, login as weblogic (assuming that you have assigned the tasks to weblogic) and you should see three tasks. Submit one of them and go back to the flow trace. You should see that one human task has been completed and the other two are still pending.

Gateway46

Go back to the BPM workspace, submit one of the remaining two tasks and once the task is submitted click on the refresh icon. You should see that the third task get removed from your inbox. This is because of the expression we have defined on the complex gateway (to abort all pending flows if that expression was evaluated to true).

If you go back to the flow trace you should see that all three human tasks have been completed and the process ended.

Gateway47

Even though only two tokens reached the complex gateway, it was enough to signal the process to continue with its execution.

Download sample application: Complex Gateway

Event-based Gateway

My last article on gateways is on the event-based gateway, another type of gateway supported by Oracle BPM 12c to provide divergence in processes.

The event-based gateway is very similar, conceptual wise, to the exclusive gateway in the sense that we can have various outgoing sequence flows but only one branch is followed. The operational difference though is that, as its name suggests, the event-based gateway uses events for defining the branching conditions and decisions rather than data-specific conditions.

Gateway48

An event-based gateway can consist of multiple events; however the first event that occurs will determine the execution path that will be followed.

Using the order process as an example, once an order is received and validated it needs to be processed. Assuming that we have multiple warehouses, the order will be processed by the warehouse that can process all inventory items ordered and responds first. The process will wait until one of the warehouses responds to the request for processing the order. However, the process cannot wait indefinitely.

So let's see how we can implement the above scenario using the event-based gateway.

Let's start with creating the basic BPM application and BPM project (named both application and project "EventBasedGatewayDemo") and selecting "Composite with BPMN Process" in step 3.

Gateway49

This will bring up the "BPMN 2.0 Process Wizard" where you are prompted to specify a process name and the service type. Give your process a name, for example OrderProcess and select "Asynchronous Service" as the service type.

Gateway50

In step 3 of the BPMN 2.0 Process Wizard you are prompted to specify the input and output process arguments. A typical order definition would consist of an order id, a collection of order items, the order total, customer details and bill and ship address details. For simplicity reasons my demo process will only consist of the order id (of type int) and the order total (of type decimal) as input arguments and a status argument of type string as output.

Gateway51

The event-based gateway is composed of the event-based split gateway and two or more target events. These events can be either message catch events, timer catch events or receive tasks. Please note that you cannot mix message catch events and receive tasks within the same event-based gateway. 

Select and drop the "Event Based" gateway on the default sequence flow between the "Start" and "End" activities. You should notice that JDeveloper automatically has added three activities; an event based split gateway activity, a catch message activity and a timer catch activity.

Gateway52

There is an error on the Timer activity because it doesn't have an outgoing default sequence flow. Give the event based gateway split activity and the catch message activity some meaningful names and add a new catch message activity just below the default created catch message activity and define default sequence flows for all activities.

Gateway53

Next set the timer activity to wait for 30 seconds for a reply from the warehouses and define an implementation on the two catch message activities. Again for simplicity and demo reasons I have used the "Define Interface" message exchange type and created only a single argument, order id of type int. The implementation of both catch message activities are exactly the same, the only difference is the operation name.

Gateway54

So we have a process that expects some events to arrive from the two warehouses while its being executed. This means that the main process, which in our case its the order process needs to find a way to correlate these intermediate events with the itself. To do that we need to create a correlation property (an attribute to correlate the main process with the intermediate events) and a correlation key (which defines the properties to use in the correlation which consists of one or more correlation properties).

I will use the order id to correlate the events that will be flowing from the warehouses into the main order process, therefore I have created a correlation property named "orderId" and of type int and a correlation key named "ck_orderId" with the orderId correlation property selected.

Gateway55

We now need to instruct the process and intermediary events to use the orderId correlation property we created. The main process will be responsible for initiating the correlation and matching events that will be coming in from the warehouses with the main process. Therefore on the message start activity select under "Implementation" select "Correlations" and select the orderId correlation property and map it to the orderId process input argument. Ensure that you have selected the "Initiates" option to instruct the process to correlate an instance of the order process with the supplied order id.

Gateway56

The same correlation definitions need to be applied on the two catch message activities. Please ensure that the "Initiates" option is not selected since this will be done upon the instantiation of the process.

Gateway57

Deploy your process and run a test instance using the "start" operation. If you inspect the audit trail you should see that the instance is waiting at the event-based split gateway activity.

Gateway58

Run a new test instance of your order process but this time use one of the warehouse operations (for example, use the "warehouseB" operation). If you inspect the audit trail you should notice that the order is now completed and that the process followed the second branch.

Gateway59

Download sample application: Event-based Gateway


Summery BPM Suite Gateways

There are various ways to control the flow of a process. In this five-part series we’ve focused on gateways and explored the five different gateways offered by Oracle BPM to define the control points within your processes. We have seen how you can deviate from the default process path using a split-merge gateway (parallel gateway, inclusive gateway and complex gateway) and tried to shed some light on the more complex gateway types by demystifying the event-based and complex gateways.

The biggest challenge in modeling and implementing processes is knowledge of the components set. I hope that by the end of this five-part series you have a clearer view on gateways and how to use each gateway to define your control and deviation points within your processes.
 
Antonis Antoniou
Antoniou
Antonis Antoniou is a Technical Director working for Oracle Platinum Partner eProseed. He is a Fusion Middleware Expert, a specialist in the areas of Enterprise 2.0, Business Process Management and Service Oriented Architecture and a certified professional on Oracle Application Grid, Oracle WebCenter Portal, Oracle WebCenter Content, ADF, Oracle BPM and Oracle SOA. Antonis has long-time experience as developer, coach, trainer and architect and has leaded multiple complex projects on Oracle Fusion Middleware across Europe and Middle-East and across various industries (telecom, financial services, public sector). Antonis started his professional career at Deloitte where he worked for 8 years, reaching the level of senior manager in charge of the technology integration service line before joining eProseed. Antonis is an avid technology evangelist and a regular speaker at various Oracle conferences and events.

Receive our SOA Magazine

Events Calendar

loader

Twitter