Novell is now a part of Micro Focus

Generating a Unique Notes FullName prior to Notes Registration

Novell Cool Solutions: Tip
By Perry Nuffer

Digg This - Slashdot This

Posted: 23 Aug 2006


How can I generate a unique Notes FullName so that the user add command will not fail when sent to the Notes registration process by the NotesDriverShim?


You may find the style sheet included below works for your situation. Insert this sample style sheet into the Notes Driver command transformation policy set and try it. It queries Notes up to 10 times for a unique Notes FullName field, incrementing the LastName component with an appended digit until it finds a unique person FullName within the NAB. If your business needs are different, it shouldn't be too hard to change how the style sheet increments, or on which FullName component (first, middle, or last name) it increments.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet exclude-result-prefixes="query cmd dncv" version="1.0"
xmlns:query="" xmlns:xsl="">
   <!-- parameters passed in from the DirXML engine -->
   <xsl:param name="srcQueryProcessor"/>
   <xsl:param name="destQueryProcessor"/>
   <xsl:param name="srcCommandProcessor"/>
   <xsl:param name="destCommandProcessor"/>
   <xsl:param name="dnConverter"/>
   <xsl:param name="fromNds"/>
   <!-- identity transformation template -->
   <!-- in the absence of any other templates this will cause -->
   <!-- the stylesheet to copy the input through unchanged to the output -->
   <xsl:template match="node()|@*">
         <xsl:apply-templates select="@*|node()"/>
   <!-- add your custom templates here -->
   <xsl:template name="queryNotesFullName">
      <xsl:param name="notes_full_name"/>
      <xsl:param name="first_name"/>
      <xsl:param name="middle_name"/>
      <xsl:param name="last_name"/>
      <xsl:param name="new_name"/>
      <xsl:param name="query_count" select="1"/>
      <xsl:variable name="query">
         <nds dtdversion="3.0" ndsversion="8.x">
               <query class-name="User" scope="subtree">
                  <search-class class-name="User"/>
                  <search-attr attr-name="FullName">
                     <value type="string">
                        <xsl:value-of select="$notes_full_name"/>
      <xsl:variable name="result" select="count(query:query($destQueryProcessor,$query)//instance)"/>
      <!-- Display result count to the trace, for the curious XSLT programmer -->
      <!-- <xsl:message>result=<xsl:value-of select="$result"/></xsl:message> -->
         <xsl:when test="$result != '0' and $query_count &lt;= '10'">
            <!-- Name Collision! Build a new name, then search for it -->
            <!-- Change the LastName within the FullName to create a unique Notes FullName -->   
            <xsl:variable name="new_last_name">
               <xsl:value-of select="$last_name"/>
               <xsl:value-of select="$query_count"/>
            <xsl:variable name="try_notes_full_name">
               <xsl:if test="$first_name">
                  <xsl:value-of select="$first_name"/>
                  <xsl:value-of select="' '"/>
               <xsl:if test="$middle_name">
                  <xsl:value-of select="$middle_name"/>
                  <xsl:value-of select="' '"/>
               <xsl:value-of select="$new_last_name"/>
            <!-- Display varibles to the trace, for the curious XSLT programmer -->
            <!-- <xsl:message>try_notes_full_name=<xsl:value-of select="$try_notes_full_name"/></xsl:message>
            <xsl:message>query_count=<xsl:value-of select="$query_count"/></xsl:message>
            <xsl:message>first_name=<xsl:value-of select="$first_name"/></xsl:message>
            <xsl:message>middle_name=<xsl:value-of select="$middle_name"></xsl:message>
            <xsl:message>last_name=<xsl:value-of select="$new_last_name"/></xsl:message>
            <!-- Search for the FullName with new name -->
            <xsl:call-template name="queryNotesFullName">
               <xsl:with-param name="notes_full_name" select="$try_notes_full_name"/>
               <xsl:with-param name="first_name" select="$first_name"/>
               <xsl:with-param name="middle_name" select="$middle_name"/>
               <xsl:with-param name="last_name" select="$last_name"/>
               <xsl:with-param name="new_name" select="$new_last_name"/>
               <xsl:with-param name="query_count" select="$query_count + 1"/>
         <xsl:when test="$query_count > '10'">
            <!-- We have searched too many times, so quit searching and use the original name -->
            <xsl:message>Unique Notes FullName not found after <xsl:value-of select="$query_count - 1"/> search attempts.</xsl:message>
               <xsl:apply-templates select="@*|node()"/>
            <!-- We have a unique name, use it! -->            
               <xsl:attribute name="type">
                  <xsl:value-of select="'string'"/>
               <xsl:value-of select="$new_name"/>
   <!-- Use the Surname as the changing component for the Notes FullName -->
   <!-- Change the Surname within the FullName to create a unique Notes FullName -->   
   <xsl:template match="add[@class-name='User']/add-attr[@attr-name='Surname']/value">
      <xsl:variable name="first_name" select="../../add-attr[@attr-name='Given Name']/value/text()"/>
      <xsl:variable name="initials" select="../../add-attr[@attr-name='Initials']/value/text()"/>
      <xsl:variable name="surname" select="../../add-attr[@attr-name='Surname']/value/text()"/>
      <xsl:variable name="full_name">
         <xsl:if test="$first_name">
            <xsl:value-of select="$first_name"/>
            <xsl:value-of select="' '"/>
         <xsl:if test="$initials">
            <xsl:value-of select="$initials"/>
            <xsl:value-of select="' '"/>
         <xsl:value-of select="$surname"/>
      <xsl:call-template name="queryNotesFullName">
         <xsl:with-param name="notes_full_name" select="$full_name"/>
         <xsl:with-param name="first_name" select="$first_name"/>
         <xsl:with-param name="middle_name" select="$initials"/>
         <xsl:with-param name="last_name" select="$surname"/>
         <xsl:with-param name="new_name" select="$surname"/>

Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions.

© Micro Focus