Sunday, 3 July 2016

BizTalk Mapper/Transformation | Basic Concepts - Part2


This is my second article on BizTalk Basic Concepts, Here,in this article, I would brief about Transformation using BizTalk Maps and where all these transformation can be executed inside BizTalk. 

BizTalk Mapper/Transformation

Maps or transformations are one of the most common components in the integration processes. We will focus only in the process of mapping and transformation of messages. 

The map editor, BizTalk Mapper Designer, enables us to perform transformations of complex messages in a visual and extremely simple way, expressed in graphics associations of links that define the relationships between the various elements of messages.These relationships between elements are internally implemented as XSL Transformations (XSLT - Extensible Stylesheet Language Transformation) which is the standard recommended by Worldwide Web Consortium (W3C) to perform transformations between XML schemas. 
Maps can be used for processing messages received at a receive port, inside orchestrations or for processing messages sent to a send port, as the following figure suggest:


The editor consists essentially of three modules: 
Source Schema view: this is the data structure of the source message and is on the left side of the main window 

Destination Schema view: this is the data structure of the target message and is on the right side of the main window; The links that define the mapping lead into the destination schema tree view from the grid view, and ultimately from the source schema tree view. 

Mapper Grid view: is in the middle of the main window, between the two data structures (source and target); This area plays a critical role in the definition of maps, containing the links and functoids that control how data in a source instance message is transformed into an instance message that conforms to the destination schema. The grid view can have multiple layers, called grid pages, allowing you to organize complex maps into logical subdivisions of mappings and are accessible through the tabs that are at the bottom of the mapper grid view. 




BizTalk Mapper provides an extensive set of functoids that can be used in maps to perform a variety of operations on data that is being mapped from a source instance message to a destination instance message.

By default, the functoids are organized into nine categories based on their intended purpose: 
  • Advanced Functoids: used to create various types of data manipulation, such as implementing custom script (C#, Visual Basic .NET, XSLT), value mapping, and managing and extracting data from looping records.
  • Conversion Functoids: used to convert data, such as: convert ASCII to characters or to convert numbers from one base to another (hex, decimal). 
  • Cumulative Functoids: used to perform various types of accumulation operations for values that occur multiple times within an instance message. 
  • Database Functoids: used to look up data from a database and to perform simple cross-referencing operations (sometimes called ID mapping). 
  • Date and Time Functoids: this is a set of operations applicable on dates like, add date, time, date and time, or add days to a specified date, in output data. 
  • Logical Functoids: used to conditionally control the behavior of other functoids and to determine whether particular output data is created. 
  • Mathematical Functoids: used to perform specific numeric calculations such as addition, multiplication, and division. 
  • Scientific Functoids: used to perform specific scientific calculations such as logarithmic, exponential, and trigonometric functions. 
  • String Functoids: used to manipulate data strings (text alphanumeric) by using well-known string functions such as concatenation, length, find, and trim. 
BizTalk allows even to create our own custom functoids. 

To create a new map within a BizTalk project 
Right-click a BizTalk project in Solution Explorer, click Add, and then click Add New Item. 
In the Add New Item dialog box, in the Templates area, click Map. 
Select the text in the Name box, type a name for the map, and then click Open. 
In BizTalk Mapper, in the left pane, click Open Source Schema. 
In the BizTalk Type Picker dialog box, expand the Schema node in the tree, if necessary, select the appropriate source schema, and then click OK. And the source schema opens in the right pane. 
In BizTalk Mapper, in the right pane, click Open Destination Schema. 
In the BizTalk Type Picker dialog box, expand the Schema node in the tree, if necessary, select the appropriate destination schema, and then click OK. And the destination schema opens in the right pane. 
Transformation using Functoids 
Drag-and-drop the element in the source schema to the element in the destination schema either directly or using an appropriate functiods. Here, we would touch base with most commonly used functiods like look-up, value extractor and scripting functiod. 
Database Look-Up and Value Extractor
The Database Lookup Functoid requires four parameters. The first parameter is used in the search criteria. To configure this parameter, drag and drop the ProductName node from the source schema onto the left side of the functoid. The second parameter is a full connection string for the database with a provider, machine name, database and authentication. The third parameter is the name of the table used in the search. And finally, the fourth parameter is the name of the column used in the search criteria. 
Now drag and drop a Value Extractor functoids from Database Functoids tab in the Toolbox onto the map surface for each extracted value from the return record set, in this case, the ProductID column from the Product table. Then, connect the left side of the Value Extractor to the right side of Database Lookup. Finally, in Value Extractor functoid, create a constant with the name of the extracted column.
Scripting Functiod
The Scripting functoid enables you to use custom script or code at run time to perform functions otherwise not available. 
External Assembly: It allows us to associate this functoid with an existing function in assembly published on Global Assembly Cache (GAC). 
Inline C#: This option allows us to associate and invoke C# code directly into the functoid. 
Inline JScript .NET: Same as above but using code JScript .NET 
Inline Visual Basic .NET: Same as above but using code Visual Basic .NET 
Inline XSLT: This option allows us to associate the Scripting functoid with XSLT. 
Inline XSLT Call Template: identical to the above, however it allows us to associate and call XSLT templates directly into the functoid.
Click on the Advanced Functoids tab, and drag and drop the Scripting functoid onto the map surface. This functoid's input and output values are dependent of the logic contained within the Scripting functoid. Connect the left side of Scripting functoid to the appropriate source data items as well as the right side to the destination data items.

Now let's configure the Scripting functoid by right-click over it and selecting Configure Functoid Script option, when the Configure Functoid Script dialog is displayed, select Inline C# for Script Type. Then enter the business logic written in C# in the Inline script buffer textbox 
Testing and Validation of maps (at design time) 

At design time we have, included in Visual Studio, 3 features that allow us to test and validate the maps:
  1. Test Map: Tests the selected map. 
  2. Validate Map: Validates the map 
  3. Debug Map: If a map is compiled successfully, Debug Map launches the XSLT debugger. It allows you to step through the generated XLST, just like any other Visual Studio debugger. These features are available to developers in an easy manner and directly of the development tool, Visual Studio, without the need to build and deploy the maps or even create and configure ports.
Test Map
For this we only need to configure the properties of the map before we execute the test:
  • Right-clicking the map name and select Properties option; 
  • In the Properties window set “TestMap Input Instance” property with the path to the input file. 
  • Set the value to False for both validate TestMap Input and Output properties to test partially developed maps 
Debug Map
This option allows us debugging a map, thereby facilitate the identification and correction of complex problems of mapping at design time. Debugging a map is very straightforward, and can be useful in many situations. When debugging the map, the Debug Map feature uses the map file properties, such as TestMap Input Instance and TestMap Output Instance. Therefore, before you debug the map, it is recommend that you configure the input and output instance properties on the map file. 

To perform this option, we need to: 
  • In Solution Explorer, right-click the map you want to test, and then click Debug Map. Visual Studio displays the map in XSLT format in its editor. 
  • Press F10 or F11 to debug the XSL code. 
    • When you press F11 on a functoid call, Visual Studio steps into the C# code for the functoid. You can view the values of variables used in the functoid source code in the Locals debugger window. 
  • Standard debug shortcuts apply, including: F9 to toggle a breakpoint and F5 to continue 

Conclusion
In this article, you have seen 
  • Overview of BizTalk Map Editor and basic funtoids. 
  • How to Create, Test and Debug map. 
  • Implement business logic related to the transformation using functiods like DB-Lookup, Scripting and Iterative Functiods.
The video demonstration is available on the Youtube, here is the embedded video.



No comments:

Post a Comment

Note: only a member of this blog may post a comment.