Hi Guys
In this Post we will discuss in depth of BussinessRuleEngine.(Continution to BussinessRule Part 1)
Our current rule developed in BussinessRule Part 1 approves vacations of one day in duration, requiring all other leave requests to be manually approved. Ideally, we would like to approve holidays of varying duration as long as sufficient notice has been given, for example:
This will add a new function with a default name (for example, Function_1) to our list. Click on the function name to select it and update it to startIn. From the drop-down list, select the Return Type of the function, which is int in our case.
Next, we need to specify the arguments we wish to pass to our function. Click on the green plus sign, as shown in the following screenshot, and this will add an argument to our list. Here we can specify the argument name (for example, startDate), and from the drop-down list, the argument Type, which should be XMLGregorianCalendar (when creating XML facts, the JAXB processor maps the type xsd:date to javax.xml.datatype.XMLGregorianCalendar).
The final step is to implement the business logic of our function,
which consists of one or more actions. We enter these actions in the Body
section of the function. The first action we need to create is one that
creates a local variable of type calendar, which holds the current
date.
To do this, click on <insert action> within the Body section of our function. The rule editor will display a drop-down list that lists all the available actions.
Same as above create another Function,Argument for leaveduration as showm below
Now modify the Ruleset to below
Now we are ready to test Function logic for BussinessruleEngine
HappyLearning
By DeepthiReddy
In this Post we will discuss in depth of BussinessRuleEngine.(Continution to BussinessRule Part 1)
Our current rule developed in BussinessRule Part 1 approves vacations of one day in duration, requiring all other leave requests to be manually approved. Ideally, we would like to approve holidays of varying duration as long as sufficient notice has been given, for example:
- Approve vacations of one day in duration with a start date that's two weeks or more in the future
- Approve if for 2-3 days and more than 30 days in the future
- Approve if 5 days or less and more than 60 days in the future
So we will need to write our own logic to calculate these values. Rather than embedding this logic directly in each rule, best practice dictates that we place this logic into a separate function. This not only ensures that we have a single version of the logic to implement but minimizes the size of our rules, thus making them simpler and easier to maintain. For our purposes, we will create the following functions:
- startsIn: Which returns the number of days before the specified start date
- leaveDuration: Which returns the number of days from the start date to the end date
Next, we need to specify the arguments we wish to pass to our function. Click on the green plus sign, as shown in the following screenshot, and this will add an argument to our list. Here we can specify the argument name (for example, startDate), and from the drop-down list, the argument Type, which should be XMLGregorianCalendar (when creating XML facts, the JAXB processor maps the type xsd:date to javax.xml.datatype.XMLGregorianCalendar).
The list of valid
types is made up of the basic types (for example, int, double, char, and
so on), plus the XML facts (excluding object factories) and the Java
Facts (excluding the Rules Extension Method) defined in our rules
dictionary.
To do this, click on <insert action> within the Body section of our function. The rule editor will display a drop-down list that lists all the available actions.
Same as above create another Function,Argument for leaveduration as showm below
Now modify the Ruleset to below
Now we are ready to test Function logic for BussinessruleEngine
HappyLearning
By DeepthiReddy
No comments:
Post a Comment