Hi All,
We are writing an UDF to put a file into a folder based on some conditions over SFTP. Based on the file name, we'll decide in which folder to put those files into. The folder path will be determined inside the Java code. There is no need to change the file name or content of the files. Scenario is a Java program receives the file, checks the file name, decides on the folder it needs to place and put it into it.
What is happening is, if we specify the destination folder in the parameters, it is picking from the source folder and placing all the files (even for the files which doesnt pass the condition ) in the folder. Instead if we put * in there for Filepath, files are going missing.
Below are the screen shots of configurations
Below is the Java code we use:
try { String currDateMinusOneFilesPath = "/interface/DMS/AMT/CORRECTFILES"; String otherFilesPath = "/interface/DMS/AMT/WRONGFILES"; final DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); final Calendar fileDate = Calendar.getInstance(); DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION); DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/Files", "FileName"); DynamicConfigurationKey key1 = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/Files", "Directory"); String filename=conf.get(key); String splitValue = filename.substring(filename.length()-8, filename.length()); Calendar calendar = Calendar.getInstance(); fileDate.setTime(dateFormat.parse(splitValue)); if(fileDate.get(Calendar.YEAR) == calendar.get(Calendar.YEAR) && fileDate.get(Calendar.MONTH) == calendar.get(Calendar.MONTH)) { if(calendar.get(Calendar.DATE) - fileDate.get(Calendar.DATE) == 1) { conf.put(key,filename); conf.put(key1,currDateMinusOneFilesPath); } else { conf.put(key,filename); conf.put(key1,otherFilesPath); } } else { conf.put(key,filename); conf.put(key1,otherFilesPath); } } catch(Exception e) { throw new StreamTransformationException(e.toString()); } finally { return ""; }
Your help is highly appreciated.
Thanks,
Lokesh