Avoiding Empty Attributes in Identity Manager

coolguys_netiq

By: coolguys_netiq

February 14, 2007 2:14 am

Reads: 202

Comments:0

Rating:0

Problem

A Forum reader recently asked:

“I want like to query for an OU and retrieve several attributes. This is the script I am using:

<?xml version="1.0" encoding="UTF-8"?><policy 
xmlns:query="http://www.novell.com/nxsl/java/com.novell.nds.dirxml.driver.XdsQueryProcessor">
 <rule>
  <description>GetData</description>
  <conditions>
   <and>
    <if-class-name op="equal">User</if-class-name>
   </and>
  </conditions>
  <actions>
   <do-set-local-variable name="user-locID">
    <arg-string>
     <token-op-attr name="workforceID"/>
    </arg-string>
   </do-set-local-variable>
   <do-set-local-variable name="result">
    <arg-string>
     <token-xpath expression='query:search($destQueryProcessor, "subtree", 
"", "", "Organizational Unit", "OU", $user-locID, "L,Telephone 
Number")/attr[@attr-name="L"]/value'/>
    </arg-string>
   </do-set-local-variable>
  </actions>
 </rule>
</policy>

This works pretty well; after this script the result contains the value of “L”, which I can set for a user account. Is it possible to retrieve not only L, but also Telephone Number? Of course I could do the same query with a new variable name, but this would result in several queries.

Is there an easy way to remove empty attributes from the XML doc? Or maybe there is a way not even to set an empty attribute.”

And here’s the response from Father Ramon …

Solution

Place the raw result of the query into a variable of type node-set and then use that variable to get the results for individual values.

    <do-set-local-variable name="result">
     <arg-node-set>
      <token-xpath expression='query:search($destQueryProcessor, 	
	"subtree", "", "", "Organizational Unit", "OU", $user-locID,
	 "L,Telephone Number")'/>
     </arg-node-set>
    </do-set-local-variable>
    <do-set-local-variable name="result-L">
     <arg-string>
      <token-xpath expression='$result/attr[@attr-name="L"]/value'/>
     </arg-string>
    </do-set-local-variable>
    <do-set-local-variable name="result-phone">
     <arg-string>
      <token-xpath expression='$result/attr[@attr-name="Telephone 
Number"]/value'/>
     </arg-string>
    </do-set-local-variable>

Different attributes have different requirements as defined in the schema. String attributes can have a minimum and maximum length, and some attributes are defined to have a minimum attribute length of 1 and others of 0.

There are ways both to strip empty attributes and to not set them in the first place. The former would use strip-xpath with an expression like .//value[. = '']. The latter could be done in a couple of different ways. You could have separate rules that checked the values in the conditions and only set them if they were non-empty. Or, you could use a for-each as a psuedo-conditional – something like this:

<do-set-local-variable name="result">
  <arg-node-set>
   <token-xpath expression='query:search($destQueryProcessor, "subtree", 
"", "", "Organizational Unit", "OU", $user-locID,      "L,Telephone 
Number")'/>
  </arg-node-set>
</do-set-local-variable>
<do-for-each>
  <arg-node-set>
   <token-xpath expression='$result/attr[@attr-name="Telephone 
Number"]/value'/>
  </arg-node-set>
  <arg-actions>
   <do-add-dest-attr-value name="Telephone Number">
    <arg-value>
     <token-local-variable name="current-node"/>
    </arg-value>
   </do-add-dest-attr-value>
  </arg-actions>
</do-for-each>
<do-for-each>
  <arg-node-set>
   <token-xpath expression='$result/attr[@attr-name="L"]/value'/>
  </arg-node-set>
  <arg-actions>
   <do-add-dest-attr-value name="L">
    <arg-value>
     <token-local-variable name="current-node"/>
    </arg-value>
   </do-add-dest-attr-value>
  </arg-actions>
</do-for-each>
VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)

Tags:
Categories: Identity Manager, Technical Solutions

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