Generating a Unique Notes FullName prior to Notes Registration



By: pnuffer

August 23, 2006 9:20 am

Reads: 150

Comments:0

Rating:0

Problem

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?

Solution

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:cmd="http://www.novell.com/nxsl/java/com.novell.nds.dirxml.driver.XdsCommandProcessor"
xmlns:dncv="http://www.novell.com/nxsl/java/com.novell.nds.dirxml.driver.DNConverter"
xmlns:query="http://www.novell.com/nxsl/java/com.novell.nds.dirxml.driver.XdsQueryProcessor" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <!-- 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:copy>
         <xsl:apply-templates select="@*|node()"/>
      </xsl:copy>
   </xsl:template>
   <!-- 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">
            <input>
               <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"/>
                     </value>
                  </search-attr>
                  <read-attr/>
               </query>
            </input>
         </nds>
      </xsl:variable>
      <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:choose>
         <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>
            <xsl:variable name="try_notes_full_name">
               <xsl:if test="$first_name">
                  <xsl:value-of select="$first_name"/>
                  <xsl:value-of select="' '"/>
               </xsl:if>
               <xsl:if test="$middle_name">
                  <xsl:value-of select="$middle_name"/>
                  <xsl:value-of select="' '"/>
               </xsl:if>
               <xsl:value-of select="$new_last_name"/>
            </xsl:variable>
            <!-- 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:call-template>
         </xsl:when>
         <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:copy>
               <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
         </xsl:when>
         <xsl:otherwise>
            <!-- We have a unique name, use it! -->            
            <xsl:copy>
               <xsl:attribute name="type">
                  <xsl:value-of select="'string'"/>
               </xsl:attribute>
               <xsl:value-of select="$new_name"/>
            </xsl:copy>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>
   
   <!-- 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>
         <xsl:if test="$initials">
            <xsl:value-of select="$initials"/>
            <xsl:value-of select="' '"/>
         </xsl:if>
         <xsl:value-of select="$surname"/>
      </xsl:variable>
      <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"/>
      </xsl:call-template>
   </xsl:template>
</xsl:stylesheet>
VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)

Tags: ,
Categories: Uncategorized

Disclaimer: As with everything else at NetIQ Cool Solutions, this content is definitely not supported by NetIQ, so Customer Support will not be able to help you if it has any adverse effect on your environment.  It just worked for at least one person, and perhaps it will be useful for you too.  Be sure to test in a non-production environment.

Comment