Package com.orchestranetworks.addon.dataexchange.transformation
Classes and interfaces to call {addon.label} transformation functions to convert data for import, export and transfer.
Example of creating transformation function in the import, export XML and data transfer
You must define a custom transformation function before adding it to your code TransformationCatalog.
For example:
public final class TransformationDefinitionTest implements TransformationDefinition { public String getCode() { return "TRANSFORMATION_DEFINITION_TEST"; } public UserMessage getLabel() { return UserMessage.createInfo("Transformation function test"); } public UserMessage getDescription() { return UserMessage.createInfo("Transformation function test"); } public List<InputDefinition> getInputDefinitions() { List<InputDefinition> inputDefinitions = new ArrayList<InputDefinition>(); inputDefinitions.add(new InputDefinition( "Source field value", UserMessage.createInfo("Storing source field value."), SchemaTypeName.XS_INT, false)); return inputDefinitions; } public OutputDefinition getOutputDefinition() { return new OutputDefinition( UserMessage.createInfo("Storing target field value."), SchemaTypeName.XS_STRING, false); } public List<ParameterDefinition> getParameterDefinitions() { return new ArrayList<ParameterDefinition>(); } public Transformation getTransformation(Operation operation) { switch (operation) { case IMPORT_XML: return new XMLImportTransformationTest(); case EXPORT_XML: return new XMLExportTransformationTest(); case TRANSFER_DATA: return new TransferTransformationTest(); default: return null; } } public boolean isBidirectional() { return true; } public boolean isAggregation() { return false; } }
Next, create the implementation definition.
Example of import XML
public final class XMLImportTransformationTest implements Transformation<XMLImportTransformationExecutionContext> { public void setup(TransformationConfigurationContext configurationContext) throws DataExchangeException { } public Object execute(XMLImportTransformationExecutionContext executionContext) throws DataExchangeException { if (executionContext == null) { throw new DataExchangeException(UserMessage.createError("Context is not initialized.")); } Object inputValue = executionContext.getInputValue(); SchemaNode node = executionContext.getTargetSchemaNode(); if (inputValue == null) { return null; } try { if (Integer.class.isInstance(inputValue)) { return node.formatToXsString(inputValue); } if (String.class.isInstance(inputValue)) { String tmpValue = String.valueOf(inputValue); if (tmpValue == null) { return null; } return node.parseXsString(tmpValue); } throw new DataExchangeException(UserMessage.createError("Invalid input data.")); } catch (ClassCastException ex) { throw new DataExchangeException(ex); } catch (ConversionException ex) { throw new DataExchangeException(ex); } catch (Exception ex) { throw new DataExchangeException(ex); } } }
Example of export XML
public final class XMLExportTransformationTest implements Transformation<XMLExportTransformationExecutionContext> { public void setup(TransformationConfigurationContext configurationContext) throws DataExchangeException { } public Object execute(XMLExportTransformationExecutionContext executionContext) throws DataExchangeException { if (executionContext == null) { throw new DataExchangeException(UserMessage.createError("Context is not initialized.")); } Object inputValue = executionContext.getInputValue(); SchemaNode node = executionContext.getSourceSchemaNode(); if (inputValue == null) { return null; } try { if (Integer.class.isInstance(inputValue)) { return node.formatToXsString(inputValue); } if (String.class.isInstance(inputValue)) { String tmpValue = String.valueOf(inputValue); if (tmpValue == null) { return null; } return node.parseXsString(tmpValue); } throw new DataExchangeException(UserMessage.createError("Invalid input data.")); } catch (ClassCastException ex) { throw new DataExchangeException(ex); } catch (ConversionException ex) { throw new DataExchangeException(ex); } catch (Exception ex) { throw new DataExchangeException(ex); } } }
Example of transfer data
public final class TransferTransformationTest implements Transformation<TransferTransformationExecutionContext> { public void setup(TransformationConfigurationContext configurationContext) throws DataExchangeException { } public Object execute(TransferTransformationExecutionContext executionContext) throws DataExchangeException { if (executionContext == null) { throw new DataExchangeException(UserMessage.createError("Context is not initialized.")); } Object inputValue = executionContext.getInputValue(); SchemaNode node = executionContext.getSourceSchemaNode(); if (inputValue == null) { return null; } try { if (Integer.class.isInstance(inputValue)) { return node.formatToXsString(inputValue); } if (String.class.isInstance(inputValue)) { String tmpValue = String.valueOf(inputValue); if (tmpValue == null) { return null; } return node.parseXsString(tmpValue); } throw new DataExchangeException(UserMessage.createError("Invalid input data.")); } catch (ClassCastException ex) { throw new DataExchangeException(ex); } catch (ConversionException ex) { throw new DataExchangeException(ex); } catch (Exception ex) { throw new DataExchangeException(ex); } } }
Finally, the transformation function must be registered in the add-on in order to be available in the configuration:
TransformationCatalog.add(new TransformationDefinitionTest());
Example of creating aggregation transformation function
First, create the custom aggregation transformation function definition.
For example:
public class AggregationDefinitionTest implements TransformationDefinition { public String getCode() { return "AGGREGATION_DEFINITION_TEST"; } public UserMessage getLabel() { return UserMessage.createInfo("Aggregate of integer numbers"); } public UserMessage getDescription() { return UserMessage.createInfo("The sum of the input integers"); } public List<InputDefinition> getInputDefinitions() { List<InputDefinition> inputDefinitions = new ArrayList<InputDefinition>(); inputDefinitions.add(new InputDefinition( "Source field values", UserMessage.createInfo("List of input integers to calculate."), SchemaTypeName.XS_INT, true)); return inputDefinitions; } public OutputDefinition getOutputDefinition() { return new OutputDefinition( UserMessage.createInfo("The sum of the input integers."), SchemaTypeName.XS_INT, false); } public List<ParameterDefinition> getParameterDefinitions() { return new ArrayList<ParameterDefinition>(); } public Transformation getTransformation(Operation operation) { return new AggregationTransformationTest(); } public boolean isBidirectional() { return false; } public boolean isAggregation() { return true; } }
Next, the definition of the implementation must be created. For example:
public class AggregationTransformationTest implements AggregationTransformation { public void setup(TransformationConfigurationContext configurationContext) throws DataExchangeException { } public Object execute(AggregationTransformationExecutionContext executionContext) throws DataExchangeException { if (executionContext == null) { throw new DataExchangeException(UserMessage.createError("Context is not initialized.")); } List<AggregationTransformationExecutionValue> inputs = executionContext.getInputValues(); if (inputs == null || inputs.isEmpty()) { return inputs; } int sumOfInput = 0; for (AggregationTransformationExecutionValue executeValue : inputs) { if (executeValue == null || executeValue.getValue() == null) { continue; } sumOfInput += this.sumOfInput(executeValue.getValue()); } return Integer.valueOf(sumOfInput); } private int sumOfInput(Object inputValue) throws DataExchangeException { if (Integer.class.isInstance(inputValue)) { return ((Integer) inputValue).intValue(); } try { return Integer.valueOf((String) inputValue).intValue(); } catch (Exception ex) { throw new DataExchangeException(ex); } } }
Finally, the aggregation transformation function must be registered in the add-on in order to be available in the configuration:
TransformationCatalog.add(new AggregationDefinitionTest());
-
Class Summary Class Description AggregationTransformationExecutionValue Deprecated. Since 2.3.0, replaced byAggregationTransformationExecutionValue
.ApplicationType Defines possible application types.InputDefinition Deprecated. Since 2.3.0, replaced byInputDefinition
.OutputDefinition Deprecated. Since 2.3.0, replaced byOutputDefinition
.ParameterDefinition Deprecated. Since 2.3.0, replaced byParameterDefinition
.TransformationCatalog Deprecated. Since 2.3.0, replaced byTransformationCatalog
. -
Enum Summary Enum Description Operation