| Samples > Rule Team Server Authoring Extensions > How to Publish a Custom Business Rule Language |
How to Publish a Custom Business Rule Language |
PREVIOUS NEXT |
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 include:
To install the sample:
teamserver > servercustombrl sample.
repack command to package the compiled code inside the teamserver EAR.
deploy command to deploy the new EAR.
Finished: deploy).
set-extensions command to add the new rule type to the extension model in Rule Team Server.
This sample can only be opened and run in the Samples Console.
To run the sample:
http://localhost:8080/teamserver/ and enter:
loanvalidation-rules project.
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 ;
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' ;
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.
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:
ExtendedBAL.java - The semantic context extension for the Extended BAL language.
ExtendedBALCodeGeneratorExtender.java and ExtendedBALNodeTranslators.java - The classes that manage the translation to IRL of the Extended BAL language.
resources/
custombrl.brmx - The description of the extension of the model, used to declare the new type of business rule (ExtendedActionRule). This type uses the extended BAL language.
defaultExtension.brdx - The default extension data. This file is unchanged.
resources/language/
extendedBAL.xsd and extendedBAL.properties - The files that describe the new Extended BAL language: They include some description files of the standard BAL plus:
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.
To rebuild this sample:
| Copyright © 1987-2008 ILOG S.A. All rights reserved. Legal terms. Documentation homepage. | PREVIOUS NEXT |