Using Extension XML to Transform Data

There are several techniques within Data Hub to change data. The techniques used within an extension XML file are here.

You can use simple expressions, SpEL expressions, and/or custom SpEL expressions provided by SAP Commerce Cloud to modify, alter, or disable XML attribute definitions.

Using a Simple Expression

You have a RawItem called integrationKey. However, in your canonical data model, you want the item to be known as customerId. To accomplish this renaming, you use a simple expression. Look at the following XML taken from the canonicalExtension.xml file. The attribute is first declared as customerId, which is going to be its label within the canonical data model. Then, when you look at the transformation, you see the RawCustomer is the type source in the raw data mode. The integrationKey is the data source in the raw data model. After the transformation occurs, the integrationKey in the raw data model is now known as the customerId in the canonical data model.

                <attribute>
                    <name>customerId</name>
                    <model>
                        <localizable>false</localizable>
                        <collection>false</collection>
                        <type>String</type>
                        <primaryKey>true</primaryKey>
                    </model>
                    <transformations>
                        <transformation>
                            <rawSource>RawCustomer</rawSource>
                            <expression>integrationKey</expression>
                        </transformation>
                    </transformations>
                </attribute>

Using SpEL Expressions in Extension XML

The Spring Expression Language (SpEL) is a powerful data modification tool that you can use in your canonicalItem.xml file. First you modify the expression tag by adding the spel attribute and setting it to "true". Then you add your value followed by the SpEL expression you are using. The full range of SpEL options are supported.

<canonicalItems>
    <item>
        <type>CanonicalCustomer</type>
        <attributes>
            <attribute>
                <name>customerId</name>
                <transformations>
                    <transformation>
                        <rawSource>RawCustomer</rawSource>
                        <expression spel="true">name + "_" + accountGroup + "_" + country</expression>
                    </transformation>
                </transformations>
            </attribute>
        </attributes>
    </item>
</canonicalItems>

Using the resolve Function

The resolve() function is a custom SpEL function. It is a lookup function. General usage of the resolve() function is: resolve('<type_code>'[, '<pool_name>'][, 'integrationKey=<value>' | '<primary_key_attribute>=<value>',...]). These terms are defined as:
  • <type_code> is a type code of a referenced CanonicalItem
  • <pool_name> is the name of the data pool where the referenced object exists. If pool name is not specified explicitly, then the referenced object resolves in the same data pool where the context object exists. If the context object is not an instance of a CanonicalItem, then the default GLOBAL pool is used.
  • integrationKey=<value> specifies the integration key value of the referenced item instead of deriving it implicitly from the expression context. As an alternative, you may specify values of all primary key attributes in the function call.
For example, you create and load a named pool with a lookup table called CanonicalCountry full of country codes. You also have a pool of raw items that contain country names. When you compose the raw items with country names, you use the resolve() function to look up and replace the country name with the corresponding country code. The XML in the canonicalItem.xml file looks like:
<attribute>                           
    <name>countryName</name>
    <localizable>false</localizable>
    <collection>false</collection>
    <transformationExpression>resolve('CanonicalCountry')?.code</transformationExpression>
    <exportCode>town</exportCode>
    <mandatoryInHeader>true</mandatoryInHeader>
</attribute>

Overriding or Disabling Target Attribute Definitions

Sometimes your target extension setup just needs a minor adjustment to work fine for a different job. Rather than re-create the entire extension, you can create a custom extension that modifies your original extension definition. In the custom extension, you use the XML override attribute to modify the target attribute or the XML disable attribute to ignore the target attribute altogether. In the following code snippet, you see <attribute override="true">. You can now change the values of any of the subsequent fields in this attribute. The target extension adopts those changes. In a similar way, if your XML said <attribute disable="true">, this target attribute would be completely ignored.

         <targetItems>
            <item>
               <type>ApparelProduct</type>
               <exportCode>ApparelProduct</exportCode>
               <description>Hybris Platform representation of apparel product</description>
               <updatable>true</updatable>
               <canonicalItemSource>CanonicalProduct</canonicalItemSource>
               <status>ACTIVE</status>
               <attributes>
                  <attribute override="true">
                     <name>baseName</name>
                     <localizable>true</localizable>
                     <collection>false</collection>
                     <transformationExpression>baseName</transformationExpression>
                     <exportCode>name</exportCode>
                     <mandatoryInHeader>false</mandatoryInHeader>
                  </attribute>

Overriding or Disabling Canonical Attribute Definitions

Sometimes your canonical extension setup just needs a minor adjustment to work fine for a different job. Rather than re-create the entire extension, you can create a custom extension that modifies your original extension definition. In the custom extension, you use the XML override attribute to modify the transformation expression of the canonical attribute or the XML disable attribute to ignore the target attribute altogether. In the following code snippet, you see <attribute override="true">.

You can now change the values of the transformationExpression. The canonical extension adopts those changes. In a similar way, if your XML said <attribute disable="false">, the transformationExpression of this canonical attribute is completely ignored.