August 17, 2023

tBRMS – Docs for ESB 5.x

tBRMS

tBRMS_icon32_white.png

Warning

This component will be available in the Palette of
the studio on the condition that you have subscribed to the relevant edition of
Talend Studio.

tBRMS properties

Component family

Processing

 

Function

tBRMS retrieves business rules
from a Drools Guvnor repository and applies them to a Job.

Purpose

tBRMS applies Drools business
rules to an incoming flow and writes the output data to an XML
file.

Basic settings

Property type

Either Built-in or
Repository
.

 

 

Built-in: No property data stored
centrally.

 

 

Repository: Select the repository
file where properties are stored. The fields that follow are
completed automatically using the fetched data.

 

Schema and Edit Schema

A schema is a row description, it defines the number of fields that will be processed
and passed on to the next component. The schema is either Built-in or stored remotely in the
Repository.

Click Edit schema to make changes to the schema. If the
current schema is of the Repository type, three options are
available:

  • View schema: choose this option to view the
    schema only.

  • Change to built-in property: choose this option
    to change the schema to Built-in for local
    changes.

  • Update repository connection: choose this option to change
    the schema stored in the repository and decide whether to propagate the changes to
    all the Jobs upon completion. If you just want to propagate the changes to the
    current Job, you can select No upon completion and
    choose this schema metadata again in the [Repository
    Content]
    window.

 

 

Built-in: You create and store
the schema locally for only the current component. Related topic:
see Talend Studio User
Guide
.

 

 

Repository: The schema already
exists and is stored in the Repository, hence can be reused in
various projects and Job flowcharts. Related topic: see
Talend Studio User
Guide
.

 

XML Field

Select the XML field for the data to be written to the output
file.

 

Guvnor URL

The Guvnor repository URL.

  Username and
Password

Type in the authentication information used to connect to the
Talend Administration Center that
incorporates the Drools Guvnor of interest.

To enter the password, click the […] button next to the
password field, and then in the pop-up dialog box enter the password between double quotes
and click OK to save the settings.

  TAC URL

Type in the name of the Talend Administration Center that incorporates the Drools
Guvnor of interest.

For example, when the URL of the Talend Administration Center to be used is http://localhost:8080/tac500, then
enter tac500.

 

Module List

Click […] to open the [Deploy Jar] dialog box. Then click
[…] to open the [Select Jarfile] dialog box, and select
the Jar file which contains the business rule to be applied.

Note

For the time being, Talend does not support declaring a
fact model from Drools Guvnor integrated within
Talend Administration Center. You can define a fact model
only by uploading a JAR file containing the classes used by your
application and rules.

 

Guvnor Package

After the desired Jar file is selected, this field will be
populated automatically with the end part of the path to the
URL for binary package, as
indicated in the Information and important
URLs
view of the Drools Guvnor website, when you
select a particular package, for example, “/package/org.talend.bank/LATEST”.

 

Class Name

After the desired Jar file is selected, this field will be
populated automatically with the name of the class in which the
business rule is stored in a Jar file.

  Drools flow ID
(optional)

A Drools flow describes the order in which a series of business
rules are executed. Its flow ID is defined manually when you are
creating the Drools flow.

When you need to call a specific Drools flow via tBRMS to use the execution order it
defines, enter the corresponding flow ID in this field.

For more information about Drools flow, see the relevant Drools
manuals.

Advanced Settings

Configure XML Tree

Click […] to map the source
schema to the XML output schema.

 

Group by

Use the tool bar to modify the column order.

 

Advanced separator

Select this check box to modify the separators used for
numbers.

 

Encoding

Select the encoding type from the list or select Custom and define it manually. This field
is compulsory for DB data handling.

 

tStatCatcher Statistics

Select this check box to collect the log data at the component
level.

Global Variables

ERROR_MESSAGE: the error message generated by the
component when an error occurs. This is an After variable and it returns a string. This
variable functions only if the Die on error check box is
cleared, if the component has this check box.

NB_LINE: the number of rows read by an input component or
transferred to an output component. This is an After variable and it returns an
integer.

A Flow variable functions during the execution of a component while an After variable
functions after the execution of the component.

