2. Translators
A translator defines a logic for data manipulation.
Data manipulation can occurs in the following scenarios:
₋ Importing outside data into Cenit
₋ Updating data already stored in Cenit
₋ Converting data already stored in Cenit
₋ Exporting data outside Cenit
3. Translators
Translate input data
into data types
records
Convert records
between data
types
Update data type
records
Translate data type
records into
outgoing data
4. Import Translators
Import translators create data type
records from outside data.
The target data type defines the
type of the records to be created.
If no target data type is defined then
the translator is supposed to be able
to import data into any data type.
The logic of an import translator is
described in ruby style
5. Import Translators: target data type
Import translators create data type
records from outside data.
The target data type defines the
type of the records to be created.
If no target data type is defined then
the translator is supposed to be able
to import data into any data type.
The logic of an import translator is
described in ruby style
6. Import Translators: ruby style
Import translators create data type
records from outside data.
The target data type defines the
type of the records to be created.
If no target data type is defined then
the translator is supposed to be able
to import data into any data type.
The logic of an import translator is
described in ruby style
7. Import Translators: ruby style
The translator transformation is written in a DSL based on the Ruby
Programming Language.
The variables data and target_data_type are available and represent
the outside data and the target data type respectively.
A simple JSON importer can be defined by the following transformation:
8. Import Translators: ruby style
A little more of transformation code allows to parse the outside data and to
create multiple records:
9. Import Translators: ruby style
There are several methods available on the target data type object that can be
invoked to create records. They all have the following pattern:
(create|new)_from_(json|xml|edi)[!]
Example: create_from_xml, new_from_edi
The new methods does not persist the created record an a further invocation
of a save method is needed.
The create methods attempt to persist the records, halting on error only if
the method name ends with the exclamation symbol.
10. Import Translators: ruby style
The following transformation parse a data using Nokogiri and creates one or
multiple records from XML document elements:
11. Export Translators
Export translators format data type
records into data going outside
Cenit.
The source data type defines the
type of the records to be formatted.
If no source data type is defined then
the translator is supposed to be able
to format records of any data type.
A MIME type can be optionally
defined.
12. Export Translators
Export translators format data type
records into data going outside
Cenit.
The source data type defines the
type of the records to be formatted.
If no source data type is defined then
the translator is supposed to be able
to format records of any data type.
A MIME type can be optionally
defined.
13. Export Translators
Export translators format data type
records into data going outside
Cenit.
The source data type defines the
type of the records to be formatted.
If no source data type is defined then
the translator is supposed to be able
to format records of any data type.
A MIME type can be optionally
defined.
14. Export Translators: ruby style
The translator transformation can be written in ruby style.
Depending on the translator having the option bulk source, the variable
source or sources is available representing a single record or an
enumeration of records to be formatted.
A simple non bulkable JSON exporter can be defined by the following
transformation:
15. Export Translators: ruby style
If the translator is bulkable a little more of transformation code is needed to
format all the source records into a single JSON data:
Note: the result of the translation execution is the value of the latest
evaluated expression.
16. Export Translators: ruby style
There are a set of predefined methods available on record objects that can be
used for basic formats:
to_(json|xml|edi)
Every formatter method can receive options, for example:
- source.to_json(pretty: true)
- source.to_xml(with_blanks: true)
- source.to_edi(field_separator: ‘+’)
17. Export Translators: ruby style
The variable source_data_type is a reference to the translator source
data type and for facility a method to_xml_array have been added to
records enumeration, so a transformation for bulkable XML exporter can be
written as following:
18. Export Translators: XSLT style
The logic of an export translator can
be described as an XML Stylesheet
transformation.
XSLT style translators are no
bulkable.
Cenit convert the source record to
XML format if necessary and the
applies the XSLT transformation.
19. Export Translators: XSLT style
The following XSLT transformation changes the value of every attribute with
name email by sample@mail.com:
20. Update Translators
Update translators update data type
records.
The target data type defines the
type of the records to be updated.
If no target data type is defined then
the translator is supposed to be able
to update records of any data type.
The logic of an import translator is
described in ruby style.
21. Update Translators
Update translators update data type
records.
The target data type defines the
type of the records to be updated.
If no target data type is defined then
the translator is supposed to be able
to update records of any data type.
The logic of an import translator is
described in ruby style.
22. Update Translators
Update translators update data type
records.
The target data type defines the
type of the records to be updated.
If no target data type is defined then
the translator is supposed to be able
to update records of any data type.
The logic of an import translator is
described in ruby style.
23. Update Translators: ruby style
Update translators are non bulkable so they are applied to a single target
record which is available through the variable target:
24. Conversion Translators
Conversion translators transform
records into others.
The source and target data types
defines the records conversion
types.
The logic of an import translator can
be described in several format: ruby,
XSLT and chain.
25. Conversion Translators
Conversion translators transform
records into others.
The source and target data types
defines the records conversion
types.
The logic of an import translator can
be described in several format: ruby,
XSLT and chain.
26. Conversion Translators
Conversion translators transform
records into others.
The source and target data types
defines the records types.
The logic of an import translator can
be described in several format: ruby,
XSLT and chain.
27. Conversion Translators: ruby style
Conversion translators are non bulkable so they convert a record at the time.
The source and target records are available through the variables target
and source. Converting a costumer from a message would be as simple as:
28. Conversion Translators: XSLT style
Even if records are not stored in XML format an XSLT transformation is
possible for Cenit by the following steps:
1. Format the source record into XML if necessary.
2. Applies the XSLT transformation to the XML formatted record.
3. Create a target data from the transformed XML document.
29. Conversion Translators: chain style
Chain style convert records by
concatenating two conversion
translator:
⁻ The source exporter: convert the
source record to an intermediate
data type.
⁻ The target importer: convert the
intermediate record to the target
data type.
30. Conversion Translators: chain style
Chain style convert records by
concatenating two conversion
translator:
⁻ The source exporter: convert the
source record to an intermediate
data type.
⁻ The target importer: convert the
intermediate record to the target
data type.