Russian Call Girls in Karol Bagh Aasnvi ā”ļø 8264348440 šš Independent Escort S...
Ā
Oracle business rules
1. Oracle Business Rules
Oracle Business Rules is a high performance and
lightweight business rules product that is part of the
Oracle Fusion Middleware Suite that can be used in
both SOA and BPM suite.
To have a business process more agile and coherent
with the changing demands of Business, Oracle
Business rules is a must for any design. Also it
should act as a central component where all process
rules are located.
With OBR 11g one added advantage of business
rules is that they can be exposed as any other web
service. This makes it an instant hit as it becomes
hot pluggable.
Here in this example blog i would show how to
create a complex rule in JDeveloper and test it out
through multiple ways.
The Scenario
A high school needs a web service implemented as a
rule in Oracle that calculates the grades of students.
2. The service would take some basic candidate
information and an array of subjects/marks that the
candidate has obtained. The rules engine will have to
allocate the candidate Grades on the basis of the
following logic.
Average
Marks
Grade Allotted
<40 FAIL
40-60 FAIR
60-80 GOOD
80-90 VERY GOOD
90-100 OUTSTANDING
For the sake of this demonstration we would use an
XSD definition for CandidateInformation and
CandidateGrade.
<?xml version="1.0" encoding="UTF-
8"?>
<xsd:schema xmlns:xsd="<a
href="http://www.w3.org/2001/XMLSch
ema"">http://www.w3.org/2001/X
MLSchema"</a> xmlns="<a
href="http://www.example.org""
5. ļ· Open JDeveloper and Create a New SOA
Application.
ļ· Name the application as
BusinessRulesApplication and click on Next.
6. ļ· Name the project as BusinessRulesProject and
again click Next. Make sure āSOAā is selected
under āProject Technologiesā
7. ļ· Choose āComposite with Business Ruleā and
click on āFinishā.
ļ· You would see that a window pops out to create
a rule and specify the inputs and output for the
rule.
ļ· Name the rule as āGradeAllocationRuleā and
click on the ā+ā icon to specify the Input and
Output types for the rule. Select
āCandidateInformationā from the
9. ļ· Wait for the wizard to create the rule definition.
Click on the Ruleset at the top and rename it to
āGradeAllocationā.
10. ļ· Click on āBucketsetsā link in the left most panel
and Add a āList of Rangesā.
ļ· Name the bucketset as āmarkRangeā and create
a list of ranges as under.
11. ļ· Click OK to save changes to the bucketset and
click on GradeAllocation ruleset.
ļ· Select āCreate Decision Tableā from the two
options. Remember that we can either create an
āif-then-elseā rule or a decision table. A decision
table is implicitly evaluated as an āof-then-elseā
rule only but gives a better manageability to rule
definitions.
12. ļ· Name the decision function as ādecideGradeā
and check āAdvanced Modeā to be true.
ļ· Click on āInsert Patternā in the workspace
below.
13. ļ· Right Click on the āvariableā block and click on
āSurround withā and click on āPattern Blockā
14. ļ· Click on the auto generated expression and from
the dropdown select āaggregateā
ļ· Now click on variabe and define a variable
named āaverageMarksā, Click on āfunctionsā to
select āaverageā from the dropdown. Click on
āfact typeā to select āSubjectTypeā element as
the fact. Name this as āsubjectTypeā. Click on
āexpressionā now to select
āsubjectType.subjectMarkā as we are
interested in the average marks across all
subjects. The overall construct should look like
below :
15. ļ· Click on āinsert conditionā in the panel below
and then click āedit conditionā to select
āaverageMarksā from the option. Choose the
bucketset āmarksRangeā from the dropdown
āLocal List of Rangesā.
ļ· Click on the ā+ā icon adjacent to the range
dropdown and keep adding a rule for each of the
16. range. Remember you have to add six distinct
rule. Select a distinct value defined in the
bucketset each time. Here is how to define the
rules.
ļ· Now go to the āActionsā panel and click on
āinsert actionā. Select āAssert newā. Double
click on the action and click on
āCandidateGradeTypeā under Facts. Check the
option āParameterizedā for the property
āoverallGradeā
17. ļ· Now click on each of the option box in the Grid
to define a value for the outcome. Since
overallGrade is a String type, assign a grade in
string for each of the condition as under
18. ļ· Save all projects and files in JDeveloper. With
this we are done with the Rules creation part. So
here is a summary of what we did.
o Created a bucketset for a list of mark ranges
and grade type associated with them.
o Created a decision table for a set of rules.
Initialized a variable for āaverageMarksā
and using a pattern block assigned it as an
average of all subject marks.
o Now for each condition for the rule asserted
the outcome for
āCandidateGrade.overallGradeā with the
grade that has to be assigned.
o Pretty simple. Isnāt it?
Testing the Rules
Creating business rules isnāt just enough. There has
to be a mechanism to test them. Remember Oracle
Rules engine is a inference based rules engine i.e
rules are all evaluated at runtime. For more
information on how rules are evaluated refer to
Oracle Business rules architecture. Here I would
show how rules can be tested using three ways.
Testing Rules by Creating a Debug RL function
19. ļ· Click on the āFunctionsā link and add a new
function and name it to āDebugRuleā. Select
boolean under both Return Type and
Bucketset.
ļ· For the body part of the function we would right
an RL construct to initialize
CandidateInformationType (input to the rule)
and pass some dummy values to it.
ļ· Check the screen snap below and create a body
exactly like the one below
20. ļ· Now if you are familiar with any programming
language understanding the above construct
should be like a cakewalk.
ļ· You would now see that the āTestā link for the
function becomes enabled. Click on it to test the
rule output.
21. ļ· Here you go. You can see that the output grade
is āOUTSTANDINGā. Has to be since the
dummy value of marks assigned were 100 and
100. You can now change the marks in the
subjects or add a new subject type to test the rule
again for a different output.
22. ļ· You can create as many Rulesets as you may for
evaluating more complex conditions and add
them to the Decision Functions in the order you
would need their evaluation to come up with
complex business scenarios.
Testing Rules from EM console
ļ· Deploy the BusinessRulesProject to a domain
server extended with soa suite. Boot up the em
console and browse to the project composite.
23. ļ· Click on the āTestā icon for the composite to
launch the EM test wizard for the composite.
ļ· You would see a Tree View for the request
message for the composite wherein you can
input sample values
24. ļ· Fill in any random values for the type
bpelInstance. The only important value would
be the attribute āNCNameā. Make sure you put
the name of your Decision Function there.
ļ· Fill the request wizard with
CandidateInformation as under
25. ļ· Click on Test Web Service button on top left of
the page to test the Rules decision service.
ļ· Expand the CandidateGrade in the Response
tab to see the overallGrade for the student.
ļ· You can click on āLaunch Flow Traceā to view
the execution trace for the Decision Service.
26. ļ· You can see how easily we can test out our
Business rules from the EM console.
Testing Rules from SOAP UI
More than often in real life scenarios we would like
to create some kind of a unit testing suite for out
business rules. Ag you might have already made
note that in SOA suite 11g Business rules are
exposed as standard web services that can be
invoked from anywhere. See the demonstration
below to see how Business rules can be externalized
as web service and invoked through third parties
even.
ļ· Go to the BusinessRulesProject composite in
the EM console.
ļ· Click on the āService Iconā to copy the WSDL
endpoint for the rules service.
27. ļ· Create a SOAPUI project based on this WSDL.
ļ· Fill the mock service request with actual values
28. ļ· Run the test and you should see the outcome
from the Rules decision function.
29. Now you can build a test suite to create mock
requests for various scenarios and assert the
responses