To fill up a field or expression with a variable, press Ctrl +
Space
to access the variable list and choose the variable to use from it.

For further information about variables, see Talend Studio
User Guide.

Usage

This component handles data flows. Therefore it requires input and
output components.

Limitation

n/a

Scenario: Applying business rules to an input flow to filter relevant data

This scenario describes a five component Job in which tBRMS applies Drools Guvnor business rules to an input flow, in order
that relevant data can be retrieved in the output. In this case, rules are applied to
input data concerning candidates applying for a loan. The output will show whether the
candidates qualify or not.

tBRMS_Components.png

Prerequisite: Make sure that the business rules have
already been imported into Drools Guvnor.

In this example, the rules from the file repository_export.xml are imported. For more information about the file
and how to import rules into Drools Guvnor from an XML file, see https://help.talend.com/display/KB/How+to+import+rules+into+Drools+Guvnor+from+an+xml+file.

Dropping and linking the components

To do this, proceed as follows:

  1. Drop the following components from the Palette onto the design workspace: tFixedFlowInput, tMap,
    tBRMS, tExtractXMLField, tLogRow.

  2. Link tFixedFlowInput to tMap using a Row >
    Main
    connection. Rename the link as loanAsk to better identify its function.

  3. Link tMap to tBRMS using a Row > *New Output*
    (Main)
    connection.

  4. Link tBRMS to tExtractXMLField using a Row > Main connection
    and then use another Row > Main
    connection to connect tExtractXMLField to
    tLogRow.

Configuring the input flow

  1. Double-click tFixedFlowInput to open its
    Basic settings view:

    tFileInputExcel_BasicSettings.png
  2. Click Edit schema to define the structure
    of the source data. In this example, five columns are defined for the input
    information of candidates.

    components-use_case_tbrms_tfixedflowinput_schema.png
  3. Click OK to validate your changes and
    close the dialog box.

  4. Select Use Inline Content(delimited file)
    in the Mode area.

  5. Change the settings in the Row Separator
    and Field Separator fields as needed. In
    this example, enter ” “ in the Field Separator field.

  6. In the Content area, enter the following
    data which represents the information of ten
    candidates:

Configuring the tMap component

  1. Double-click tMap to open its Map Editor.

    components-use_case_tbrms_tmap.png
  2. In the lower right part of the map editor, click the plus button to add
    eight columns: age, annualRevenue, loanDeposit, loanAmount,
    numberOfYears, loanInterest, monthlyPayment, rejected.

    Those columns defined will appear in the synonyms table on the right side
    of the map editor. In this example, the table is row1.

  3. In the upper left part of the map editor (input flow), select the
    age and annualRevenue columns and drop them respectively to the
    age and annualRevenue columns in the upper right part of the map
    editor (output flow).

    Alternatively, click Auto map! to map the
    columns with the same name automatically.

  4. In the row1 table, click the Expression column in the loanDeposit row to locate the cursor, and then click the
    three-dot […] button to open the
    [Expression Builder] dialog box.

    Enter the following expression to calculate the loan deposit:

    components-use_case_tbrms_expression_builder.png

    Click OK to close the [Expression Builder] dialog box.

    Now the downPayment and totalAmount fields from the incoming data flow
    are concatenated to the output column: loanDeposit.

  5. Click the Expression column in the
    loanAmount row to locate the
    cursor.

    Enter the following expression to calculate the amount of
    loan:

  6. Click the Expression column in the
    numberOfYears row to locate the
    cursor.

    Enter loanAsk.duration to concatenate
    the duration row of the input flow to the
    numberOfYears row in the output
    column.

  7. Enter 0.0 in the Expression column of the loanInterest and monthlyPayment rows respectively.

  8. Enter false in the Expression column of the rejected row.

  9. Click OK to close the map editor.

Configuring the tBRMS component

To do this, perform the following operations:

