Introduction:
Business Process Execution Language (BPEL) is a XML-based language used to define enterprise business processes within Web services. BPEL extends the Web services interaction model and enables it to support business transactions. Processes written in BPEL can orchestrate interactions between Web services using XML documents. In order to accomplish this, maps such as XML map and BO (Business Objects) map could be used to convert data from one structure to another.
Below are the approaches to handle some mapping scenarios using XML map.
1) Handle complex logic using BPEL variables:
There may be scenarios where a complex logic are to be executed and the result of the logic need to be used as one of the condition in map. Executing the logic in iteration of the map may be complicated and also will impact performance.
Illustrated Scenario:
For instance, there is a java utility method that will return the employee ID of the “Best Employee of the Year”. This method implements a complex logic by analyzing various data and stats to arrive at the result. Expectation is to map the employee information using XML map in BPEL and set the isEmployeeOfTheYear element to true, if the employee is the “Best Employee of the Year” based on the utility method logic.
Mapping Approach:
Call the utility method and assign value to the ‘bestEmployeeID’ variable
Apart from input/output of the XML map, add an additional input element ’bestEmployeeID’ to the XML map
This is the ‘properties’ view of XML data map after the second input variable is added to the map.
Assign the bestEmployeeID to a map variable to get the reference inside for loop
Checking for condition inside the for loop to check if the current instance’s employee id is matching with best employee’s ID
If the condition matches then ‘true’ is assigned to isEmployeeOfTheYear element in output
Benefits of using this approach:
- This improves performance as we are not applying complex logic to derive bestEmployeeID, for every element in employee list.
- The complex logic to derive bestEmployeeID, has been secluded from BPEL’s XML map and hence maintainability is easy.
2) Using Map Variables:
Local map variables could be used in the below mentioned scenario.
- Pass additional details to a for-each apart from the list
- Use a derived object/list or value in any level of map, such as inside for-each, inside if/else scope, local map scope and so on.
Illustrated Scenario:
Basic requirement of this illustrated map is to map the employee list. The employee ID of the best employee of the year is passed as an additional input to the map. This information is needed inside for-each scope in order to set isBestEmployeeFlag inside for-each scope. If best employee id is passed as a supplementary input to for-each then we end up with an error. To avoid this error and also get the best employee id into for-each scope, map variable could be used. Error screenshot is below.
Mapping Approach:
Create a map variable and assign value to it using XPATH expression
Created map variable is available everywhere inside the map scope and hence can be used inside for-each scope.
Benefits of using this approach:
- When using map variable, we can avoid carrying a particular derived object into multiple levels of map such as If/else scope, for-each scope or local map scope.
- We can avoid error that happens while passing supplementary input to for-each
- By using map variable we can derive object/list or value once and make it available everywhere in map and thus avoid running the derivation logic in multiple places if map.
3) JOIN:
Join could be used to pass additional details to for-each apart from the primary array/list. Like, map variable Join is another way to pass additional input to for-each. XML map does not allow multiple inputs to for-each. If we need value of another object to population few element of the target List, then it can be accomplished to using “Join”. Both the List and the additional object could be passed as input to Join. Inside Join both the List and additional object will be available as Source along with target List. Mapping could be done as per the requirement.
Illustrated Scenario:
Basic requirement of this illustrated map is to map the employee list. The employee ID of the best employee of the year is passed as an additional input to the map. This information is needed inside for-each scope in order to set isBestEmployeeFlag inside for-each scope.
Mapping Approach:
Pass any additional information to map using Join
Use the additional information used inside the for-each scope
4) APPEND:
Append option could be used to map multiple single objects if same data type to an array or List.
Illustrated Scenario:
Map two employee objects to a list of employee object, thus forming a list out of multiple single objects of same type.