Talend job for if – Else in tJavaRow

Talend job for if – Else in tJavaRow

Scenario

I do a job which request on Informix DB with two tMap  and one tUnit for generate a Directory of personns. The Job  works fine. But i have a problem for reverse column at the end of job in my csv.

in fact : My csv contain : Name – married name – FirstName. I just want : if married name is different of null,  the name = married name.

At the end of my job, juste before generate my final csv, i have add between my tUnit and the cvs output file a tJavaRow coponent, who i haved generate  the java code correctely
(exemple :output_row.nom_pat = input_row.nom_pat; (name)
output_row.nma_pat = input_row.nma_pat; (married name)

And i have add this code :

if (input_row.nma_pat != null) {
output_row.nom_pat = input_row.nma_pat;
output_row.nma_pat = “”;}
else { output_row.nom_pat = input_row.nom_pat;}

With that, the job runs correctly, when a line contains a married name, i have this married name in the collumn of name, but the others lines who havent married name (male) have a null name. This is my problem. I think my If – Else is not good.

After tMap, request and other i have in output two csv files. This two file have got the same schemas :

-iddossier
-nom (name)
-nma (married name)
-prenom
-sexe
-den
-dso
-service
-chambre

I merges this two file with tUnit component (same schemas) on a csv output file (same schemas). The problem is that : In my database for married women , the married name is insert into “nma” and maiden name in “nom”. In my directory i want the married name and not “nom”.

I just want for some lines of my csv who have got a married name, swhitch this column into “nom”. I hope you understand smile For that between tUnit and ouput csv i have add an tJavaRow, i have clik on generate code and i add to that little code of java (i don’t know java).

“output_row.iddossier = input_row.iddossier;
output_row.nom_pat = input_row.nom_pat;
output_row.nma_pat = input_row.nma_pat;
if (input_row.nma_pat != null) {
output_row.nom_pat = input_row.nma_pat;
output_row.nma_pat = “”;}
else { output_row.nom_pat = input_row.nom_pat;}
output_row.pre_pat = input_row.pre_pat;
output_row.sex_pat = input_row.sex_pat;
output_row.den_dossier = input_row.den_dossier;
output_row.dso_dossier = input_row.dso_dossier;
output_row.ser_dos = input_row.ser_dos;
output_row.nch_sej = input_row.nch_sej;”

That work because all the “nm”a are put in “nom” collumn, thats i want. But all others name’s without married name (male or women not married) disappear.

 

Talend job for if – Else in tJavaRow

 

Solution

 

Leave a Reply