Package com.orchestranetworks.addon.dint.transformation
Provides classes and interfaces to define and register transformations.
A transformation can be added to SourceFieldMappingStep, or TransformationMappingStep. You can execute multiple transformations as a chain. For example:-
To capitalize string data before inserting it in the target table:
- First, get SourceFieldMappingStep from TableMapping. - Use StringUpperCase transformation to perform uppercase conversion on the source field. - Finally, map to the target field. -
To add a prefix such as 'Mr/Ms' to a name field and insert into the target table:
- First get ConstantTransformationMappingStep from TableMapping. - Use StringConcat transformation to concatenate with the name field from the source table. - Finally, map to the target field. -
To capitalize only the first name of the full name string and insert into the target table:
- First, get SourceFieldMappingStep from TableMapping. - Use StringSplit transformation to split full name string into two variable 'firstName' and 'lastName'. - Use StringUpperCase transformation to perform uppercase conversion on the 'firstName' variable. - Use StringConcat transformation to concatenate with the variable 'lastName', the output of the previous split step. - Finally, map to the target field.
A custom transformation needs to be registered to be displayed in the mapping screen:
TransformationRegistry.getInstance().add(new ACustomTransformationDefinition());
The following is an example of a custom transformation function with a generic input structure:
public class AddressAggregate implements TransformationDefinition<GenericDataObject, String>
{
private static final InputDefinition INPUT_COUNTRY = new InputDefinition(
"country",
UserMessage.createInfo("Country"),
UserMessage.createInfo("'Country' will be put at the end after concatenation."),
DefaultDataTypes.STRING,
false);
private static final InputDefinition INPUT_CITY = new InputDefinition(
"city",
UserMessage.createInfo("City"),
UserMessage.createInfo("'City' will be put before 'Country' after concatenation."),
DefaultDataTypes.STRING,
false);
private static final InputDefinition INPUT_STREET = new InputDefinition(
"street",
UserMessage.createInfo("Street"),
UserMessage.createInfo("'Street' will be put before 'City' after concatenation."),
DefaultDataTypes.STRING,
false);
private static final InputDefinition INPUT_NUMBER = new InputDefinition(
"number",
UserMessage.createInfo("Number"),
UserMessage.createInfo("'Number' will be put at the beginning after concatenation."),
DefaultDataTypes.INTEGER,
false);
private static final OutputDefinition OUTPUT_ADDRESS = new OutputDefinition(
"address",
UserMessage.createInfo("Output address"),
UserMessage.createInfo("Output address description"),
DefaultDataTypes.STRING,
false);
public InputDefinition getInputDefinition()
{
return new InputDefinition(
"Complex input name",
"Complex input label",
"Complex input description",
Arrays.asList(INPUT_COUNTRY, INPUT_CITY, INPUT_STREET, INPUT_NUMBER));
}
public OutputDefinition getOutputDefinition()
{
return OUTPUT_ADDRESS;
}
public TransformationFunction<GenericDataObject, String> getFunction()
{
return new TransformationFunction<GenericDataObject, String>()
{
public String transform(TransformationExecutionContext<GenericDataObject> context)
throws DataIntegrationException
{
GenericDataObject inputValue = context.getInputValue();
String country = inputValue.getValue(INPUT_COUNTRY.getName());
String city = inputValue.getValue(INPUT_CITY.getName());
String street = inputValue.getValue(INPUT_STREET.getName());
Integer number = inputValue.getValue(INPUT_NUMBER.getName());
String output = MessageFormat
.format("{0} {1} street, {2} city, {3}", number, street, city, country);
return output;
}
};
}
}
The following is an example of a custom transformation function with a generic output structure:
public class SplitStringComplexOutput implements TransformationDefinition<String, GenericDataObject>
{
InputDefinition INPUT_STRING = new InputDefinition(
"Information",
DintAPIInfoMessages.get_Dint_Transform_StringSplitFunction_Input_Name(),
DintAPIInfoMessages.get_Dint_Transform_StringSplitFunction_Input_Description(),
DefaultDataTypes.STRING,
false);
private static final OutputDefinition OUTPUT_STRING = new OutputDefinition(
"Name",
UserMessage.createInfo("Name"),
UserMessage.createInfo("Name description"),
DefaultDataTypes.STRING,
false);
private static final OutputDefinition OUTPUT_INTEGER = new OutputDefinition(
"Age",
UserMessage.createInfo("Age"),
UserMessage.createInfo("Age description"),
DefaultDataTypes.INTEGER,
false);
public InputDefinition getInputDefinition()
{
return this.INPUT_STRING;
}
public OutputDefinition getOutputDefinition()
{
return new OutputDefinition(
"Complex output",
"Complex output label",
"Complex output description",
Arrays.asList(OUTPUT_STRING, OUTPUT_INTEGER));
}
public TransformationFunction<String, GenericDataObject> getFunction()
{
return new TransformationFunction<String, GenericDataObject>()
{
public GenericDataObject transform(TransformationExecutionContext<String> context)
throws DataIntegrationException
{
String inputValue = context.getInputValue();
List<String> results = Arrays
.asList(inputValue.split(Pattern.quote(this.separator)));
String name = results.get(0);
Integer age = Integer.valueOf(results.get(1));
GenericDataObject complexData = GenericDataObject.newInstance();
complexData.setValue(OUTPUT_STRING.getName(), name);
complexData.setValue(OUTPUT_INTEGER.getName(), age);
return complexData;
}
};
}
}
Please refer to the corresponding package for the detail and examples.-
Interface Summary Interface Description GenericDataObject Represents the value structure of a generic input or output of a transformation.TransformationConfigurationContext Allows to access the configuration of a transformation.TransformationDefinition<I,O> Definition of a transformation.TransformationExecutionContext<I> Accesses the data to be transformed.TransformationFunction<I,O> Transforms data based onTransformationDefinition. -
Class Summary Class Description InputDefinition The definition of a transformation's input.OutputDefinition The definition of a transformation's output.ParameterDefinition The definition of a transformation's parameter.TransformationRegistry RegistersTransformationDefinitions to be displayed in the mapping screen. -
Enum Summary Enum Description TransformationCategory Categories of transformations.