Friday 1 February 2013

LookUp DVM in SoaSuite 10g, the 11g way

In SoaSuite 10g there is a xpath and xslt function do Domain Value Map lookups,lookupDVM. This function is based on tables in the SoaSuite repository. There is a screen in the ESB console to edit them.

In SoaSuite 11g there is a separate artefact for DVM's, and a corresponding lookupDVM function.
I found that one more convenient, since there is an editor in Jdeveloper for it and the artefact is in fact an xml file that can be put in the MDS and referenced from anywhere in your SOA projects. And lastly, it can be versioned as any other artefact.
Deployment is similar to other SOA-artefacts. For 10g you must ensure to synchronise the dvm's in the database between the different (OTAP) environments.

Today I needed a simple translation from 0,1 to Ja,Nee (Yes, No). I did not feel like to create a DVM in the database. But, also in 10g there is a quite similar solution as the 11g lookupDVM function

In SoaSuite 10g, there is an oracle xsl-extension function: lookupXML. It enables you to read in a xml file and perform a xpath-lookup query. I found it very convenient to lookup fixed (OTAP) environment-dependent parameters. If you would put those in bpel preferences you have to ensure that they're changed every deployment between the environments. Using the lookupXML function, you can lookup those values from an xml file from the filesystem of the SOASuite. Then you only have to put an version of the file in a fixed folder on every SOASuite environment. After adapting those for the particular environment, you don't need to touch it every deployment anymore.

This same construction can be used to do lookups. I created the following xml file:

<?xml version="1.0" encoding="windows-1252" ?>
<!-- $Id: email_texts.xml 99 2013-02-01 08:27:07Z ca_mavandenakker $ -->
<!-- This file can be located in a HTTP accessible directory in the midtier installation and it's referred 
     through an lookup-xml XPath expression in the service invocation.  -->
<!-- The current location is http://${deploy.soasuite.URL}/ObjectLibrary/Core/xml/v1/CoreLookupDVM.xml -->
<domains>
      <domain name="JaNee">
            <keyDb>0</keyDb>
            <dispValue>Nee</dispValue>
            <boolean>false</boolean>
      </domain>
      <domain name="JaNee">
            <keyDb>1</keyDb>
            <dispValue>Ja</dispValue>
            <boolean>true</boolean>
      </domain>
</domains>
   
Since the lookupXML is a xsl function, it is in 10g apparently not available as an Xpath function, I created an XSD for the convenience of doing the DVM-lookups:
<?xml version="1.0" encoding="windows-1252" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:version="1.0"
            xmlns:svnId="$Id$" xmlns="http://www.darwin-it.nl/xsd/v1/DVM"
            xmlns:dvm="http://www.darwin-it.nl/xsd/v1/DVM"
            targetNamespace="http://www.darwin-it.nl/xsd/v1/DVM"
            elementFormDefault="qualified">
  <xsd:element name="DVM" type="dvm:DVMType">
    <xsd:annotation>
      <xsd:documentation>Domain Value Mapping</xsd:documentation>
    </xsd:annotation>
  </xsd:element>
  <xsd:complexType name="DVMType">
    <xsd:sequence>
      <xsd:element name="Domain" type="xsd:string"/>
      <xsd:element name="FromKey" type="xsd:string"/>
      <xsd:element name="FromValue" type="xsd:string"/>
      <xsd:element name="ToKey" type="xsd:string"/>
      <xsd:element name="ToValue" type="xsd:string"/>
    </xsd:sequence>
  </xsd:complexType>
