Skip to main content

Transformation (Optional)

Overview​

Defines which column values should be changed before import. There are two ways to apply a transformation:

  • By column name: a global transform, applied to any column matching the column attribute.
  • By id: a targeted transform, only applied when a value mapping explicitly references the transform by transformId.
<transformations>
<transformation id="transform_country" column="Country" value="substring(@Country, 4,2)"/>
</transformations>

<context>
<mapping id="product_context_mapping">
<attribute name="country">
<value type="row_value" column="Country" transformId="transform_country" />
</attribute>
</mapping>
</context>

Transformation by XPath​

Supports XPath 1.0 functions. Available in all versions.

See: https://www.edankert.com/xpathfunctions.html

<transformations>
<transformation column="ArticleNumber" value="concat(substring('0000000000', 1, 10 - string-length(@ArticleNumber)), @ArticleNumber)"/>
</transformations>

Transformation by a Plugin Method​

<transformation column="Range" value="plugin(globalName='com.priint.project.demo.datamapping.TransformPlugin',methodName='getRangeValue')" />

Implement a plugin method with a single Map<String, Object> parameter. The map contains column name as key and column value as value.

package com.priint.project.demo.datamapping;

@Stateless(mappedName = TransformPlugin.MAPPED_NAME)
@LocalBean
@PubServerPlugin
public class TransformPlugin {
public static final String MAPPED_NAME = "com.priint.project.demo.datamapping.TransformPlugin";
/**
* return range cell value if not empty, otherwise return type cell value
* @param cellValueMap key=column name, value is column value
* @return a string after change
*/
public String getRangeValue(Map<String, Object> cellValueMap) {
String result = (String) cellValueMap.get("Range");
if (StringUtils.isBlank(result))
result = (String) cellValueMap.get("Type");
return result;
}
}

Transformation by a Static Method​

<transformation column="Range" value="static(className='com.priint.project.demo.utils.TransformUtils',methodName='getRangeValue')"/>
package com.priint.project.demo.utils;

public class TransformUtils {

/**
* return range cell value if not empty, otherwise return type cell value
* @param cellValueMap key=column name, value is column value
* @return a string after change
*/
public static String getRangeValue(Map<String, Object> cellValueMap) {
String result = (String) cellValueMap.get("Range");
if (StringUtils.isBlank(result))
result = (String) cellValueMap.get("Type");
return result;
}
}

Deploy it as a .jar library in /pubserver/lib.