Hi All,
I am trying to build an attribute generator rule to populate value for an attribute called Abbrev during provisioning. I validated the below code and it does not check for unique values and creates the same value for all the identities with the same name.
Example:
Doe, John
This code generates Doe, J for all the users with same name failing to check the uniqueness instead of following the logic in the code, I have used “attrSearchCountAccounts” to check the uniqueness.
Kindly let me know if there is any issue with the code.
Thanks All.
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
import org.apache.commons.lang.StringUtils;
import sailpoint.object.Application;
import sailpoint.object.Identity;
import sailpoint.server.IdnRuleUtil;
import sailpoint.tools.GeneralException;
import sailpoint.tools.Util;
import sailpoint.rule.*;
List sourceIDList = new ArrayList(Arrays.asList(new String[]{"....."}));
String abbrev="";
String firstName = StringUtils.trimToNull(identity.getAttribute("firstname"));
String lastName = StringUtils.trimToNull (identity.getAttribute("lastname"));
String middleName = StringUtils.trimToNull (identity.getAttribute ("midddleName"));
String firstchar = StringUtils.substring(firstName, 0, 1);
String middlechar = StringUtils.substring(middleName, 0, 1);
public boolean isUnique(String abbrev){
String operation = "Equals";
boolean isUnique = false;
List searchValues = new ArrayList(Arrays.asList (new String[] {abbrev}));
if(idn.attrSearchCountAccounts(sourceIDList, "allAbbrev", operation, searchValues) == 0) {
isUnique = true;
}else{
isUnique = false;
}
return isUnique;
}
public String createUniqueID(String abbrev) throws Exception{
long uniqueCounter = 1;
String tempAbbrev = abbrev + new String(uniqueCounter);
while(!isUnique(tempAbbrev) && uniqueCounter < 20){
uniqueCounter++;
tempAbbrev = abbrev + new String(uniqueCounter);
}
if(uniqueCounter >= 20){
throw new Exception("Unique Name counter exceeds max limit");
}
return tempAbbrev;
}
if(firstName == null || "".equals(firstName) || lastName == null || "".equals(lastName)){
throw new Exception("First Name or Last Name is null or empty");
}else{
abbrev = lastName + ", " + firstchar;
if(!isUnique(abbrev)){
abbrev = lastName + ", " + firstName;
if(!isUnique(abbrev)){
if(middleName == null || "".equals(middleName)){
throw new Exception("Middle Name is null or empty");
}else{
abbrev = lastName + ", " + firstName + ", " + middlechar;
if(!isUnique(abbrev)){
abbrev = lastName + ", " + firstName + ", " + middleName;
if(!isUnique(abbrev)){
abbrev = createUniqueID(abbrev);
}
}
}
}
return abbrev;
}else{
return abbrev;
}
}