Look-Ahead Attribute Updates

Let's say you want to track a source-system flag with a timestamp so you can track when you first saw that flag change. So you create an attribute and instead of just a flag, you use a timestamp. 

However, the default behavior is to send all attributes that are different and since you're translating a flag into a timestamp for right now, it's going to be a different value than the last time you saw it.

To solve this, do your own comparison in the 'After Lookup' part of a connector and remove attributes you don't want to update.


After Lookup Hook

// Make sure there's a returned object, otherwise conn is null and exceptions
// will happen later when tying to get it's value
if (conn) {

// If there's already a value on the conn object, remove the attribute from work 
// so it doesn't get updated.
if (work.someAttribute.getValue() && conn.someAttribute.getValue() ) {
work.removeAttribute("someAttribute");
}
}


Attribute Mapping
(of someAttribute)

// Check to see if we removed the attribute earlier. If it's still
// present, we need some data. Otherwise let it be null 
if ( work.someAttribute && work.someAttribute.getValue() ) {
// Here we're replacing the attribute flag with a time stamp
   new java.sql.Timestamp(java.lang.System.currentTimeMillis());
}
else
work.someAttribute


Comments