</xsd:schema>
Based on this XSD you can create a variable, fill in the Domain, eg. "JaNee", the FromKey, eg. "keyDb", the FromKeyValue, eg. "0", and the ToKey, eg. "dispValue" or "boolean". Then you can transform the variable to it's self using the following XSL:
<?xml version="1.0" encoding="UTF-8" ?>
<?oracle-xsl-mapper <!-- SPECIFICATION OF MAP SOURCES AND TARGETS, DO NOT MODIFY. -->
  <mapSources>
    <source type="XSD">
      <schema location="http://melia03.hhdelfland.nl/ObjectLibrary/Core/xsd/v1/DVM.xsd"/>
      <rootElement name="DVM" namespace="http://www.darwin-it.nl/xsd/v1/DVM"/>
    </source>
  </mapSources>
  <mapTargets>
    <target type="XSD">
      <schema location="http://melia03.hhdelfland.nl/ObjectLibrary/Core/xsd/v1/DVM.xsd"/>
      <rootElement name="DVM" namespace="http://www.darwin-it.nl/xsd/v1/DVM"/>
    </target>
  </mapTargets>
  <!-- GENERATED BY ORACLE XSL MAPPER 10.1.3.5.0(build 090730.0200.1754) AT [FRI FEB 01 10:04:09 CET 2013]. -->
?>
<xsl:stylesheet version="1.0"
                xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/"
                xmlns:ehdr="http://www.oracle.com/XSL/Transform/java/oracle.tip.esb.server.headers.ESBHeaderFunctions"
                xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:version="1.0"
                xmlns:ns0="http://www.darwin-it.nl/xsd/v1/DVM"
                xmlns:hwf="http://xmlns.oracle.com/bpel/workflow/xpath"
                xmlns:xp20="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20"
                xmlns:xref="http://www.oracle.com/XSL/Transform/java/oracle.tip.xref.xpath.XRefXPathFunctions"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:ora="http://schemas.oracle.com/xpath/extension"
                xmlns:ids="http://xmlns.oracle.com/bpel/services/IdentityService/xpath"
                xmlns:orcl="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.ExtFunc"
                xmlns:svnId="$Id$"
                exclude-result-prefixes="xsl xsd version ns0 svnId bpws ehdr hwf xp20 xref ora ids orcl">
  <xsl:variable name="configURI"
                select="'http://${deploy.soasuite.URL}/ObjectLibrary/Core/xml/v1/CoreLookupDVM.xml'"/>
                
  <xsl:template match="/">
    <ns0:DVM>
      <ns0:Domain>
        <xsl:value-of select="/ns0:DVM/ns0:Domain"/>
      </ns0:Domain>
      <ns0:FromKey>
        <xsl:value-of select="/ns0:DVM/ns0:FromKey"/>
      </ns0:FromKey>
      <ns0:FromValue>
        <xsl:value-of select="/ns0:DVM/ns0:FromValue"/>
      </ns0:FromValue>
      <ns0:ToKey>
        <xsl:value-of select="/ns0:DVM/ns0:ToKey"/>
      </ns0:ToKey>
      <ns0:ToValue>
        <xsl:call-template name="LookupDVM">
          <xsl:with-param name="domainName" select="/ns0:DVM/ns0:Domain"/>
          <xsl:with-param name="fromKey" select="/ns0:DVM/ns0:FromKey"/>
          <xsl:with-param name="fromKeyValue" select="/ns0:DVM/ns0:FromValue"/>
          <xsl:with-param name="toKey" select="/ns0:DVM/ns0:ToKey"/>
        </xsl:call-template>
      </ns0:ToValue>
    </ns0:DVM>
  </xsl:template>
  <!--  User Defined Templates  -->
  <xsl:template name="LookupDVM">
    <xsl:param name="domainName"/>
    <xsl:param name="fromKey"/>
    <xsl:param name="fromKeyValue"/>
    <xsl:param name="toKey"/>
    <xsl:variable name="parentPath"
                  select="concat('/domains/domain[@name=&quot;',$domainName,'&quot;]' )"/>
    <xsl:variable name="result"
                  select="orcl:lookup-xml($configURI,$parentPath,$fromKey,$toKey ,$fromKeyValue)"/>
    <xsl:value-of select="$result"/>
  </xsl:template>
</xsl:stylesheet> 
This for those cases that you just want to lookup some values from the domain-xml this construction can be handy. In other cases where you need to lookup multiple values in an complexer xsl't you can copy and paste the construction above.

Since the CoreLookupDVM.xml is a, quite simple, xml file, it can easily be transformed to an 11g lookupDVM file.

No comments :