Dynamic Field Data Transformation
CopyStorm/Restore has the ability to transform data in the CopyStorm backup database prior to writing it to the target Salesforce. Built-in data transformers include:
- Scramble — replace each letter with a different letter, replace each number with a different number.
- Email Scrambler — build a new email address of the same size but with random letters & digits.
- Email Append Invalid — append “.invalid” to an email address.
- Asterisk — replace the source data with “******”.
- Random Dictionary Substitution — for Names, Countries, Cities, Streets…etc
- Lorem Ipsum — replace a block of text to the infamous “Lorem ipsum dolor sit amet, consectetur adipiscing…”
- Random Date/Time — replace a date or date/time with a random date or date/time within the same year.
Read more about built-in transformers in the Fields to Restore Editor article.
If the built-in transformers are insufficient for your needs the instructions in this article can be used to add a new transformer to CopyStorm/Restore. The approach described in this article is the same as what CopyStorm/Restore does internally.
To Add a Dictionary Transformer
To add a dictionary transformer that substitutes values from a provided list of values, you can create or update update the TransformerRegistry.xml file with a tag:
<Transformers>
<Dictionary name=”My Transformer Name” file=”/path/to/a/file.txt”/>
</Transformers>
This will add two new transformers:
- Random: My Transformer Name
- Uniform: My Transformer Name
These transformers will replace the input text with a value taken from the text file (one value per line). The Random transformer will replace each input value with a random line from the text file. The Uniform transformer will replace each input value with a line from the text file, always replacing the same input text with the same value from the text file.
To Implement a Custom Transformer
Step 1: Build a Java Class That Implements a Transformer
The first step is to build a Java class implementing “com.capstorm.copystormrestore.transform.ITransformer”. The code below contains the implementation of the Asterisk transformer:
public class AsteriskTransformer implements ITransformer { @Override public String transform(String table, String column, int columnWidth, String recordId, String value) { if( StringUtils.isBlank(value)) { return value; } return StringUtils.repeat("*", value.length()); } }
The parameters to the transform() method are:
Parameter | Description |
---|---|
table | The name of the table containing the column to transform. |
column | The name of the column to transform. |
columnWidth | The maximum width of the column value. |
recordId | The Salesforce Id of the record being processed. |
value | The current value of the column. This may be null. |
The method must return the value to insert / update in Salesforce.
Once the class has been created, package it into a jar and put the jar into the “lib” subdirectory of the CopyStorm/Restore installation. CopyStorm/Restore will only find your class if it is installed in this directory.
Step 2: Create an XML Configuration File
For CopyStorm/Restore to discover a field transform it must be declared in a file named “TransformerRegistry.xml” and placed into a directory where CopyStorm/Restore looks for configuration files (for example, the “config” sub-directory of the CopyStormRestore installation).
The TransformerRegistry.xml file should look like the following:
<Transformers> <Transformer name="Asterisk" class="com.capstorm.copystormrestore.transform.AsteriskTransformer" /> </Transformers>
Where:
- “name” is the value that will appear in the CopyStorm/Restore GUI.
- “class” is the full path to the class built in the first step.
Other Details
To set up a build and test environment for a new transformer in Eclipse:
- Create a new Java project.
- Update the new project’s path to reference all jar files in the “lib” sub-directory of CopyStorm/Restore.
For other development environments, including building and testing on the command line, make sure that all the required Jars are on your Java class path.
If this is to much for your team send an email to sales@capstorm.com and they will be happy to arrange a small service contract.