Skip to main content Skip to complementary content

Defining the survivor validation flow

Procedure

  1. Double-click tRuleSurvivorship to open its Component view.
  2. Select GRP_ID from the Group Identifier list and GRP_SIZE from the Group size list.
  3. In the Rule package name field, replace the by-default name org.talend.survivorship.sample with a name of your choice, if needed.
    The survivor validation flow will be generated and saved under this name in the Repository tree view of the Integration perspective.
  4. In the Rule table, click the plus button to add a row per rule.
    In this example, define one rule and complete it as the following:

    Order

    Rule name

    Reference column

    Function

    Value

    Target column

    Sequential

    "Rule1"

    File

    Expression

    .equals("1")

    Acctname

    One rule, "Rule1", will be generated and executed by tRuleSurvivorship. This rule validates the records in the File column that comply with the expression you enter in the Value column of the Rule table. The component will then select the corresponding value as the best breed from the Acctname target column.
  5. Next to Generate rules and survivorship flow, click the icon to generate the rule package according to the conditions you have defined.
    The rule package is generated and saved under Metadata > Rules Management > Survivorship Rules in the Repository tree view of the Integration perspective.
  6. In the Repository tree view, browse to the rule file under the Survivorship Rules folder and double-click "Rule1" to open it.
    But this rule will select the values that come from file 1. However, you may also want to survive records based on specific criteria; for example, if Acctname has a value in file1, you may want to use that value, or else use the value from file2 instead. To do this, you must modify the code manually in the rule file.
  7. Modify the rule with the following Drools code:
    package org.talend.survivorship.sample 
    
    rule "ExistInFile1"
        no-loop true
        dialect "mvel"
        ruleflow-group "Rule1Group"
    when
        $input : RecordIn( file.equals("1"), acctname!= null, !acctname.trim().equals("") )  
    then
        System.out.println("ExistInFile1 fired\t" + $input.record_id);
        dataset.survive( $input.TALEND_INTERNAL_ID, "Acctname" );
        dataset.survive( $input.TALEND_INTERNAL_ID, "File" );
    end
    
    rule "NotExistFile1"
        no-loop true
        dialect "mvel"
        ruleflow-group "Rule1Group"
    when
        $input : RecordIn( file.equals("2"), acctname!= null && !acctname.trim().equals("") )  
        (not (exists (RecordIn( file.equals("1") ))) 
        or exists( RecordIn( file.equals("1"), acctname== null || acctname.trim().equals("") ) ))
    then
        System.out.println("NotExistFile1 fired\t" + $input.record_id);
        dataset.survive( $input.TALEND_INTERNAL_ID, "Acctname" );
        dataset.survive( $input.TALEND_INTERNAL_ID, "File" );
    end
    Information noteWarning:

    After you modify the rule file, you must not click the icon. Otherwise, your modifications will be replaced by the new generation of the rule package.

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!