The Talend Open Studio Routines BRules, or Business Rules, contains a set of validation functions for use in Talend components like tMap. Version 0.1 wrapped up Google's phone number validation library (libphonenumber). Version 0.2 adds the shorthand routines "all()" and "xor()" that handle empty values passed in the input schema.
The following screenshot shows a tMap component calling BRules functions.
|Screenshot of tMap Using BRules Functions|
all() is a function that accepts a variable number of arguments and makes sure that there is a value for each of them. Each String is checked for null, the empty string(""), and whitespace. Other Object types are checked for null. If any argument is missing, the validation fails.
all("one") # true
all("one", "two") # true
all(null) # false
all("", "two") # false
all(new Long(0L), null) #false
xor() is a function that accepts a variable number of arguments and makes sure that one and only one of the values is set. Each String is checked for null, the empty string (""), and whitespace. Other Object types are checked for null. If at least one of the arguments is set, the validation succeeds.
xor("one") # true
xor("one", "") # true
xor("", "") #false
xor(null) # false
xor("one", "two") # false
The varying number of arguments is implemented using a Java 5 language feature.
In the Talend documentation, a routine usually includes the class name. For example, "TalendDate.dateDiff()" is used when calling dateDiff(). This can be shortened if a static import is used. "BRules.all()" can be reduced to simply "all()".
To do this, add a single tJava component with a static import like the following
import static routines.BRules.all;
import static routines.BRules.xor;
This is a link to the project homepage on Talend Exchange. Look for "BRules" under routines.
Look for future BRules release to further shorten your Talend expressions and to bring in more third-party libraries.