One Star

Using tJava component

I'm very new to atlend and using TOS for bigdata 5.3.1. I wanted to find the file extensions in the given directory and do that specific job for each file types.
Description :
I have the folder where i fave 3 files with different extensions say a.csv,b.xml and c.json. What I wanted to do here is if the file is csv ,first it should find the file extension and then it should read the file with schema. So that next time if i get the csv file with the same schema with different data it should not again create the schema for that and it should take the schema already created for the 1st time.
If my file is xml or json, it should do the same thing as i explained for the csv.
To achieve this in talend i have used the components as below
tFileList >> tJava >> tFileInputDElimited >> tLogRow
In tFileList i'm getting all the files .In tJava i'm checking the file extensions but i'm facing the problem in tJava componet ,i.e., how to get the file lists from the tFileList component in tJava.
The code i have used in jJava is
String dir = (String)globalMap.get("tFileList_1");
String filename = dir("CA.csv");
int dotPosition = filename.lastIndexOf(".");
String extension = "";
if (dotPosition != -1) {
extension = filename.substring(dotPosition);
System.out.println("The file is of type: " + extension);
In the 1st line its giving error.Also if file is csv it will go for tFileInputDElimited job next. But if the file is xml i wanted to execute TFileInputXML >So can i draw multiple jobs attached to tjava component?
Am i doing proper here for my requirement?
Please suggest me what can be done ? Also i have attached screenshot of my job.
Four Stars

Re: Using tJava component

Hi ShreeCS,
What about using tFileProperties component to get the filename and use tjavarow to get right 3 characters as file extension?? This would be simpler than the java code...

You can have multiple jobs from tJava component based on OnSubJobOk or based on If clause with some expression for it may be if basename contains xls -- one flow, if .csv -- second flow etc....
One Star

Re: Using tJava component

using the java code below i'm able to get the file name ->
String filename = (String) globalMap.get("tFileList_1_CURRENT_FILE") ;
Rest of my java code is used to get the file type ,next job components are used to read the csv file and xml file .But the thing is here after tJava component i'm not getting the option of onSubjobOK .So i used onComponentOK.
Is it fine to use that?
I have attached my job flows and errors m facing. also may be here its not checking for the condition of the file type.I tried with the condition " If(extention="csv")" but it was throwing error so removed it.
you suggested using tFileProperties and tjavarow .So can you tell me the job flow ?
please find the attachments.
One Star

Re: Using tJava component

I believe this is the same post... and a proposed solution...