How to use contexte variables in compnents developped with new component kit

Highlighted
Six Stars

How to use contexte variables in compnents developped with new component kit

Hi 

i'm migrating some components from java jet to the new component kit;

How to use contexte variables in compnents developped with new component kit.

Highlighted
Employee

Re: How to use contexte variables in compnents developped with new component kit

Hi @Bilel.Charradi 

 

With new Talend Component Kit you don't need to implement anything special in your Component code to support context variables. Context variables are supported by Studio out of the box.

It works in following way:

1. Component option value goes to generated code without changes.

If user set a value with context variable he may see following Java code fragment in generated code

(click on "Code" tab to see generated code)contextInCode.png2. In generated you may see that Map<String, Object> is created for Component options. Context variables are evaluated during this configuration Map setup. Map will hold evaluated context variable value (e.g. "myValue" string)

3. Then this Map is used to initialize Component. In Component code you will get evaluated context variable value (you will get "myValue" instead of context.input in Component code).

 

However, note that Components developed with new Component Kit support only static values (i.e. values which are not changed during Job runtime), because Component options are evaluated only once at the beginning.

 

If you have more questions don't hesitate to ask.

If you found some bug related to context variable value support, please create a ticket in our Jira for TUP (Studio) project.

 

Best regards,

Ivan Gonchar

Highlighted
Five Stars

Re: How to use contexte variables in compnents developped with new component kit

Hi Ivan,
From which object are we able to access global/context variables? I'm within the OnNext method in a processor and can't see an obvious way to get at these.
Highlighted
Employee

Re: How to use contexte variables in compnents developped with new component kit

Hi @serdarkilic 

 

It is not possible to access global/context variables directly in Component code. 

You may set global/context variable as value of Component UI property.

Then global/context variable value will be evaluated during Job code execution and set as value of Component Configuration class (a POJO class which defines Component properties)

In your Component code you may get variables values as values in your Configuration class.

Highlighted
Four Stars

Re: How to use contexte variables in compnents developped with new component kit

Hello,

 

I have tried this solution and while it works for context variables, it is treating the global variables as text (i.e. I get "jobName" output instead of the actual name of the job) 

 

I have included below a screen shot of the configuration in my studio and code for the configuration object and object for the list below.  

 

Configuration (Studio 7.1.1) 

Screenshot 2019-08-12 12.07.02.png

 

Configuration object:

Screenshot 2019-08-12 12.08.15.png

 

List object:

Screenshot 2019-08-12 12.07.50.png

2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

Have you checked out Talend’s 2019 Summer release yet?

Find out about Talend's 2019 Summer release

Blog

Talend Summer 2019 – What’s New?

Talend continues to revolutionize how businesses leverage speed and manage scale

Watch Now

6 Ways to Start Utilizing Machine Learning with Amazon We Services and Talend

Look at6 ways to start utilizing Machine Learning with Amazon We Services and Talend

Blog