Thursday, March 12, 2015

Rule Executor in PDI 5.2

I have created a sample of Rule Execution for PDI 5.2 . Created this sample by taking Sample file from data-integration folder itself. This code sample will validate birthdate and based on condition gives the status by creating a status column out there

Hope you guys like it.


















Add Rules Executor step in Transformation and add this code in that step

package org.pentaho.di.trans.steps.rules

import org.pentaho.di.trans.steps.rules.Rules.Column;

global java.util.List list

rule "Very Old Pal"
    dialect "java"
    when
        $birthdate: Column(name == "birthdate", payload >= '1950/01/01' &&  payload  < '1970/01/01' )
        
    then
        Column Status = new Column();
Status.setName("Status");
        Status.setType(String.class.toString());
        Status.setPayload("Very Old Pal");
        insert(Status);
end

rule "Old Pal"
    dialect "java"
    when
        $birthdate: Column(name == "birthdate", payload >= '1970/01/01' &&  payload  < '1980/01/01' )
        
    then
        Column Status = new Column();
Status.setName("Status");
        Status.setType(String.class.toString());
        Status.setPayload("Old Pal");
        insert(Status);
end

rule "Young Pal"
    dialect "java"
    when
        $birthdate: Column(name == "birthdate", payload >= '1980/01/01' &&  payload  < '2000/01/01' )
        
    then
        Column Status = new Column();
Status.setName("Status");
        Status.setType(String.class.toString());
        Status.setPayload("Young Pal");
        insert(Status);
end

rule "Teen"
    dialect "java"
    when
        $birthdate: Column(name == "birthdate", payload >= '1980/01/01' &&  payload  < '2000/01/01' )
        
    then
        Column Status = new Column();
Status.setName("Status");
        Status.setType(String.class.toString());
        Status.setPayload("Teen");
        insert(Status);
end