Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I will pass run date (format: yyyymmdd) during job run and i have to archive the files from a folder which are 90 days old from the run date which i have passed.
The files in the folder are of the format
abcdefgh.Dyyyymmdd.
How can this be achieved
I suppose the date passed to job reside in a context variable named "inDate" with data type String.
First you need to compute the value for "context.inDate - 90 days".
You can to that within a tSetGlobalVar component to define a global variable named "referenceDate" like this:
Then you need to get files in the source folder using tFileList.
Connect the tFileList component to an other tSetGlobalVar using the "Iterate" row.
Into the tSetGlobalVar component you will get the date part from the filename for each file you:
Connect tFileCopy to this tSetGlobalVar using an "If" trigger with the following expression:
((String)globalMap.get("referenceDate")).compareTo((String)globalMap.get("fileDate")) <= 0
Finally, configure the tFileCopy component as need to archive the current file:
Current will be moved to the folder designed by "archiveFolder" context variable.
job design
Hi,
Should the job be designed like given above or there should be 2 different tfilelist components ?
when i ran the above job i got the following error for the tsetglobalvar_2:-
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method replaceALL(String, String) is undefined for the type String.
Not sure whether i have designed it wrong.
I have changed it like that and ran the job but now it throws the below error-
tSetGlobalVar_2 null
[statistics] disconnected
Exception in component tSetGlobalVar_2
java.lang.NullPointerException
Here is what your job should look like:
tSetGlobalVar_1 to define the "reference date" based on the inDate context variable with the following expression:
TalendDate.addDate(context.inDate, "yyyyMMdd", -90, "dd")
tFileList_2 to get file list (no comment)
tSetGlobalVar_3 to compute the "file date" base on the current filename with the following expression:
((String)globalMap.get("tFileList_2_CURRENT_FILE")).replaceAll("^.*\\.D", "")
If trigger is defined with the following expression:
((String)globalMap.get("referenceDate")).compareTo((String)globalMap.get("fileDate")) <= 0
Note: we can use String.compareTo() because of the date format (yyyyMMdd).
tFileCopy to move the current file into the archived folder:
Hi,
attaching the job component by component.
Now the job runs successfully but file is not getting copied ( there are files that are more than 90 days old in the source location) to the archive path.
Not getting what has gone wrong.
Hi,
No files got archived even when there were files matching the criteria(greater than 90 days).
Attaching the files from the path along with.(for testing purposes i have created touch files which is why all are showing up as 0 KB).
Thanks.