Announcing the Saviynt Knowledge Exchange unifying the Saviynt forums, documentation, training,
and more in a single search tool across platforms. Read the announcement here.

Remove Accents and Normalize String

Community_User
Saviynt Employee
Saviynt Employee
Originally posted on October 20 2021 at 15:09 UTC

Hi,


I need to transform text that comes from HR, this includes special characters and accents (to meet AD requirements).


I have a script that works in 'pure' groovy using this IDE:

https://www.tutorialspoint.com/execute_groovy_online.php


import java.text.Normalizer import java.text.Normalizer.Form  private String camelCase(String name){     List list = new ArrayList();     for (String part in name.split(' ')){         list.add(part[0].toUpperCase() + part.substring(1,part.length()).toLowerCase());     }     return Normalizer.normalize(list.join(' '), Form.NFD).replaceAll(/\p{InCombiningDiacriticalMarks}+/, '').replaceAll('[^a-zA-Z ]', ''); }

 This is working perfectly for me (with some limitations that we can live with) some unit tests:

 

CHRIS JEFFERS VAN DER RENSBURG becomes: Chris Jeffers Van Der Rensburg Ugly UNCLE TOM becomes: Ugly Uncle Tom SANDY-JANE MCWILLIAMS becomes: Sandyjane Mcwilliams JERRY O'BRIAN becomes: Jerry Obrian éôü êùéàç ÍËÇ becomes: Eou Eueac Iec ł € œ becomes:   

 You can see the limitations on the last line, it does not like those characters.


How can I now integrate this into the ACCOUNTNAME JSON? I have tried to use it, but I get the following error (hope you can read it):

image









Can I create a function and then use it like I intend? Or is there another way I need to do 'advanced' transformations?


Here is a snippet of my JSON:

CN=${ private String camelCase(String name){     List list = new ArrayList();     for (String part in name.split(' ')){         list.add(part[0].toUpperCase() + part.substring(1,part.length()).toLowerCase());     }     return Normalizer.normalize(list.join(' '), Form.NFD).replaceAll(/\p{InCombiningDiacriticalMarks}+/, '').replaceAll('[^a-zA-Z ]', ''); } camelCase(user.firstname + ' ' + user.lastname); }${         if(role.equalsIgnoreCase('Contractor or Vendor') || role.equalsIgnoreCase('Contractor or Vendor - No Mailbox')){             if(company.equalsIgnoreCase('Adapt IT')){                 ',OU=Adapt IT,OU=User Accounts,OU=Administrative Container'             }             else if(company.equalsIgnoreCase('Adcorp BLU')){                 ',OU=Adcorp BLU,OU=User Accounts,OU=Administrative Container'             }             else if(company.equalsIgnoreCase('Advansys')){                 ',OU=Advansys,OU=User Accounts,OU=Administrative Container'             }             else if(company.equalsIgnoreCase('African Business Software (ABS)')){                 ',OU=African Business Software (ABS),OU=User Accounts,OU=Administrative Container'             }             else if(company.equalsIgnoreCase('Altron Karabina')){                 ',OU=Altron Karabina,OU=User Accounts,OU=Administrative Container'             }             else if(company.equalsIgnoreCase('Bidvest Mobility')){                 ',OU=Bidvest Mobility,OU=User Accounts,OU=Administrative Container'             }

 Thanks in advance!!

This message was previously posted on Saviynt's legacy forum by a community user and has been moved over to this forum for continued exposure.
3 REPLIES 3

Community_User
Saviynt Employee
Saviynt Employee
Originally posted on October 20 2021 at 15:16 UTC

Hi Craig,

It does not seem to be liking the method definition on your json. Can you rather build this into a jar and then call it fetch your values and try?


Regards,

Sahaj

This message was previously posted on Saviynt's legacy forum by a community user and has been moved over to this forum for continued exposure.

Community_User
Saviynt Employee
Saviynt Employee
Originally posted on October 21 2021 at 07:41 UTC

Thanks Sahaj,


I will implement a Jar

This message was previously posted on Saviynt's legacy forum by a community user and has been moved over to this forum for continued exposure.

Community_User
Saviynt Employee
Saviynt Employee
Originally posted on October 21 2021 at 12:58 UTC

For the sake of anyone else looking to do something similar, this is what I found.

I created a class called camelCase (not really the right name, but close enough) that's input was a String, however that didnt work as it seems that when passing a String into a class through the config, it actually passes a String Array, so in my class, instead of expecting a String, I now expect an String Array and that works.


  

package com.altron.normalizeName;  import java.text.Normalizer; import java.text.Normalizer.Form; import java.util.ArrayList; import java.util.Arrays; import java.util.List;  public class NormalizeName { //this does not work as what comes in from the ACCOUNTNAME rule is a String[] public static String camelCase(String name){     List<String> list = new ArrayList<String>();     String[] splitName = name.split(" ");     for (String part : splitName) {     list.add(part.substring(0,1).toUpperCase() + part.substring(1,part.length()).toLowerCase());     }     String joined = String.join(" ", list);     String normalized = Normalizer.normalize(joined, Form.NFD);     String replaced = normalized.replaceAll("[^a-zA-Z ]", ""); return replaced; } //This works. Since I only ever expect 1 string, I can do what I do on line 25 public static String camelCase(String[] names){     List<String> list = Arrays.asList(names);     String name = names[0];     String[] splitName = name.split(" ");     for (String part : splitName) {     list.add(part.substring(0,1).toUpperCase() + part.substring(1,part.length()).toLowerCase());     }     String joined = String.join(" ", list);     String normalized = Normalizer.normalize(joined, Form.NFD);     String replaced = normalized.replaceAll("[^a-zA-Z ]", "");  return replaced; } }

  Then I call it by using:


 

CN=${def name = com.altron.normalizeName.NormalizeName.camelCase(user.firstname + ' ' + user.lastname);return name;},///rest of the DN here

 

This message was previously posted on Saviynt's legacy forum by a community user and has been moved over to this forum for continued exposure.