Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved


Chapter 17 Rule Templates : Rule Template and Rule Template View Overview

Rule Template and Rule Template View Overview
A rule template is a specialized type of rule, and a rule template view puts a user-friendly interface around the rule template for use in Web Studio.
Rule templates and rule template views enable non-technical Web Studio users to define executable rules (called business rules) within limits defined in the rule template.
This chapter assumes familiarity with rules. For details on creating rules, see Chapter 16, Rules and Rule Functions
The Rule Template Editor
Comparing similar sections of the Rule Template editor and the Rule editor highlights the unique features of rule templates.
Configuration Section
The Configuration section is the same as the Configuration section in a rule. Priority, ranking, and forward chaining features work the same at runtime whether a rule is created using the Rule Editor or the Rule Template Editor.
Declarations and Variables Section
The Declarations and Variables section (declare in the source view) is similar to the Declaration section of a rule. However, in rule templates you can declare primitive types (as you can in rule functions). You can also define initial expressions for primitive types, for example, int j = 50;
Pre-conditions Section
The Pre-conditions section (when in the source view) is similar to the Conditions section of a rule. However, WebStudio users can add additional conditions when defining individual business rules. The Pre-conditions section specifies conditions that must be met in all instances of a rule template before the rule’s actions execute.
Another difference is that the Pre-conditions section can contain non-conditional statements, for example, local variable declarations, to provide more flexible and comprehensive condition checking capabilities. Here is a simple example of such a section:

 
int i=con.prop1;
int j=con2.prop1;
i > j;
i == j;

 
This feature enables complex calculations to be done before the definition of the condition. The Pre-conditions section could also contain conditions that might appear in any rule, such as the following:
con.prop1 > con2.prop1;
Action Context Section
The Action Context section (actionContext in the source view) has a similar purpose to the Actions section of a rule. The Action Context section, however, defines all possible actions that can be taken by a business rule (after all conditions are met). Only the action context statements that the WebStudio user selects and defines as commands in the business rules are actually taken (depending on rule evaluation at runtime).
Defining the superset of all possible actions simplifies and restricts the configuration of business rules in WebStudio.
The actions are not completely defined in the rule template. Completing the definition of an action is a WebStudio user task. If bindings are used (and a view) then in WebStudio, the business rule writer has to enter only the binding values to complete the definition.
Action context statements are of three types: create, modify, and call, plus arbitrary actions, as explained next.
Create Statements
Create statements enable business rule developers to create new concepts or events. Create statement uses fully qualified name for the concepts and events instead of simple name. For example:
create Concepts.Bulk bulk;
In the rule template, that is as far as you go. It’s up to the business rule developer to assign the specific constructor values for the entity type.
Modify Statements
Modify statements enable business rule developers to modify concepts or events. For example:
modify bulk;
Only entities in the scope of the rule can be used. As with create statements, it is up to the business rule developer to determine which properties to change and assign values to those properties.
Call Statements
Call statements enable business rule developers to call rule functions. Call statement uses fully qualified name for the concepts and events instead of simple name. For example:
call RuleFunctions.matchFound matchfound;
The business rule developer assigns the parameters for the rule function.
Arbitrary Actions
Rule template developers can add arbitrary actions as well as create, modify, and call statements. For example:

 
create Concepts.Bulk bulk;
if (mybinding > 10) {
   MyRFs.myRF(otherbinding);
   mycon.prop1 = thirdbinding;
}

 
Bindings Tab
The form editor for rule templates provides an additional tab, the Bindings tab, with two sections that are not found in the Rule editor: Bindings and Views (bindings and views in the source view).
Bindings
A binding is used like a local variable whose value is assigned by WebStudio users when defining business rules.
When defining a rule template, you can use bindings in condition checks and in action statements. For example, suppose you define a binding called dollarAmount. You could then define a condition as follows:
output.UNIT_PRICE > dollarAmount;
At runtime, the UNIT_PRICE is checked against the specific dollar amount defined in the business rule.
Similarly, you could use the binding in an action statement as follows:
RuleFunctions.matchFound(match,null,dollarAmount);
When executed, the engine calls the matchFound rule function and passes the value of dollarAmount as defined in the business rule.
Bindings are primitive types. You can optionally provide an initial value, and the value can be defined using a domain model. If a domain model is specified for a binding, the view defined for a rule template displays the input field for the binding as a drop down box. In the following example, the String binding day is initially assigned to the value of Monday, and it is tied to the domain model RuleFunctions.WeekDays.
String day = "Monday" (RuleFunctions.WeekDays);
Views
In the Views section of the Bindings tab, you select a view that you have already defined. The selected view is used in WebStudio to present the rule template to the users and enable them to define the business rules (that is, executable rules).
If you do not associate a view with a rule template, a builder-based interface is used.
Rule Template Views
A rule template view defines a visual presentation of the rule template to make it easy for the WebStudio user to define a business rule.
The View uses rule template bindings to define an easy-to-use form-like interface where the WebStudio user assigns values to the bindings, for example, threshold values. For example:

 
Require that all applicants have a minimum income of <binding id="minimumIncome"></binding>, a minimum age of <binding id="minimumAge"></binding>, and restrict the credit type to <binding id="creditType"></binding>

 
If the binding is associated with a domain model, the WebStudio interface will display the input widget as a drop down list. Otherwise, an input widget of the appropriate type is displayed, for example, a check-box for a boolean field.

Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved