How I simplified my Code and populated a Mapping Table

0 Likes
I had the need to notify the administrators of our printing system every time the financial people assigned a new accounting code to our employees. We charge back printing with Equitrac which a print accounting system. Whenever we add a new type of employee the Finance people assign them unique accounting codes and these are assigned to every employee object by IDM yet the issue we faced was every time a new code appears the Equitac Administrator needs go in an manually prepare what they call Departments so that employees are not blocked from printing which is the default for new codes.

The picture below is my first attempt at a solution by using a Regular Expression to find new codes.

regex

The issue was the number of codes grew so large that it became almost impossible to edit in designer. I sought the help of friends to find a better direction. "Geoffc" and others I was told to look at Mapping tables. I had a list of codes and using Notepad I quickly created a CSV file with two Columns the first I called "currentprintcode" and the second I called notify. The currentprintcode contain a list of all currently used PrintCodes and the notify column just has the value FALSE for all entries. Designer allows you to create a new mapping table from a csv file so I now had a mapping table I called lib-PrintCode. Seen in the image below

mappingtable

I rewrote my code to search the Mapping Table and alert us if a new PrintCode was used

<rule>
<description>Print Code Notify</description>
<comment xml:space="preserve">This uses a mapping table lib-PrintCodes that stores known PrintCodes. If a code is found that is not in the table it will email us and it will add it to the bottom of the Mapping Table with the PrintCode and the value False. The condition group excludes Students and Alumni so that the Lookups are only being done on staff. </comment>
<conditions>
<and>
<if-attr mode="regex" name="printcode" op="equal">...\....\.70104\...</if-attr>
</and>
</conditions>
<actions>
<do-set-local-variable name="printcodeNotiy" scope="policy">
<arg-string>
<token-map dest="notify" src="currentprintcode" table="..\..\Library\lib-PrintCode">
<token-attr name="printcode"/>
</token-map>
</arg-string>
</do-set-local-variable>
<do-set-local-variable name="lcl.printcode" scope="policy">
<arg-string>
<token-attr name="printcode"/>
</arg-string>
</do-set-local-variable>
<do-if>
<arg-conditions>
<and>
<if-local-variable mode="regex" name="printcodeNotiy" op="equal">.*FALSE.*</if-local-variable>
</and>
</arg-conditions>
<arg-actions>
<do-break/>
</arg-actions>
<arg-actions>
<do-if>
<arg-conditions>
<and>
<if-attr mode="regex" name="noEmail" op="not-equal">.*TRUE.*</if-attr>
</and>
</arg-conditions>
<arg-actions>
<do-send-email server="idmmail.davenport.edu" type="html">
<arg-string name="to">
<token-text xml:space="preserve">abc@davenport.edu</token-text>
</arg-string>
<arg-string name="from">
<token-text xml:space="preserve">Customer.Service@davenport.edu</token-text>
</arg-string>
<arg-string name="subject">
<token-text xml:space="preserve">New PrintCode Found "</token-text>
<token-local-variable name="lcl.printcode"/>
<token-text xml:space="preserve">"</token-text>
</arg-string>
<arg-string name="message">
<token-text xml:space="preserve">IDM dedicated a new PrintCode this means we need to adjust Equitrac for a new department and review IDM code for possible changes. Please have the person at DU who works on Equitrac adjust this new Department for employee printing. The known codes are stored in lib-PrintCode not in Code</token-text>
<token-local-variable name="lcl.printcode"/>
<token-text xml:space="preserve">" Is the new Number. </token-text>
<token-text xml:space="preserve">This message Produced by sub-etp-PrintingCodesAlert,cn=Subscriber,cn=BusinessLogic,cn=DriverSet1,o=services
</token-text>
</arg-string>
</do-send-email>


This really did the trick all the old ugly Regex Expression is gone and the mapping table now has a list of the known codes. This just left me with one issue that concerned me and that was I did not want to have to manually add the new values to the mapping table every time a new code was discovered. So once again I got help from the community that was able to show me how I could code through code add the new values to the table each time one was discovered. Here is the code to add the new value.

<do-set-local-variable name="myMappingTable" scope="policy">
<arg-node-set>
<token-xml-parse>
<token-base64-decode>
<token-src-attr name="DirXML-Data">
<arg-dn>
<token-global-variable name="myMappingTableDN"/>
</arg-dn>
</token-src-attr>
</token-base64-decode>
</token-xml-parse>
</arg-node-set>
</do-set-local-variable>
<do-set-local-variable name="myNewRow" scope="policy">
<arg-node-set>
<token-xml-parse>
<token-text xml:space="preserve">&lt;row>
&lt;col></token-text>
<token-local-variable name="lcl.printcode"/>
<token-text xml:space="preserve">&lt;/col>
&lt;col>FALSE&lt;/col>
&lt;/row></token-text>
</token-xml-parse>
</arg-node-set>
</do-set-local-variable>
<do-clone-xpath dest-expression="$myMappingTable/mapping-table" src-expression="$myNewRow/row"/>
<do-set-src-attr-value name="DirXML-Data">
<arg-dn>
<token-global-variable name="myMappingTableDN"/>
</arg-dn>
<arg-value type="string">
<token-text xml:space="preserve">&lt;?xml version="1.0"
encoding="UTF-8"?></token-text>
<token-xml-serialize>
<token-local-variable name="myMappingTable"/>
</token-xml-serialize>
</arg-value>
</do-set-src-attr-value>
</arg-actions>
<arg-actions/>
</do-if>
</arg-actions>
</do-if>
</actions>
</rule>
</policy>



So now I have a complete solution that alerts us to new Printcodes as soon as they are associated to our users which produces an email to the Administrator and it adds the value to the mapping table so alerts are only sent when new unique values are discovered which is exactly what was asked of me.

Labels:

How To-Best Practice
Comment List
Related
Recommended