Wednesday, 21 December 2016

Switching DVM on the basis of "choose-when-otherwise" clause

What is DVM:
Domain value maps operate on actual data values that transit through the infrastructure at run-time. They enable you to map from one vocabulary used in a given domain to another vocabulary used in a different domain. For example, one domain may represent a city with a long name (Boston), while another domain may represent a city with a short name (BO).

#Use-Case:
Here, we have a simple use-case. We have two different DVMs. The only difference is one DVM has state code of 2 characters and another one has it of 3 characters.

Now, while testing if we pass "India" as country in 3rd parameter it will call a DVM which has 3 character state code otherwise it will call the next one.

To test your Domain Value Map use-case, first create a schema as shown below.


Now, create a XSL mapper file to map its (XSD) source node to target node. 



Now, create 2 DVM which are as belows:



Here is the XSL code:

<ns0:processResponse>    
<ns0:res_Name>        
<xsl:value-of select="/ns0:process/ns0:Name"/>      
</ns0:res_Name>      
<ns0:res_State>        
<xsl:value-of select="/ns0:process/ns0:State"/>      
</ns0:res_State>      
<xsl:choose>        
<xsl:when test="/ns0:process/ns0:Country='India'">          
<ns0:res_Country>            
<xsl:value-of select='dvm:lookupValue ("DVM/DVMwithQualifier.dvm", "State", /ns0:process/ns0:State,"StateCode", /ns0:process/ns0:State )'/>          
</ns0:res_Country>        
</xsl:when>        
<xsl:otherwise>          
<ns0:res_Country>            
<xsl:value-of select='dvm:lookupValue ("DVM/NormalDVM.dvm", "State", /ns0:process/ns0:State,"StateCode", /ns0:process/ns0:State )'/>                                                     
</ns0:res_Country>        




</xsl:otherwise>      
</xsl:choose>    
</ns0:processResponse>

Create a normal BPEL process and use a transformation inside and choose your schema for source and target part with created XSL file.



Now, run the process. Finish.

=====================================================================

If you want to use DVM with qualifiers then you need to change the dvm:lookupValue arguments accordingly. Which will be look like this:

dvm:lookupValue(dvmName, source-column-name, source-column-value, target-column-name, default-value, qualifier-name1, qualifier-value1, qualifier-name2, qualifier-value2)

& your DVM would be look like this:


=====================================================================

Domain Value Map for 1 to many:

For using one-to-many relationship in DVM you to create an extra varialbe in XSLT and needs use Xpath function to use variable's value in destination nodes.

Here is XSL:

<xsl:template match="/">
    <xsl:variable select='dvm:lookupValue1M ("DVMs/city.dvm","city",/ns0:request/ns0:cityname,"state","country","region")'
                  name="cityDetail"/>
    <ns0:response>
      <ns0:state>
        <xsl:value-of select="$cityDetail/state"/>
      </ns0:state>
      <ns0:country>
        <xsl:value-of select="$cityDetail/country"/>
      </ns0:country>
      <ns0:region>
        <xsl:value-of select="$cityDetail/region"/>
      </ns0:region>
    </ns0:response>
  </xsl:template>



Here is XSD and DVM:




======================================================================

Note: Sometimes while testing your XSLT you might end up with some error, which you can resolve by setting serverURL and testURL.


No comments:

Post a Comment