Set up Your environment#
Be sure the DirXML Script namespace definitions are set within the policy where using the Java call.In our examples, we defined the namespace as:
xmlns:uvf="http://www.novell.com/nxsl/java/com.willeke.ldap.utils.uniquevaluefinder.UniqueValueFinder"
If you are using designer, set the GUI namespace as:
com.willeke.ldap.utils.uniquevaluefinder.UniqueValueFinderand mark the check box for Java Extension.
You will also need to place the Java jar files in the correct location.
Example of calling Unique Value Finder form a Driver#
In this example the desire is to generate a unique value for uiDnumber.The values for the passed parameters are: (In order)
- attributeForUniqueValue - $lv-uniqueAttr
- preFix - $lv-Prefix
- startValue - "1001"
- maxLength - $lv-size
- maxTries - "65000"
- counterPad - "false"
- useAlpha - "false"
- dummy - "dummy"!!Example Policy
We deployed and tested this policy example as shown on the web site on our 8.8.5 with "Generic Loopback" version="3.6.10.4747"
WARNING! Use at your own risk!
Obviously thing are always different form one system to another.
<rule> <description>Test findUniqueValue</description> <comment xml:space="preserve">An example to show how to use Unique Value Finder with Driver</comment> <comment name="author" xml:space="preserve">Jim Willeke</comment> <comment name="version" xml:space="preserve">1</comment> <comment name="lastchanged" xml:space="preserve">2010-01-08</comment> <conditions> <and/> </conditions> <actions> <do-set-local-variable name="lv-uniqueAttr" scope="policy"> <arg-string> <token-text xml:space="preserve">uidnumber</token-text> </arg-string> </do-set-local-variable> <do-set-local-variable name="lv-prefix" scope="policy"> <arg-string> <token-text xml:space="preserve">null</token-text> </arg-string> </do-set-local-variable> <do-set-local-variable name="lv-size" scope="policy"> <arg-string> <token-text xml:space="preserve">6</token-text> </arg-string> </do-set-local-variable> <do-if> <arg-conditions> <and> <if-local-variable name="lv-prefix" op="available"/> <if-local-variable mode="nocase" name="lv-prefix" op="not-equal"/> </and> </arg-conditions> <arg-actions> <do-set-local-variable name="newuidnumber" scope="policy"> <arg-string> <token-xpath expression='uvf:findUniqueValue("uidNumber", "null", "1001", "5", "65000", "false", "false", "dummy")'/> </arg-string> </do-set-local-variable> </arg-actions> <arg-actions> <do-trace-message> <arg-string> <token-text xml:space="preserve">Do something else</token-text> </arg-string> </do-trace-message> <do-break/> </arg-actions> </do-if> <do-if> <arg-conditions> <and> <if-local-variable name="newuidnumber" op="available"/> <if-local-variable mode="nocase" name="newuidnumber" op="not-equal"/> <if-local-variable mode="nocase" name="newuidnumber" op="not-equal">NO_CONNECTION</if-local-variable> <if-local-variable mode="nocase" name="newuidnumber" op="not-equal">INVALID_DATA</if-local-variable> <if-local-variable mode="nocase" name="newuidnumber" op="not-equal">NO_UNIQUE_NAME</if-local-variable> <if-local-variable mode="nocase" name="newuidnumber" op="not-equal">MAX_TRIES_REACHED</if-local-variable> </and> </arg-conditions> <arg-actions> <do-trace-message> <arg-string> <token-text xml:space="preserve">**** We got this value form findUniqueValue: </token-text> <token-local-variable name="newuidnumber"/> </arg-string> </do-trace-message> <do-break/> </arg-actions> <arg-actions> <do-if> <arg-conditions> <or> <if-local-variable mode="nocase" name="newuidnumber" op="equal"/> <if-local-variable name="newuidnumber" op="not-available"/> </or> </arg-conditions> <arg-actions> <do-trace-message> <arg-string> <token-text xml:space="preserve">#### newuidnumber Came back empty ####</token-text> </arg-string> </do-trace-message> </arg-actions> <arg-actions> <do-trace-message color="brred"> <arg-string> <token-text xml:space="preserve">#### findUniqueValue error: </token-text> <token-local-variable name="newuidnumber"/> <token-text xml:space="preserve">####</token-text> </arg-string> </do-trace-message> </arg-actions> </do-if> </arg-actions> </do-if> </actions> </rule>!Example Output Trace This is a level 3 trace from the execution of the above policy:
[01/08/10 07:47:46.107]:gl ST: Applying rule 'Test findUniqueValue'. [01/08/10 07:47:46.108]:gl ST: Action: do-set-local-variable("lv-uniqueAttr",scope="policy","uidnumber"). [01/08/10 07:47:46.109]:gl ST: arg-string("uidnumber") [01/08/10 07:47:46.110]:gl ST: token-text("uidnumber") [01/08/10 07:47:46.111]:gl ST: Arg Value: "uidnumber". [01/08/10 07:47:46.111]:gl ST: Action: do-set-local-variable("lv-prefix",scope="policy","null"). [01/08/10 07:47:46.113]:gl ST: arg-string("null") [01/08/10 07:47:46.113]:gl ST: token-text("null") [01/08/10 07:47:46.114]:gl ST: Arg Value: "null". [01/08/10 07:47:46.115]:gl ST: Action: do-set-local-variable("lv-size",scope="policy","6"). [01/08/10 07:47:46.116]:gl ST: arg-string("6") [01/08/10 07:47:46.117]:gl ST: token-text("6") [01/08/10 07:47:46.117]:gl ST: Arg Value: "6". [01/08/10 07:47:46.118]:gl ST: Action: do-if(). [01/08/10 07:47:46.119]:gl ST: Evaluating conditions. [01/08/10 07:47:46.120]:gl ST: (if-local-variable 'lv-prefix' available) = TRUE. [01/08/10 07:47:46.121]:gl ST: (if-local-variable 'lv-prefix' not-equal "") = TRUE. [01/08/10 07:47:46.122]:gl ST: Performing if actions. [01/08/10 07:47:46.123]:gl ST: Action: do-set-local-variable("newuidnumber",scope="policy",token-xpath("uvf:findUniqueValue("uidNumber", "null", "1001", "5" , "65000", "false", "false", "dummy")")). [01/08/10 07:47:46.125]:gl ST: arg-string(token-xpath("uvf:findUniqueValue("uidNumber", "null", "1001", "5", "65000", "false", "false", "dummy")")) [01/08/10 07:47:46.127]:gl ST: token-xpath("uvf:findUniqueValue("uidNumber", "null", "1001", "5", "65000", "false", "false", "dummy")") [01/08/10 07:47:46.210]:gl ST: Token Value: "1006". [01/08/10 07:47:46.211]:gl ST: Arg Value: "1006". [01/08/10 07:47:46.212]:gl ST: Action: do-if(). [01/08/10 07:47:46.213]:gl ST: Evaluating conditions. [01/08/10 07:47:46.213]:gl ST: (if-local-variable 'newuidnumber' available) = TRUE. [01/08/10 07:47:46.214]:gl ST: (if-local-variable 'newuidnumber' not-equal "") = TRUE. [01/08/10 07:47:46.216]:gl ST: (if-local-variable 'newuidnumber' not-equal "NO_CONNECTION") = TRUE. [01/08/10 07:47:46.217]:gl ST: (if-local-variable 'newuidnumber' not-equal "INVALID_DATA") = TRUE. [01/08/10 07:47:46.218]:gl ST: (if-local-variable 'newuidnumber' not-equal "NO_UNIQUE_NAME") = TRUE. [01/08/10 07:47:46.220]:gl ST: (if-local-variable 'newuidnumber' not-equal "MAX_TRIES_REACHED") = TRUE. [01/08/10 07:47:46.221]:gl ST: Performing if actions. [01/08/10 07:47:46.222]:gl ST: Action: do-trace-message("**** We got this value form findUniqueValue: "+token-local-variable("newuidnumber")). [01/08/10 07:47:46.224]:gl ST: arg-string("**** We got this value form findUniqueValue: "+token-local-variable("newuidnumber")) [01/08/10 07:47:46.225]:gl ST: token-text("**** We got this value form findUniqueValue: ") [01/08/10 07:47:46.227]:gl ST: token-local-variable("newuidnumber") [01/08/10 07:47:46.228]:gl ST: Token Value: "1006". [01/08/10 07:47:46.228]:gl ST: Arg Value: "**** We got this value form findUniqueValue: 1006". [01/08/10 07:47:46.230]:gl ST:**** We got this value form findUniqueValue: 1006 [01/08/10 07:47:46.231]:gl ST: Action: do-break(). [01/08/10 07:47:46.232]:gl ST:Policy returned:!! More Information There might be more information for this subject on one of the following: