DataMapperExpressionConverterFormat definition examples

This topic provides a description and example definitions of the DataMapperExpressionConverterFormat formatter.

The DataMapperExpressionConverterFormat class extends the DataMapperConverterFormat class to support mapping from expression manipulation to context value.

The expression is a JavaScript snippet which supports multiple data types such as constants, context value, global function and expression, also supported nested expressions.

The DataMapperExpressionConverterFormat definition contains a new attribute, "fromExpression”, whose value is an expression. WebSphere® Multichannel Bank Transformation Toolkit contains a new JavaScript evaluation engine to execute the expression and return a result. If the result is a WebSphere Multichannel Bank Transformation Toolkit data element, then it will be mapped to another data element which defined in the “to” attribute. If the result is a pure Java object, then it will be mapped to a data field which defined in the “to” attribute.

A DataMapperExpressionConverterFormat expression can be derived from the mapping tooling that is included in the Transaction Editor. In the expression, escape characters might be used that cannot be easily understood by end users; for example, a dollar sign ($) might be used instead of a dot (.) when specifying data paths so that “preson$address$street” is used instead of “preson.address.street” in expressions. A dot (.) is used in expressions for function separating character such as functs_BTTGlobalFunctions.concat(param1,param2). It is strongly recommended that you create or modify expressions by using WebSphere Multichannel Bank Transformation Toolkit tooling instead of by manually creating or modifying the expressions.

The DataMapperExpressionConverterFormat class can also be extended to support mapping between two contexts and to support mapping between a context and a keyed collection. In such cases, the mapping elements of the source and target should have same name.
Note: In the mapper definitions, an asterisk (*) is used to specify a context.

Mapping from a manipulated value to a data field

This example also shows how to use an expression such as adding two different data values:
<fmtDef id="mappingFmt31">
	<mapperConverterExpression>
		<map fromExpression="accountList$0$name" to="fisherMan.name" />
		<map fromExpression="byteField1 + byteField2" to="byteField" />
	</mapperConverterExpression>
</fmtDef>

Mapping from a manipulated data element to another data element

This example also shows how to use global functions. The getRowByIndex global function is used to return an element in an IndexedCollection by index:
<fmtDef id="mappingConditionGetRowByIndex">
	<mapperConverterExpression>
		<map fromExpression="functs_BTTGlobalFunctions.getRowByIndex(iColl01,2)"
			to="iCollField01" />
	</mapperConverterExpression>
</fmtDef>

Mapping between contexts

A Keyed collection from a source context is shown here:
<kColl id="CustomerInfo" dynamic="true">
  <field id="username"  />
  <field id="age" />
<field id="address" />
</kColl>
A Keyed collection from a target context is shown here:
<kColl id="CustData" dynamic="true">
  <field id="username"  />
<field id="age" />
<field id="gender" />
</kColl>
The definition of the mapper that is required to map the keyed collection from the source context to the keyed collection of the target context is shown here:
<fmtDef id="mappingConditionGetRowByIndex">
	<mapperConverterExpression>
		<map from="*"  to="*"/>
	</mapperConverterExpression>
</fmtDef>
In the definition of the mapper shown above, the “username” and the “age” fields are mapped because the names of the field elements are the same in the source context and the target context. Data elements that have different names between the source context and the target context are not mapped.

Mapping between a context and a keyed collection

A keyed collection from a source context is shown here:
<kColl id="AccountInfo" dynamic="true">
 	 <field id="accountNumber"  />
	 <field id="balance" />
</kColl>
A keyed collection from a target context is shown here:
<kColl id="CustomerInfo" dynamic="true">
  <field id="name"  />
  <field id="age" />
<field id="address" />
<kColl id="Account" >
	  <field id="accountNumber"  />
	  <field id="balance"  />
</kColl>
</kColl>
The definition of the mapper that is required to map the root keyed collection of the source context to the inner keyed collection of the target context is shown here:
<fmtDef id="mappingConditionGetRowByIndex">
	<mapperConverterExpression>
		<map from="*"  to="Account"/>
	</mapperConverterExpression>
</fmtDef>

Mapping between contexts with an inner indexed collection and a keyed collection

A keyed collection from a source context is shown here:
<kColl id="CustomerInfo" dynamic="true">
  <field id="name"  />
  <field id="age" />
<kColl id="Account" >
	  <field id="accountNumber"  />
	  <iColl id="SubAccountsList" >
	  	 <kColl >
				<field id="acctID" />
			    <field id="balance" />
 </kColl>
</iColl>
 </kColl>
</kColl>
A keyed collection from a target context is shown here:
<kColl id="UserInfo" dynamic="true">
  <field id="name"  />
  <field id="address" />
<kColl id="Account" >
	  <field id="accountNumber"  />
	  <iColl id="SubAccountsList" >
	  	 <kColl >
				<field id="acctID" />
			    <field id="balance" />
 </kColl>
</iColl>
 </kColl>
</kColl>
In Figure 1, the whole context is mapped to the target context, including both the inner keyed collection and the inner indexed collection.
Figure 1. Mapper definition 1
<fmtDef id="mappingConditionGetRowByIndex">
	<mapperConverterExpression>
		<map from="*"  to="*"/>
	</mapperConverterExpression>
</fmtDef>
In Figure 2, only the “SubAccountsList” inner indexed collection is mapped.
Figure 2. Mapper definition 2
<fmtDef id="mappingConditionGetRowByIndex">
	<mapperConverterExpression>
		<map from="Account.SubAccountsList" 
 to="Account.SubAccountsList"/>
	</mapperConverterExpression>
</fmtDef>
For more information on data mapper formatters, see DataMapperConverterFormat definition examples.