Tuesday, June 18, 2013

Java Libraries in Talend Open Studio


Although Talend Open Studio has a rich set of StringHandling functions, I prefer those in the StringUtils class of Apache Commons Lang.  One of my favorite functions is "isBlank" which checks for null, the empty String, and a String composed only of whitespace.  Fortunately, Talend provides and easy way to integrate this library call.

The Java library I'll be working with is the Commons Lang library:  Commons Lang.  Here is theJavadoc.

An Example
 
This is an image of Open Studio.  An input Excel file is mapped directly to an output Excel file.  However, since some of the fields in the source are empty, some null/empty string checks are required to make sure that the output spreadsheet's columns are aligned.

Talend Open Studio Job with tLibraryLoad Component
 Select the tLibraryLoad component.  In the Component panel, the "Basic settings" tab will let you find the JAR file.  Under "Advanced settings" there is a text box into which import statements can be added. Add the following import statement in this text box.

import org.apache.commons.lang.StringUtils;

Then, in the tMap component, add a Java expression that makes the StringUtils.isBlank call.

tMap with a Commons Lang StringUtils Call
Deployment Note

When you use tLoadLibrary, the JAR file is copied in the Talend internals.  This makes it eligible to be exported along with a job.  Don't try to adjust the IDE's or another classpath to find your JAR.

Flexibility

There are many possibilities for integration with this kind of flexibility.  This example focused on some useful string handling routines from a popular Java library.  But with Java, there is so much code out there that more capable libraries like Hibernate or JUnit could find their way into integration scenarios.

1 comment:

Shivam Kumar said...

You have done nice job . Keep it up .you can visit stringutils isnotblank and stringutils isnotempty method examples with nice explanation .