Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi -
I have a vendor that does not allow us to move or remove files from their file location once we process them. I don't make the rules people.
I need to basically only process files that were created after the last time I loaded a file into my db. I'm storing the last load date in a global variable globalMap.get("lastDate") from the database. Then I'm iterating through file properties and storing the mtime from tFileProperties in global variable globalMap.get("fileDate") with this tJavaRow:
globalMap.put("fileDate", TalendDate.formatDate("MM-dd-YYYY HH:mm:ss",new java.util.Date(input_row.mtime)));
I want to have a flow to "do nothing" if the file date is prior to last load date and then a flow to process the file if the file date is > last load date.
I can't get the conditions in the Run If links to function properly.
This is the syntax I'm using on the conditions for the 2 flows:
((Date)globalMap.get("fileDate")).compareTo(((Date)globalMap.get("lastDate")))<=0
((Date)globalMap.get("fileDate")).compareTo(((Date)globalMap.get("lastDate")))>0
I get the following error:
Exception in component tJavaRow_1
java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Date
However - everything works fine if I disable the 2 flows so I know the problem isn't in the tJavaRow - it's in the Run If links.
Any thoughts on what I'm doing wrong?
Thanks,
Darin
The error message tells you (nearly) everything you need to know....
"java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Date"
You are setting the "fileDate" globalMap to a String when you use formatDate. Why are you doing this? You do not need to format a date to compare it. Dates are stored as numbers, formatting them is ONLY for representing them to humans. If you are wanting to compare them, don't worry about the format and just compare them.
The error message tells you (nearly) everything you need to know....
"java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Date"
You are setting the "fileDate" globalMap to a String when you use formatDate. Why are you doing this? You do not need to format a date to compare it. Dates are stored as numbers, formatting them is ONLY for representing them to humans. If you are wanting to compare them, don't worry about the format and just compare them.
Thank you for the clarification.
Clearly I wouldn't have done something incorrectly had I known that I was doing so...that's kind of the point of this forum, no? I now have a better understanding of the usage of globalMap, formatDate because of this error. Where I come from - that's learning and that, I assume, is the purpose of this community.
Thank you for your time.
I just reread my post. I think I came across a little harsher than I had intended when I wrote it. Sorry if you got the wrong impression and that my written English came across a little curt. #RememberNotToPostOnHereWhenReallyTired