Canonical Item Data Structure
Canonical data structure is completely independent of source or target system data structures. It provides a single source of truth for your data, allowing it to be published to a wide range of target systems. It is entirely up to you how you model this canonical view.
Canonical data is composed from raw data fragments in the data pool. The resultant canonical item structure should provide a view of your data that is logical and easy to refer to. Canonical item structure should enable you to easily publish data to any target system, and therefore not be tied to any one system. Similar to raw item structure, canonical item structure is defined in your canonical-item.xml file.
Canonical item metadata defines canonical item types, and each of these types contains one or more attributes. Canonical item attributes are populated with the content of a corresponding raw item attribute during composition. These attributes can have additional properties, including one that determines whether it is used as a primary key. Canonical data has a relational data structure, rather than flat.
But canonical item metadata provides more than just a model of the data structure. It also contains a definition of the mapping between raw item and canonical item attributes. This mapping is provided in the transformation tag for each attribute. The transformation contains the raw item and attribute names from which the canonical item data is to be taken.
Canonical Item XML
The following raw item XML shows a simple example of canonical item metadata. Similar to the raw item example, there are two items, CanonicalProduct and CanonicalCategory, each with three attributes.
<canonicalItems> <item> <type>CanonicalProduct</type> <description>Canonical representation of apparel product</description> <status>ACTIVE</status> <attributes> <attribute> <name>identifier</name> <model> <type>String</type> <primaryKey>true</primaryKey> </model> </attribute> <attribute> <name>baseName</name> <model> <type>String</type> <primaryKey>false</primaryKey> </model> </attribute> <attribute> <name>baseDescription</name> <model> <type>String</type> <primaryKey>false</primaryKey> </model> </attribute> </attributes> </item> <item> <type>CanonicalCategory</type> <description>Canonical representation of apparel category</description> <status>ACTIVE</status> <attributes> <attribute> <name>identifier</name> <model> <type>String</type> <primaryKey>true</primaryKey> </model> </attribute> <attribute> <name>name</name> <model> <type>String</type> <primaryKey>false</primaryKey> </model> </attribute> <attribute> <name>description</name> <model> <type>String</type> <primaryKey>false</primaryKey> </model> </attribute> </attributes> </item> </canonicalItems>
Here, the identifier attribute of each canonical item, which is of type String, is being used as a primary key. These additional properties, type and primaryKey, are provided in the model tag for each attribute. Note that transformations are not provided yet.
Transformations are provided in the transformations tag for each attribute. If provided in the same canonical-extension.xml file, they would appear with the other parts of the attribute definition. This example shows that the identifier is being taken from the attribute sourceId of the raw item RawProduct:
<canonicalItems> <item> <type>CanonicalProduct</type> <description>Canonical representation of apparel product</description> <status>ACTIVE</status> <attributes> <attribute> <name>identifier</name> <model> <type>String</type> <primaryKey>true</primaryKey> </model> <transformations> <transformation> <rawSource>RawProduct</rawSource> <expression>sourceId</expression> </transformation> </transformations> </attribute> </item>
However, there is a good reason to keep the transformations separate from the structure. We discuss this separation in the following section.
Structuring Your Canonical Metadata
Because the canonical data model should ideally have no dependencies on source or target data models, it is best practice to define canonical transformations separately. Transformations provide the mapping from raw to canonical items. They therefore have a dependency on the source system. Place these transformations in the raw item metadata XML file. You then keep all metadata that has a dependency on a particular source system together in one file. With this single file, you can easily replace the metadata for a new source system if needed, without affecting the canonical view in any way.
To place these canonical transformations into the raw-extension.xml file and have them work, there are a number of steps to follow:
- Place the following dependency at the head of your raw-extension.xml file, replacing the extension name with the name of your canonical metadata file.
<dependencies> <dependency> <extension>project-canonical-extension</extension> </dependency> </dependencies>
- Put canonical item definitions for all your canonical items into your raw-extension.xml file exactly as you did with the canonical-extension.xml file.
<canonicalItems> <item> <type>CanonicalProduct</type> <attributes> ... </attributes> </items> </canonicalItems>
- Populate the attributes list with canonical item attributes containing only the attribute name and transformations.
<attribute> <name>identifier</name> <transformations> <transformation> <rawSource>RawProduct</rawSource> <expression>sourceId</expression> </transformation> </transformations> </attribute> <attribute> <name>baseName</name> <transformations> <transformation> <rawSource>RawProduct</rawSource> <expression>baseName</expression> </transformation> </transformations> </attribute> ...
The name tag is essential. It is the link between the transformation, and the structural model of the attribute in your canonical-extension.xml file.