Samples > Rule Team Server Authoring Extensions > How to Publish a Custom Business Rule Language

This sample shows how to deploy and make available in Rule Team Server a customized language that has been defined in Rule Studio. The sample uses the same customized business rule language as defined in the Rule Studio authoring > custombrl sample.

Key Features

Key features include:

Installing this Sample

To install the sample:

  1. In the Samples Console, locate the teamserver > servercustombrl sample.
  2. Check that the Samples Server is started. For information on how to start and stop the Samples Server, see Stopping and Restarting the Samples Server from the Samples Console.
  3. Execute the repack command to package the compiled code inside the teamserver EAR.
  4. Execute the deploy command to deploy the new EAR.
  5. Wait for the Java EE application to start before continuing. (The server trace displays the message: Finished: deploy).
  6. Execute the set-extensions command to add the new rule type to the extension model in Rule Team Server.

Running this Sample

This sample can only be opened and run in the Samples Console.

To run the sample:

  1. Sign in to Rule Team Server: http://localhost:8080/teamserver/ and enter:
  2. Username: rtsAdmin
    Password: rtsAdmin
  3. Make sure you are in the loanvalidation-rules project.
  4. On the Compose tab, click ExtendedActionRule.
  5. Click OK to create a new Extended Action Rule and go to the Content step.
  6. You can now use the extended features of the new language. The extended features enable you to:
    - add a condition, such as <expr> is kind of <target>
    - write actions starting with declare, such as declare <variable1> to the borrow of the loan report
    - use nested if/then/else statements in the action part
Example 1: the is kind of operator

The is kind of operator enables the creation of expressions that test whether a value is an instance of a certain class:

definitions
  set event to a financial event ;
if 
  event is a kind of cash event 
then
  display "Start processing of a new CASH event: " + the description of event ;
else
  display "Start processing of a new FINANCIAL event: " + the description of event ;
Example 2: the declare statement

The construction declare <variable> supports the creation of local variables in actions. After a declaration, the actions can initialize the variable and refer to it within the same lexical scope:

definitions 
      set 'sourceEvent' to a financial event where the type of this financial event is DENIAL;
      set 'account' to an account where the account ID of sourceEvent is the ID of this account;
then
  declare 'acknowledge event' as a financial event ;
  set 'acknowledge event' to a new financial event with 
      type set to ACKNOWLEDGEMENT , 
      account ID set to the ID of account , 
      parent ID set to the ID of sourceEvent;
  set the date of 'acknowledge event' to the current date ; 
  insert 'acknowledge event' ;
Example 3: nested if/then/else statements

Nested if/then/else statements enable the creation of complex text-based rules without the need to create several separate rules or a decision tree.

definitions
    set 'debitevent' to a cash event
            where the type of this cash event is DEBIT ;
    set 'account' to an account
            where the account ID of debitevent is the ID of this account ;
    set 'amount' to ( - the amount of debitevent ) in the currency of
debitevent converted to USD on the date of debitevent ; set 'balance' to the balance of account in the currency of account
converted to USD on the current date ; if balance is more than amount then display "the following debit event is accepted " + the description of debitevent ; else if amount - balance is more than 10000 then : - report exception about debitevent with text "Debit of more than $10000 over account balance: the
debit event is refused" - retract debitevent - declare 'denial' as a financial event - set 'denial' to a new financial event with type set to DENIAL , account ID set to the ID of account , parent ID set to the ID of debitevent , date set to the date of debitevent - insert denial else : - if amount - balance is more than 2000 then : - report exception about debitevent with text "Debit of more than $2000 over account balance: an
operator should watch all transactions on account" - if the currency of debitevent is not the currency of account then : - report exception about debitevent with text "Debit in foreign currency : double-check with the customer" , else : - report exception about debitevent with text "Debit of less than $2000 over account balance:
the debit event is accepted, but recorded" ;

A colon (:) is used to start the enumeration of actions after the then and else parts, a hyphen (-) is used to start each enumerated action, and a comma (,) is used to avoid any ambiguity in the nested constructs. This is the same syntax as that used in the standard foreach construct of the BAL.

Source Files

This sample is located in <InstallDir>/teamserver/samples/servercustombrl.

The source files are the same as those provided in the authoring > custombrl sample for Rule Studio:

resources/

resources/language/

Highlights

To integrate a new language in Rule Team Server, we must associate that new language (Extended BAL) to a new Business Rule type.

To declare that new Business Rule type we must declare a rule model extension named Extended Action Rule.

We associate the language with this new type using an annotation with its ID set to language and its value set to language/extendedBAL, which is the language identifier:

<class extends="BRLRule" name="ExtendedActionRule">
  <annotation id="language" value="language/extendedBAL"/>
</class>

The Rule Team Server EAR file is repackaged with the additional classes and description files of the new language, and then redeployed.

When Rule Team Server is asked to create an Extended Action Rule, it finds the language description files then builds and displays the corresponding syntactic editor.

Rebuilding this Sample

To rebuild this sample:

  1. Open the Samples Console.
  2. Execute the build command to compile the code.

Related Concepts

Rule Model Extension Schema
Business Rule Language Definition Framework

Related Tasks

Defining a Custom Business Rule Language

Related Samples and Tutorials

How to Generate and Use a Custom Business Rule Language