Preface
The TIBCO Flogo for TIBCO BusinessWorks Developers series of articles aims to familiarize BusinessWorks developers with TIBCO Flogo in order to better utilize these complementary technologies. Each article is focused on a specific key common behavior or feature that is often used in a BusinessWorks project. It takes that common behavior and replicates that in Flogo.
Mapping
In this article, we will take a look at Mapping. There are multiple different mapping types within BusinessWorks that are commonly used. We will touch on each of these.
To further help us illustrate these mappings, we will make use of two simplistic schemas. The first schema is of customers. This schema is set with initial data in the first activity of the process or flow. Each element of the schema is named and should be self-explanatory.
BW5
BW6/CE
Flogo
The second schema is a membership schema. This groups the customers from the customers schema into a goldMember or platinumMember based on some business logic that we will get into later.
BW5
BW6/CE
Flogo
These schemas are used in the applications in BW5, BW6/CE and Flogo. The application logic is simple. It is triggered by a run-once timer. It will then proceed to initialize the Customers schema using a Mapper activity with the initial data as shown above. The next activity uses another mapper to map the values from the Customers schema to the Membership schema using various methods. It then prints out the result of the initial Customers Schema and the mapped Membership Schema.
BW5
BW6/CE
Flogo
Let us focus on the details of the mapping in the MappedData activity. Below, we will show the full mapping done in both BW5 and BW6/CE.
BW5
BW6/CE
We will go through each of these in detail when done in Flogo.
The goldMember mapping is really an iteration of the Customers element. It will allow customers with a dollarSpent of more than 0 and less than 10000. In Flogo, we achieve this by dragging the Customers array to the goldMember array. This will establish an iteration like the for-each in BW. Additionally, the filter logic within BW housed in the square brackets is represented in the Filter By section of this iteration.
A few things to note. The exists() function in BW is the isdefined() function in Flogo. When we establish the iteration, in this case from the Customers element, the scope of the Customers is put in the $loop object. So, to refer to elements within the iteration, we use the $loop with the subsequent element name. For example, $loop.Customer.dollarSpent refers to dollarSpent element of the current iteration of Customer under Customers. The keyword “and” is represented by “&&” in Flogo. Also take note that the iteration is assigned a Loop Name of goldMember. The Loop Name uses the same name as the element by default but can be changed. We will refer back to the loop name in subsequent mapping.
Once this iteration is established, we can then map the name element from the Customer over to the name element of the goldMember like below.
We next need to map the altName or alternate name. Notice that this is a repeating element on both schemas. In BW, we use a for-each to map this over. In Flogo, we can map this over like any other element. Given that the name and type is the same, it is implied that the whole array is mapped over. Another thing to take note here is that the loop name is used. Because this is an array to array mapping, the implicit context in $loop is now changed to that level. So, in order for us to refer to the parent loop, in this case, the Loop Name goldMember, we specify $loop[goldMember] instead of just using $loop.
The next element that we need to map is the homeMailLabel.This draws from the repeating address element from the Customer. Specifically for the homeMailLabel, we only want to map the address of the type “home” and an address with an activeFlag of true. We specify these conditions in the Filter By configuration.
Looking further into this mapping, we have the name element under the homeMailLabel that needs to get the value from the parent element of the iteration. In BW, we use “../<<element name>>” to get to this value. In Flogo we use the “$loop[<<parent loop name>>]” or “$loop[goldMember]” to get to this parent value.
To map the platinumMember, the rest of the logic is generally the same. This illustrates that a single array data source can be used to map to multiple arrays with different criterias.
With these mapping done, we see that all three projects, produces the same result (barring that BW is XML based and Flogo is JSON based).
BW5
BW6/CE
Flogo
All three projects coded in BW 5.15.1, BWCE 2.9.1 and Flogo 2.24.0 using the Visual Studio Code Extension are provided below for your reference.
BW_5_15_1-F4BWDev-Mapping.zip BWCE_2_9_1-F4BWDev-Mapping.zip F4BWDev-Mapping.flogo
Recommended Comments
There are no comments to display.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now