Basic settings of tBRMS

  1. Click tBRMS to open its Basic settings view.

    tbrms-basic_settings.png
  2. Click […] next to Edit schema to open the schema editor.

    The input schema to the left is automatically retrieved from tMap.

    tBRMS_Schemas.png
  3. In the output area to the right, click [+] to add a new column which will serve to write the output
    data to an XML file. Enter a name for the column and define the Type as String.

    Click OK to validate your changes and
    close the dialog box.

  4. Next to XML Field, select the name of the
    XML column you entered in the output schema.

  5. Enter the Guvnor URL in the corresponding
    field.

  6. Type in the user name and the password used to connect to the desired TAC
    .

    Enter Talend Administration Center address in the TAC URL field.

    When Drools Guvnor is installed in the same web server as Talend Administration Center, you can use the name of
    Talend Administration Center application instead of the
    full URL.

  7. Next to the Module List field, click
    […] to open the [Deploy Jar] dialog box. In this dialog box, the URL, Username,
    Password and URL
    of TAC
    fields are already filled with the corresponding
    information you entered in the earlier steps.

    tBRMS_DeployJar.png
  8. Click […] to browse the Jar files in
    the [Select Jarfile] dialog box.

    BRMS_Select_Jarfile.png

    This jar package can be downloaded at https://jira.talendforge.org/secure/attachment/54040/LoanModel.jar.

  9. Expand the nodes to browse to and select the Jar file which contains the
    rules of interest, and then click OK to
    close the dialog box. In this example, the class is org.talend.bank.LoanSimulator.

    BRMS_Deploy_Jar2.png

    A Talend programme transforms the business rule
    library into a form which can be used in the Job and creates an XSD file at
    the root of your studio, in
    /studio_path/Drools/<project_name>. The XSD file
    records the mapping between the incoming data flow and the objects to be
    handled by the Drools engine.

  10. In the Drools Flow ID (if exists) field,
    enter, between quotation marks, the ID of Drools flow to be used when
    executing the rules of interest. In this example, it is loanflowxls. For more information about Drools
    flow, see the relevant Drools manuals.

Advanced settings of tBRMS

  1. Click the Advanced Settings tab to set
    the additional parameters.

    BRMS_Advanced_settings.png
  2. In the XML Mapping area, click […] to configure the XML tree.

    Right-click the first row in the Link
    target
    table and select Import XML
    Tree
    .

    brms_xml_tree.png
  3. Browse to and select the XSD file from the root of your studio. The
    XML Tree schema is completed
    automatically.

    brms_xml_tree2.png
  4. Drop all of the relevant columns from the Schema
    List
    onto the corresponding related column fields in the
    Link target schema.

    From the dialog box which appears, select the Add
    linker to target node
    option.

    brms_xml_tree_attribute.png

    Alternatively, you can click Auto map! to
    concatenate automatically the columns between the Linker source and Link
    target
    .

  5. Right-click the reason field and select
    Set As Loop Element from the
    list.

    brms_xml_tree3.png
  6. Click OK to close the dialog box.

Configuring the output flow

To extract the data of interest, you need to configure the output flow. The
operations to be performed are as follows:

  1. Double-click tExtractXMLField to open its
    Basic settings view.

  2. Click Edit schema to open the schema
    editor.

    tExtractXMLField_Output_schema.png
  3. In the Output schema to the right of the editor, add and define the
    columns which correspond to those columns in the tBRMS input schema. The sequence and names of columns may
    vary according to your need.

  4. Click OK to close the editor.

  5. In the Loop XPath query field, enter the
    name of the XML Tree root tag, as it
    appears in the Configure XML Tree editor of
    the tBRMS component, preceded by the
    forward slash symbol and between double quotation marks, for example:
    “/loanSimulator”.

  6. In the XPath query fields, next to the
    corresponding columns, enter the fields exactly as they appear in the
    XML Tree fields of the tBRMS component, in the Link Target area of the Configure XML
    tree
    editor, between double quotation marks.

  7. Double-click tLogRow to open its
    Basic settings view:

    tLogRow_BasicSettings.png
  8. In the Mode area, select the Table (print values in cells of a table)
    option.

Saving and executing the Job

  1. Press Ctrl+S to save your Job.

  2. Press F6 or click Run on the Run console to
    launch the Job.

    tbrms_scenario_result.png

    The business rule has been applied to the input data and the table of
    results indicates which candidates have been rejected. The Reason column indicates the reason for which the
    candidate has been rejected.


Document get from Talend https://help.talend.com
Thank you for watching.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x