Tuesday, December 23, 2014

Oracle BPM 12c Gateways (Part 4 of 5): 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.

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


"Parallel and Complex" pattern
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.

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

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

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.

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.

 
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.

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.

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.

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.

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

No comments:

Post a Comment