Wednesday, August 20, 2014

Oracle BPM 12c Gateways (Part 1 of 5): Exclusive Gateway

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

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

Monday, August 4, 2014

Using ADF BC Declarative Built-in Rules (Part 5 of 10): Length Validator

The “Length Validator” is another validator that can be defined at either the entity level or the attribute level but pertains to an entity object attribute to compare the number of characters or bytes in an attribute value against a specified length.

For the purpose of this demo I have created a new ADF Fusion Web Application and created the basic business components that I will be using in this demo, an entity object based on the Employees HR table, a view object based on the Employees entity object and a default application module.

Next let’s define a “Length” validator on the Employees entity object to ensure that an employee’s first name is less than 10 characters. So on “Business Rules” tab of the Employees entity object, click on the green plus icon “Create new validator”.  This will open the “Add Validation Rule” editor for defining the validation specifics.

In the “Type” combo select “Length” and select the attribute on which you want to define the length validator. In my demo I have selected “FirstName”. Select the operator (Equals, NotEquals, LessThan, GreaterThan, LessOrEqualTo, GreaterOrEqualTo, Between), the comparison type (either Character or Bytes) and set the length value.

In the "Failure Handling" tab define a failure message and click "OK". In my example I have used a message token expression to construct a dynamic error message, passing to the failure message the employee’s first name.

If you inspect the Employee’s entity source code you will see that JDeveloper added a LengthValidationBean tag to the XML entity definition file.

Before testing our validator please ensure that your application module has the Employees view selected under the “Data Model”.

To test your validator, run the Application module and try to update an employee’s first name, providing a name greater than 10 characters. You should get your custom dynamic error message displayed.

Download sample application: Length Validator