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="priint_product_name" value="substring(@priint_product_name, 4,2)"/>
</transformations>
...
<context>
<mapping id="default-context">
<attribute name="country">
<value type="row_value" column="priint_product_name" 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="Artikelnummer" value="concat(substring('0000000000', 1, 10-length(@Artikelnummer), @Artikelnummer))"/>
</transformations>

Transformation by a Plugin Method​

Version: 1.4.*

<transformation column="Range" value="plugin(globalName='com.priint.project.demo.somfy.datamapping.ImportTransformPlugin',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.

@Stateless(mappedName = ImportTransformPlugin.MAPPED_NAME)
@LocalBean
@PubServerPlugin
public class ImportTransformPlugin extends SomfyPlugin {
public static final String MAPPED_NAME = Constants.PACKAGE_NAME + "datamapping.ImportTransformPlugin";
private static final Logger logger = LoggerFactory.getLogger(ImportTransformPlugin.class);

/**
* 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) {
logger.debug("{}: getRangeValue: cell value map:{}", ImportTransformPlugin.class.getSimpleName(), cellValueMap);
String result = (String) cellValueMap.get("Range");
if (StringUtils.isBlank(result))
result = (String) cellValueMap.get("Type");
logger.debug("{}: getRangeValue: return value:{}", ImportTransformPlugin.class.getSimpleName(), result);
return result;
}
}

Transformation by a Static Method​

Version: 1.4.*

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

Same as the plugin method, but implemented as a static method. Deploy it as a .jar library in /pubserver/lib.

public final class TransformUtils {
private static final Logger logger = LoggerFactory.getLogger(TransformUtils.class);

private TransformUtils() {
throw new IllegalStateException("Utility class");
}

/**
* 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) {
logger.debug("{}: getRangeValue: cell value map:{}", TransformUtils.class.getSimpleName(), cellValueMap);
String result = (String) cellValueMap.get("Range");
if (StringUtils.isBlank(result))
result = (String) cellValueMap.get("Type");
logger.debug("{}: getRangeValue: return value:{}", TransformUtils.class.getSimpleName(), result);
return result;
}
}