Chapter 2 Project Design Tutorial : Configure the InitializeAccount Rule Function

Configure the InitializeAccount Rule Function
In this task, you configure a rule function that you will later set to execute at startup. The InitializeAccount rule function sets values for the FraudCriteria scorecard properties. It also creates an instance of the Account concept.
Learning Points
In the InitializeAccount rule function you use an ontology function to create a concept instance.
What is a rule function?  A rule function is a function you write in the BusinessEvents rule language.
How are rule functions created and used?  You write rule functions using the rule editor. You can use rule functions in rules and other rule functions, in event preprocessors, and as startup or shutdown functions for an agent.
What is an ontology function?  An ontology function is automatically created for each concept and event in your project. These are constructor functions. Another type of ontology function enables you to create and schedule a time event.
What other types of functions are there?  BusinessEvents provides a large library of functions. You can also add custom Java functions. See Chapter 4, Creating Custom Functions in TIBCO BusinessEvents Language Reference for details.
Task G Configure the InitializeAccount Rule Function
1.
2.
Open the Rules folder, right-click in the design panel, and select Add Resource > BusinessEvents Workbench > RuleFunction.
3.
Name the rule function InitializeAccounts and click Apply.
4.
In the design panel, double-click InitializeAccounts to open it.
You see the rule function editor.
5.

 
//Intialize scorecard variables
FraudCriteria.debits_percent =.8;
FraudCriteria.interval       = 120*1000; /* 120 seconds */
FraudCriteria.num_txns = 3;

 
Notice that when you type the period after FraudCriteria, a list of its properties pops up so you can select a property.
6.
On the right side of the user interface, click the vertical Ontology tab and expand the list under Ontology Functions. You can make the function area larger to see the list more easily. You see the same folder structure as you used to build the ontology.
7.
8.
Drag the ontology function corresponding to the Account concept onto the design panel. The following signature is provided for you:

 
Concepts.Account.Account(/*extId String */,/*Balance double */,/*Debits double */,/*Status String */,/*AvgMonthlyBalance double */)

 
9.
extID: ActA
Balance: 20000.0
Debits: 0
Status: Normal
AvgMonthlyBalance: 10000.0
Document your code with a comment. Your display should look similar to the following:

 
//Create Account concept instance ActA
Concepts.Account.Account("ActA" /*extId String */,
                         20000.0 /*Balance double */,
                         0 /*Debits double */,
                         "Normal" /*Status String */,
                         10000.0 /*AvgMonthlyBalance double */);

 
10.
Now enter the following. Notice again, that when you type the period after System you can select debugOut from a list. The hash marks, by the way, are just to make the message more visible when printed to the console.

 
System.debugOut(""###############Created account ActA ###############");

 
The completed values look like this in the editor:
11.
Click Apply, then save the project.
Optional Exercise: Create a Concept Instance Using a Standard Function
Another way to create an instance of a concept is to use a standard function called Instance.createInstance(). If you want to learn about this feature, complete this exercise to create a second instance of the Account concept.
1.
Put the cursor on a new line in the rule editor and click the vertical Standard tab (on the right side of the TIBCO Designer window) to view the library of standard functions.
2.
Expand the list so you can see Instance.createInstance().
Note that the function name has a small "m" to the left of the "f" icon. The "m" indicates a mapper function.
3.
Drag the createInstance function to the design panel and type an open parenthesis at the end of the name. A link to the XSLT mapper appears:
Instance.createInstance(<<xslt-template>>
4.
5.
First you’ll select the type of concept you want to create an instance of. In the Entity Path field of the Function tab, browse to and select the concept Account, then click Apply.
6.
Click the Input tab to see the Scope Variables and Function panels. Expand the tree in the Function panel and enter values for ActB. Except for the account ID (@extId), you can use the same values you entered for ActA. Your display looks like this:
You can also use global variables to set initial values at runtime. To use a global variable, you expand the Scope Variables panel and drag the cursor from the variable name to the property or attribute name.
7.
Click Apply then click OK to dismiss the window. Close the parentheses and end the line with a semicolon. The finished line looks like this in the rule editor (with additional colors and formatting):
   Instance.createInstance("/Concepts/Account");
You can click inside the parentheses to view or change the details, as desired.
8.
   //Create Account concept instance ActB using XSLT Mapper
9.

 
System.debugOut("############### Also created account actB");

 
Summary and Next Steps
You have configured a rule function that will initialize an account (optionally two accounts) at runtime. Next you will configure rules that take action on arrival of debits, depending on whether the fraud criteria are met or not.