Thursday, September 10, 2009

Business Rules in Oracle Fusion 11g

Today I'm writing my fourth post in Oracle SOA series and will cover Business Rules functionality. I recommend to check my previous post - Business Events and ADF Business Components in Oracle Fusion 11g, sample application I'm describing today is extended version of application from my previous post. What Business Rule means? Simply speaking, its a container that encapsulates specific functionality logic. In Oracle SOA Suite 11g, Business Rule accepts inputs and returns outputs. This means we can understand Business Rule as a black box in general process flow. This black box can be reused and updated at any point of time, without affecting other components in the flow.

You can download and deploy sample application with implemented Business Rule - As I already have mentioned, this sample is extended sample from my previous post. In my previous post I have declared Business Event on ADF BC Entity Object and developed SOA Composite in Oracle SOA Suite 11g with Mediator subscribed that Business Event.

I have updated my previous SalaryManagement application with addition of one more Scope component to BPEL flow - Scope_CheckSalaryChangeRange:

This scope contains Assign activity and Business Rule component:

Ok, let's start from the beginning - what type of Business Rule I want to implement. I want to implement a check to compare the difference between original and updated salary values. I'm getting those values through Business Event raised by ADF Business Components. My Business Rule will compare the difference between salaries with predefined constant value. If the difference will be too big, Business Rule will return true in order to invoke Human Task for approval. Human Task will be implemented in my next post.

First thing I did, I have declared local variable lSalaryChangeApprove in Scope_CheckSalaryChangeRange scope. This variable will be used as input and output parameter for Business Rule:

As a next step, I have created already mentioned Assign activity and initialized there lSalaryChangeApprove variable with false value:

Initializaton is done through a wizard, you can see on the right side there is a local variable:

When initialization and preparation part was done, I have declared Business Rule RequiresSalaryChangeRule in composite.xml by choosing Business Rule Service Component from Resource Palette:

Business Rule is based on XSD schema with two elements - salaryChange and approvalRequired. First is the difference between original and new salaries, second is Business Rule outcome:

I just defined Business Rule in SOA composite, will implement it a little bit later. Now I'm back to BPEL editor, where I will drag and drop Business Rule activity inside BPEL flow. Business Rule definition wizard is opened, where I can choose just few seconds ago defined Business Rule available in Dictionary:

I will define two inputs - first will be the difference in salary and second will get local variable lSalaryChangeApprove value:

First variable value is calculated by subtracting original salary value from new and applying mathematical abs function:

Second variable initialization from scope local value:

Input variables are declared, now let's move to output:

For output, I'm assigning back result of Business Rule to local scope variable:

When inputs/outputs are defined, just press Ok button and Business Rule will be included into BPEL flow:

The last step - actual Business Rule logic implementation. Open newly created Business Rule wizard and at first define global variable - MAX_SALARY_CHANGE. This global variable will contain constant value for salary difference comparison - limit for automatic salary change approval:

If changed salary will not satisfy predefined limit, manual approval process will be required - approvalRequired variable will be assigned with true:

Business Rule is defined, now you can deploy SOA Composite to Oracle SOA Suite 11g. In order to test this Business Rule, I'm using Oracle ADF front-end application from my previous post. Let's open some record, with current salary equal to 7000:

And update it to 15000, in order to violate our salary change Business Rule:

During salary change, ADF BC is raising Business Event. Through Event Delivery Network this event is delivered to subscribed Mediator, from where in BPEL flow Business Rule is triggered and received data is processed to generate output. Full trace log:

If you open to see detail trace for Business Rule, you will find it says that manual approval for this change will be required. And its correct, because difference between salary values is 8000:

Again, if I change salary value from 15000 to 12000:

Its logical that manual approval for salary change will not be required in this case:

In my next post I will describe how to implement Human Task for manual approval.

Spanish Summary:

Este post Andrejus nos explica lo que es un Business Rule (Regla de Negocio) y como lo podemos desarrollar con Jdeveloper. Este post es parte de la coleccion de temas SOA que andrejus ha escrito y que recomienda leerlos antes de revisar este post.


Anonymous said...

I use rulesdc component to implement Business Rule functionality in the Jsp page . can we add or remove a rule from ruleset programmatically ?


Anonymous said...

Hi Andrejus,

Great going. You are proving your talent in other products now after ADF. Best of luck!!!