Six Stars

IF in tJava issue

Hello everyone, I'm trying to compare filename with date inside to whether or not delete them.

Since I have 2 types of filesname : "AA_MAGAS_yyyyMMdd_hhmm" and "AA_BBB_CCC_yyyyMMdd_hhmm" , my idea was to substring the filename (from 9 to 22 for first file type and 11 to 24 for the second one), get the date out & compare it. Then use this result in a run if condition to delete it.

My job was working for only 1 file type, but since I tried a IF condition to deal with the 2 filesname, its not working anymore. Can someone have a check ?

 

if ( ((String)globalMap.get("tFileList_1_CURRENT_FILE")).equals("AA_MAGAS_*") )

{
	
context.strdate = ((String)globalMap.get("tFileList_1_CURRENT_FILE")).substring(9,22);

context.date = TalendDate.parseDate("yyyyMMdd_hhmm",context.strdate);

//difference of days between current date & file date, >15 = delete (runif)

context.difference = TalendDate.diffDate(TalendDate.getCurrentDate(),context.date,"dd");

}

else {
	

context.ecodate = ((String)globalMap.get("tFileList_1_CURRENT_FILE")).substring(11,24);

context.date = TalendDate.parseDate("yyyyMMdd_hhmm", context.ecodate);

context.difference = TalendDate.diffDate(TalendDate.getCurrentDate(),context.date,"dd");


};


My error, seems like the IF condition is not working because the substring get it wrong :


java.lang.RuntimeException: java.text.ParseException: Unparseable date: "180210_0345.x"

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Six Stars

Re: IF in tJava issue

Hello, Thanks its all fine now. We cant use wildcard in equalsIgnoreCase. I had to use substring then equals

2 REPLIES
Nine Stars

Re: IF in tJava issue

i think issue with file name format, date format in file name looks like yyMMdd_hhmm not yyyyMMdd_hhmm this.

 

Please validate file name.

 

Regards,

Veeru Boppudi
Six Stars

Re: IF in tJava issue

Hello, Thanks its all fine now. We cant use wildcard in equalsIgnoreCase. I had to use substring then equals