Featured Post

Applying Email Validation to a JavaFX TextField Using Binding

This example uses the same controller as in a previous post but adds a use case to support email validation.  A Commons Validator object is ...

Wednesday, March 30, 2011

BRules 0.2 Released for Talend Open Studio

BRules is a collection of routines that validates data elements in Talend Open Studio. Version 0.2, which includes the new shorthand validation routines "all()" and "xor()", was uploaded to the Talend Exchange
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

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

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.

Shortened Syntax

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.

http://www.talendforge.org/exchange/index.php

Look for future BRules release to further shorten your Talend expressions and to bring in more third-party libraries.

1 comment:

  1. To do something like all() or xor() with a component, check out tAggregateRow.

    ReplyDelete