Recently, we have received one requirement where we were picking files from three different systems using FTP server and then merge them. The requirement become complex when we had to check the existence of all files at their source directory and stop if any one of the file is absent.
To achieve this requirement, we have made one scenario where we will create one sender channel which will be in test mode. That channel will always pick test file and consequently our mapping will execute. In message mapping, we have written three single values udf which will check for the files on ftp server and and pick all three files. If any one of the file is absent,it will throw runtime exception and mapping execution will stop there itself.
For better understanding you can follow below map.
For working on FTP server from PI, we have used Apache FTP executable libraries which you can find on apache.org
Step1: To import Jar file on apache libraries in imported archive
Step 2: Accessing FTP Server using FTPClient class
We can connect using connect and login method FTPClient and get all files list in the directory and then check for our file if it exists there.
At last we will read all data of file and store it in global variable “file1data” which can be appended with other files data.
If any one of the file is not present in directory it will be return empty. On which runtime exception will be thrown.
Mapping for this is given below, in which three function modules are created for each system.
All three function modules will return blank string if any of the file is not found. And on receiving blank exception_check udf will throw exception.
You post your reviews in comment section if you face any issue while implementing this requirement