Parsing transform code programmatically

Hi,

Currently I am trying to create a Join component programmatically. The hurdle in my way is, how do I define a transform function during runtime ?

I know it is possible as running a graph via the org.jetel.main.runGraph, consumes the XML graph definition and dynamically defines the transform function via the CTL2 language.

So what I am trying to accomplish is to translate

function integer transform() {
$out.0.Ric = $in.0.Ric;
$out.0.Field1 = $in.0.Ticker;
$out.0.Field2 = $in.0.Bloomberg;
$out.0.Field3 = $in.0.Assetclass;
$out.0.Field4 = $in.1.Ric;
$out.0.Field5 = $in.1.Ticker;
$out.0.Field6 = $in.1.Bloomberg;
$out.0.Field7 = $in.1.Assetclass;

return OK;
}

from a String into a RecordTransform class and instantiate a HashJoin supplying RecordTransform as a parameter.

Hi jasonq323,

easier alternative is to store code of transformation (same code as you see in transformation editor, including initial //CTL2 comment) into file, then exec second graph, where transformation file is referred via “Transform URL” property.

Hi,

Thanks for the hint.

Managed to breakpoint through a file load to see that a function can be loaded via the transform string of a Transform Node as well.

// Create transformation ports for the joiner
// These are transform function code in CTL2 that will be parsed
// Need to understand how to store this in database
String transformFunction = new StringBuilder()
.append(“//#CTL2 \n”)
.append(“// Transforms input record into output record. \n”)
.append(“function integer transform() { \n”)
.append(“$out.0.RicFeed1 = $in.0.Ric; \n”)
.append(“$out.0.TickerFeed1 = $in.0.Ticker; \n”)
.append(“$out.0.BloombergFeed1 = $in.0.Bloomberg; \n”)
.append(“$out.0.AssetclassFeed1 = $in.0.Assetclass; \n”)
.append(“$out.0.RicFeed2 = $in.1.Ric; \n”)
.append(“$out.0.TickerFeed2 = $in.1.Ticker; \n”)
.append(“$out.0.BloombergFeed2 = $in.1.Bloomberg; \n”)
.append(“$out.0.AssetclassFeed2 = $in.1.Assetclass; \n”)
.append(“return OK; \n”)
.append(“} \n”)
.append(“// Called during component initialization. \n”)
.append(“// function boolean init() {} \n”)
.append(“// Called during each graph run before the transform is executed. May be used to allocate and initialize resources \n”)
.append(“// required by the transform. All resources allocated within this method should be released \n”)
.append(“// by the postExecute() method. \n”)
.append(“// function void preExecute() {} \n”)
.append(“// Called only if transform() throws an exception. \n”)
.append(“// function integer transformOnError(string errorMessage, string stackTrace) {} \n”)
.append(“// Called during each graph run after the entire transform was executed. Should be used to free any resources \n”)
.append(“// allocated within the preExecute() method. \n”)
.append(“// function void postExecute() {} \n”)
.append(“// Called to return a user-defined error message when an error occurs. \n”)
.append(“// function string getMessage() {} \n”)
.toString();

Node nodeJoiner = new HashJoin(“HashJoin”, “$Ticker=$Ticker”, transformFunction, null, null, Join.FULL_OUTER);