<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic tJava - IF ELSE statement fails! in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/tJava-IF-ELSE-statement-fails/m-p/2337949#M106239</link>
    <description>&lt;P&gt;Hello everyone, I'm trying to compare filename with date inside to whether or not delete them.&lt;/P&gt; 
&lt;P&gt;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 &amp;amp; compare it. Then use this result in a run if condition to delete it.&lt;/P&gt; 
&lt;P&gt;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 ?&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;PRE&gt;{
	
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 &amp;amp; file date, &amp;gt;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");


};&lt;/PRE&gt; 
&lt;P&gt;&lt;BR /&gt;My error, seems like the IF condition is not working because the substring get it wrong :&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;java.lang.RuntimeException: java.text.ParseException: Unparseable date: "180210_0345.x"&lt;/FONT&gt;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Thanks !&lt;/P&gt;</description>
    <pubDate>Tue, 22 May 2018 10:25:36 GMT</pubDate>
    <dc:creator>daez</dc:creator>
    <dc:date>2018-05-22T10:25:36Z</dc:date>
    <item>
      <title>tJava - IF ELSE statement fails!</title>
      <link>https://community.qlik.com/t5/Talend-Studio/tJava-IF-ELSE-statement-fails/m-p/2337949#M106239</link>
      <description>&lt;P&gt;Hello everyone, I'm trying to compare filename with date inside to whether or not delete them.&lt;/P&gt; 
&lt;P&gt;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 &amp;amp; compare it. Then use this result in a run if condition to delete it.&lt;/P&gt; 
&lt;P&gt;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 ?&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;PRE&gt;{
	
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 &amp;amp; file date, &amp;gt;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");


};&lt;/PRE&gt; 
&lt;P&gt;&lt;BR /&gt;My error, seems like the IF condition is not working because the substring get it wrong :&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;java.lang.RuntimeException: java.text.ParseException: Unparseable date: "180210_0345.x"&lt;/FONT&gt;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Thanks !&lt;/P&gt;</description>
      <pubDate>Tue, 22 May 2018 10:25:36 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/tJava-IF-ELSE-statement-fails/m-p/2337949#M106239</guid>
      <dc:creator>daez</dc:creator>
      <dc:date>2018-05-22T10:25:36Z</dc:date>
    </item>
    <item>
      <title>Re: tJava - IF ELSE statement fails!</title>
      <link>https://community.qlik.com/t5/Talend-Studio/tJava-IF-ELSE-statement-fails/m-p/2337950#M106240</link>
      <description>&lt;P&gt;This is caused by your wildcard. You cannot use a wildcard in Equals.&lt;/P&gt; 
&lt;P&gt;Try this....&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;PRE&gt;if ( ((String)globalMap.get("tFileList_1_CURRENT_FILE")).indexOf("AA_MAGAS_")&amp;gt;-1 )

{
	
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 &amp;amp; file date, &amp;gt;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");


};&lt;/PRE&gt; 
&lt;P&gt;You may also need to account for NULL if the filename can be empty. I've not done that, but you should think about it.&lt;/P&gt;</description>
      <pubDate>Tue, 22 May 2018 11:15:59 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/tJava-IF-ELSE-statement-fails/m-p/2337950#M106240</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-05-22T11:15:59Z</dc:date>
    </item>
    <item>
      <title>Re: tJava - IF ELSE statement fails!</title>
      <link>https://community.qlik.com/t5/Talend-Studio/tJava-IF-ELSE-statement-fails/m-p/2337951#M106241</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Also, as you're parsing a date from part of a filename, you should consider using the TalendDate.isDate() function, and only attempt the parseDate if it is a date.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Thanks&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;David&lt;/P&gt;</description>
      <pubDate>Tue, 22 May 2018 11:29:14 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/tJava-IF-ELSE-statement-fails/m-p/2337951#M106241</guid>
      <dc:creator>David_Beaty</dc:creator>
      <dc:date>2018-05-22T11:29:14Z</dc:date>
    </item>
  </channel>
</rss>

