You are not logged in.
I have a set of files shown like below.
I have a tFileList component with the source folder which is holding above files. Now for files ending with USERLOGON.xml, USERLOGOFF.xml, I need to check if its corresponding CONTROL.xml file exists with the initial part of the file name as same. As you can see there is a date 20110530, 20110531 which keeps changing. Now I wanted to try out the following ways..
1. Get the file name string in a loop and substring it till the date (constant number of characters in this case 20) and append 'CONTROL.xml' to the string and pass it on to a tFileExist component.
2. If the CONTROL.xml file exists then proceed with next operation on the original file processing.
But I am not able to get the context variables or some other way to get this done.. I am new to Talend... can any body please help with possible easier ways. My Talend code generated is Java. Thanks in advance.
you have the right idea.
use a tFileList to retrieve the list of files. in a tJava, retrieve the file names from the global map and prepare your context variable-- then use it to check if your control file exists.
Is there a sample Java code, which can be used for the above purpose. My doubt is how can I say componentOK and pass the actual file name to next module after checking if corresponding CONTROL.xml exists in tJava?
If I understand correctly there are two cases here:
1) some files exist, but no control file
2) all files exist.
so, using this job template:
tFileList--iterate-->tJava--onComponentOK-->tFileExist----OnSubjobOK--->(rest of job)
in the tJava:
String fileName = globalMap.get("tFileList_1_CURRENT_FILEPATH"); <do something with fileName> context.control_file = fileName;
in the tFileExist, check for the existence of:
in the rest of your job, you can refer to the current file of the tFileList with:
Thank you very much. But I am now facing error with context.control_file.
My tJava code is:
context.control_file = substring((String)globalMap.get("tFileList_1_CURRENT_FILEPATH"),26);
This is giving error as 'The method substring(string, int) is undefined for the type <jobname>.
In tFileExist_1 -> I gave the file path as context.control_file in file name/stream.
This is giving error as ' control_file cannot be resolved or is not a field'.
What am I missing?
1) context.control_file = ((String)globalMap.get("tFileList_1_CURRENT_FILEPATH")).substring(26);
2) you need to add control_file as a context variable in the context tab.
Last edited by JohnGarrettMartin (2011-06-17 14:31:54)
Thank you very much John for patiently replying to all my questions. It seems to be working, but still there is one problem. Even if there is no corresponding CONTROL.xml file, it is copying all the files. I think it should be the problem with iteration.
My tJava code:
context.control_file = ((String)globalMap.get("tFileList_1_CURRENT_FILEPATH")).substring(0,69)+"CONTROL.xml";
My tFileExist file path:
I set a context variable. Please find the execution screenshot below.
For me it should not copy files without corresponding CONTROL.xml, but irrespective of result of before steps, it is copying all files.
instead of 'onComponentOK' you need to use an 'if' connector. click on the connector and in the 'if' component tab, you put the condition you want to check:
check the generated code for the tFileExists component to make sure i'm giving you the correct key to the globalMap.
Thank you very much John!!!
That worked with ((Boolean)globalMap.get("tFileExist_1_EXISTS")) in If condition. This really helped me understand the flow. Thank you very much for your answers and patience. Where can I get these detailed set of components and their checks or example projects. I have gone through the tutorials provided with talend, but this in depth practical details are not available i guess. Thanks again.