Technical Tip

Using Substring and a Mapping Table to Truncate Attribute Values

tip
Reads:

713

Score:
3.5
3.5
2
 
Comments:

0

In an Identity Vault environment, an attribute or field can have different character lengths in any of the connected data stores. So for example, the length of the Last Name field in an SQL database can be 50 characters, and the length of the corresponding Last Name field on an application database can be 40 characters.

These attribute length discrepancies need to be taken into consideration when writing drivers that connect the different data stores. Otherwise, data truncate errors could cause an Add or a Modify document to fail, resulting in data inconsistency across connected systems.

This article describes a method of handling Attribute length differences by using the Substring Verb token in combination with an IDM Mapping Table.

Mapping Tables Overview:

Mapping tables were first added to Identity Manager Version 3.5. IDM policies use mapping tables to map a group of values to another corresponding group of values. Mapping tables can be created and updated using iManager or Designer.

Mapping tables are accessed via the MAP Verb token. The MAP token has 4 fields: 1) Mapping Table DN, 2) Render Browse DN Relative to Policy, 3) Source Column Name and 4) Destination Column Name. The Map token maps the value specified in the source column to the value specified in the destination column (from the specified mapping table).

Sample Code

The following sample code truncates the length of a given attribute during an Add event. The attribute name and the attribute length are defined in a Mapping table named “AttributeLength”.

The code logic is as follows: During an Add event, the policy reads the name of the attributes in the Add document and then proceeds to find the corresponding attribute name in the Mapping Table (via MAP verb token). If the attribute name is defined in the Mapping Table (source field), then the MAP command returns the corresponding attribute length (from the destination field). Next, the Substring Verb token truncates the attribute value to the defined length. Finally, the attribute value is replaced in the document (Strip Xpath expression and Append XLM Text commands).


<rule>
	<description>User: During Add operations, truncate (substring) certain Operation Attributes (defined on a Table)</description>
	<conditions>
		<and>
			<if-class-name op="equal">IV_USER_STAGING</if-class-name>
			<if-operation op="equal">add</if-operation>
		</and>
	</conditions>
	<actions>
		<do-for-each>
			<arg-node-set>
				<token-xpath expression="./add-attr[value]"/>
			</arg-node-set>
			<arg-actions>
				<do-set-local-variable name="varAttributeLength">
					<arg-string>
						<token-map dest="Length" src="Name" table="AttributeLength">
							<token-xpath expression="$current-node/@attr-name"/>
						</token-map>
					</arg-string>
				</do-set-local-variable>
				<do-if>
					<arg-conditions>
						<and>
							<if-local-variable mode="regex" name="varAttributeLength" op="equal">\d+</if-local-variable>
						</and>
					</arg-conditions>
					<arg-actions>
						<do-set-local-variable name="varAttributeLength">
							<arg-string>
								<token-xpath expression="$varAttributeLength + 1"/>
							</arg-string>
						</do-set-local-variable>
						<do-set-local-variable name="varAttributeValueSubstringed">
							<arg-string>
								<token-xpath expression="substring($current-node/value/text(), 0, $varAttributeLength)"/>
							</arg-string>
						</do-set-local-variable>
						<do-strip-xpath expression="$current-node/value/text()"/>
						<do-append-xml-text expression="$current-node/value">
							<arg-string>
								<token-local-variable name="varAttributeValueSubstringed"/>
							</arg-string>
						</do-append-xml-text>
					</arg-actions>
					<arg-actions/>
				</do-if>
			</arg-actions>
		</do-for-each>
	</actions>
</rule>


The following sample code truncates the length of a given attribute during a Modify event.


<rule>
	<description>User: During Modify operations, truncate (substring) certain Operation Attributes (defined on a Table)</description>
	<conditions>
		<and>
			<if-class-name op="equal">IV_USER_STAGING</if-class-name>
			<if-operation op="equal">modify</if-operation>
		</and>
	</conditions>
	<actions>
		<do-for-each>
			<arg-node-set>
				<token-xpath expression="./modify-attr[add-value]"/>
			</arg-node-set>
			<arg-actions>
				<do-set-local-variable name="varAttributeLength">
					<arg-string>
						<token-map dest="Length" src="Name" table="AttributeLength">
							<token-xpath expression="$current-node/@attr-name"/>
						</token-map>
					</arg-string>
				</do-set-local-variable>
				<do-if>
					<arg-conditions>
						<and>
							<if-local-variable mode="regex" name="varAttributeLength" op="equal">\d+</if-local-variable>
						</and>
					</arg-conditions>
					<arg-actions>
						<do-set-local-variable name="varAttributeLength">
							<arg-string>
								<token-xpath expression="$varAttributeLength + 1"/>
							</arg-string>
						</do-set-local-variable>
						<do-set-local-variable name="varAttributeValueSubstringed">
							<arg-string>
								<token-xpath expression="substring($current-node/add-value/value/text(), 0, $varAttributeLength)"/>
							</arg-string>
						</do-set-local-variable>
						<do-strip-xpath expression="$current-node/add-value/value/text()"/>
						<do-append-xml-text expression="$current-node/add-value/value">
							<arg-string>
								<token-local-variable name="varAttributeValueSubstringed"/>
							</arg-string>
						</do-append-xml-text>
					</arg-actions>
					<arg-actions/>
				</do-if>
			</arg-actions>
		</do-for-each>
	</actions>
</rule>

The following sample code is for the an IDM Mapping table called AttributeLength.


<?xml version="1.0" encoding="UTF-8"?><mapping-table>
   <col-def name="Name"/>
   <col-def name="Length" type="numeric"/>
   <row>
      <col>FIRSTNAME</col>
      <col>50</col>
   </row>
   <row>
      <col>MIDNAME</col>
      <col>1</col>
   </row>
   <row>
      <col>LASTNAME</col>
      <col>50</col>
   </row>
   <row>
      <col>SEX</col>
      <col>1</col>
   </row>
   <row>
      <col>WORK_EMAIL</col>
      <col>50</col>
   </row>
   <row>
      <col>CAR_LIC_PLATE</col>
      <col>50</col>
   </row>
</mapping-table>





User Comments

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <p> <a> <em> <i> <cite> <code> <img> <ul> <ol> <li> <div> <dl> <dt> <dd> <b> <strong> <h1> <h2> <h3> <pre> <table> <td> <tr> <th> <blockquote>
  • Lines and paragraphs break automatically.
  • Glossary terms will be automatically marked with links to their descriptions. If there are certain phrases or sections of text that should be excluded from glossary marking and linking, use the special markup, [no-glossary] ... [/no-glossary]. Additionally, these HTML elements will not be scanned: a, abbr, acronym, code, pre.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
10 + 2 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.

© 2008 Novell, Inc. All Rights Reserved.