Skip to main content

Custom Transformations

Goal

Use a Custom Transformation function to implement a custom correction algorithm, applied to the output of a Task Rule.

Place your custom Java function inside your root package/transformations folder in the genereated project.

Notes

  • The input of the Transformation Function, i.e. the output of the rule, is read as a String
  • The transformation function returns a String
  • Apply any data correction logic inside of its transform function
  • The result is stored into the back to the column
  • Can also implement IPreScan and override the scan function. This provides you with the entire set of records in the scan function which you can inspect and use for the transform function

Transformation Interface

public interface ITransformation {
String transform(String input) throws Exception;
}

Java Examples

public class ReplaceDigits extends AbstractRandom implements ITransformation {

public static final String LABEL = "ReplaceDigits - randomize the digits in a string";

@Override
public String transform(String input) {
if(input == null || input.isEmpty())
return input;
char[] chars = input.toCharArray();
StringBuilder sb = new StringBuilder();
for (char c : chars) {
if(Character.isDigit(c))
sb.append(getRandom().nextInt(10));
else
sb.append(c);
}
return sb.toString();
}
}

ANO Usage Examples

  • You must explicitly import Transformation functions before the Tasks and Rules Section
transformation example.anonymizer.transformations.ReplaceDigits

task MyTask
{
update Booking

mask comment
format %s
transform ReplaceDigits
column comment
}