Using regular expression in Mapping Tables


Is is possible to retrieve values from a mapping table by using regular
expression?


--
joydeepg
------------------------------------------------------------------------
joydeepg's Profile: https://forums.netiq.com/member.php?userid=7638
View this thread: https://forums.netiq.com/showthread.php?t=51565

  • joydeepg wrote:

    > Is is possible to retrieve values from a mapping table by using regular
    > expression?


    You can code this, yes.
    However the default mapping table logic doesn't have this capability.

    --
    If you find this post helpful and are logged into the web interface,
    show your appreciation and click on the star below...
  • joydeepg wrote:

    > Is is possible to retrieve values from a mapping table by using regular
    > expression?


    Yes, though not out of the box. What I usually do when working with mapping
    tables:

    1. read mapping table into node set variable
    2. tag all col nodes with their name as defined on col-def nodes
    3. read the info I need using xpath

    If you set $myMappingTable to the DN of an address list and apply:

    <rule>
    <description>Read mapping table into nodeset variable for use with
    xpath/regex</description>
    <comment name="author" xml:space="preserve">Lothar Haeger</comment>
    <conditions>
    <or>
    <if-local-variable name="myMap" op="not-available"/>
    </or>
    </conditions>
    <actions>
    <do-trace-message disabled="true" notrace="true">
    <arg-string>
    <token-text xml:space="preserve">Read mapping table XML data from
    Edirectory (from subscriber channel, use "Destination Attribute" on the
    publisher)</token-text>
    </arg-string>
    </do-trace-message>
    <do-set-local-variable name="myMap" scope="driver">
    <arg-node-set>
    <token-xml-parse>
    <token-base64-decode>
    <token-src-attr class-name="DirXML-Resource" name="DirXML-Data">
    <arg-dn>
    <token-text xml:space="preserve">$myMappingTable$</token-text>
    </arg-dn>
    </token-src-attr>
    </token-base64-decode>
    </token-xml-parse>
    </arg-node-set>
    </do-set-local-variable>
    <do-trace-message disabled="true" notrace="true">
    <arg-string>
    <token-text xml:space="preserve">Copy column names to all col nodes for
    easier use with xpath</token-text>
    </arg-string>
    </do-trace-message>
    <do-for-each>
    <arg-node-set>
    <token-xpath expression="$myMap/mapping-table/col-def"/>
    </arg-node-set>
    <arg-actions>
    <do-clone-xpath
    dest-expression="$current-node/../row/col[position()=count($current-node/precedi
    ng-sibling::col-def) 1]" src-expression="$current-node/@name"/>
    </arg-actions>
    </do-for-each>
    </actions>
    </rule>

    you can search for the phone number of Mary from New York with


    <do-set-local-variable name="phoneMaryFromNYC" scope="policy">
    <arg-string>
    <token-xpath expression='$myMap//row[col[@name="Givenname"]="Mary" and
    col[@name="City"]="New York"]/col[@name="Phone"]'/>
    </arg-string>
    </do-set-local-variable>

    Now add an ECMA to the driver that defines regex matches as:

    function matches(string, pattern)
    {
    try
    {
    text = new Packages.java.lang.String(string);
    return text.matches("(?i)" pattern);
    }
    catch (e)
    {
    return false;
    }
    }

    any you can du a fuzzy search using regex:

    <do-set-local-variable name="phoneMaryFromNYC" scope="policy">
    <arg-string>
    <token-xpath
    expression='$myMap//row[es:matches(col[@name="Givenname"],"Mar(y|ie|ilyn)") and
    col[@name="City"]="(New York|NY).*"]/col[@name="Phone"]'/>
    </arg-string>
    </do-set-local-variable>

  • Actually I have a situation where based on 3 attributes(jobCategory
    ,jobFamily ,Title) I have to choose a role from the mapping table. I
    have concatenated the 3 attributes using ":" as a delimiter. Now any of
    the 3 attributes can contain * as value which means irrespective of any
    value it will get the role (ex. PATIENT CARE-NON-RN:TECHNICIANS:*). to
    achieve this I have tried the following:

    <arg-actions>
    <do-set-local-variable name="queryText" scope="policy">
    <arg-string>
    <token-join>
    <token-text xml:space="preserve">((</token-text>
    <token-dest-attr class-name="wfhUser" name="wfhJobFamily"/>
    <token-text xml:space="preserve">|\*)\W(</token-text>
    <token-dest-attr class-name="wfhUser" name="wfhJobCategory"/>
    <token-text xml:space="preserve">|\*)\W(</token-text>
    <token-dest-attr class-name="User" name="Title"/>
    <token-text xml:space="preserve">))</token-text>
    </token-join>
    </arg-string>
    </do-set-local-variable>
    <do-set-local-variable name="oldRoles" scope="policy">
    <arg-node-set>
    <token-map dest="Role Name" src="Factor"
    table="..\..\Library\roleMappingTable">
    <token-local-variable name="queryText"/>
    </token-map>
    </arg-node-set>
    </do-set-local-variable>
    <do-set-local-variable name="newRoles" scope="policy">
    <arg-node-set>
    <token-map dest="Role Name" src="Factor"
    table="..\..\Library\roleMappingTable">
    <token-local-variable name="queryText"/>
    </token-map>
    </arg-node-set>
    </do-set-local-variable>
    </arg-actions>

    But the trace show it cannot get the value from the mapping table


    --
    joydeepg
    ------------------------------------------------------------------------
    joydeepg's Profile: https://forums.netiq.com/member.php?userid=7638
    View this thread: https://forums.netiq.com/showthread.php?t=51565

  • So you build a string in your first token, that includes Regex.

    Then you want to use that inside a Map token as the src column.

    I think Lothar's approach can be adapted to your need.

    Get the XML of the table into a nodeset, then use his es:matches() call
    to find the right row, and then get the column back you are looking for.

    You do know, that if you have a mapping table, where the Src value
    returns more than one, you get a nodeset back. Then you could look at
    those values, if it helps? (Basically make the variable you store it
    into a nodeset and then you get a nodeset of values back).


    On 8/20/2014 8:55 AM, joydeepg wrote:
    > <do-set-local-variable name="queryText" scope="policy">
    > <arg-string>
    > <token-join>
    > <token-text xml:space="preserve">((</token-text>
    > <token-dest-attr class-name="wfhUser" name="wfhJobFamily"/>
    > <token-text xml:space="preserve">|\*)\W(</token-text>
    > <token-dest-attr class-name="wfhUser" name="wfhJobCategory"/>
    > <token-text xml:space="preserve">|\*)\W(</token-text>
    > <token-dest-attr class-name="User" name="Title"/>
    > <token-text xml:space="preserve">))</token-text>
    > </token-join>
    > </arg-string>
    > </do-set-local-variable>
    > <do-set-local-variable name="oldRoles" scope="policy">
    > <arg-node-set>
    > <token-map dest="Role Name" src="Factor"
    > table="..\..\Library\roleMappingTable">
    > <token-local-variable name="queryText"/>
    > </token-map>
    > </arg-node-set>
    > </do-set-local-variable>
    > <do-set-local-variable name="newRoles" scope="policy">
    > <arg-node-set>
    > <token-map dest="Role Name" src="Factor"
    > table="..\..\Library\roleMappingTable">
    > <token-local-variable name="queryText"/>
    > </token-map>
    > </arg-node-set>
    > </do-set-local-variable>



  • Is it possible to create a ECMA script to access the mapping table and
    get the desired value using regular expression.


    --
    joydeepg
    ------------------------------------------------------------------------
    joydeepg's Profile: https://forums.netiq.com/member.php?userid=7638
    View this thread: https://forums.netiq.com/showthread.php?t=51565

  • On 8/20/2014 10:36 AM, joydeepg wrote:
    >
    > Is it possible to create a ECMA script to access the mapping table and
    > get the desired value using regular expression.


    Probably. But you would be reinventing a number of wheels.

    Load your mapping table into an XML variable. Then use the es:matches()
    inside your predicates to pick the right nodes.

    You would need to load the XML somehow. In ECMA, or else get it into a
    variable and pass it into your ECMA.

    You would need to parse the XML so now you are doing XPATH in ECMA.
    Already exposed simply in DirXML Script.

    Use the right tools in the right place I would think.

  • Geoffrey Carman wrote:

    > Use the right tools in the right place I would think.


    An use question marks in questions... :-)
  • On 8/20/2014 2:51 PM, Lothar Haeger wrote:
    > Geoffrey Carman wrote:
    >
    >> Use the right tools in the right place I would think.

    >
    > An use question marks in questions... :-)


    Use the proper water fowl for the task at hand.

    I never have the right chicken, when I need it. Always a duck.