Unique username generation code[assuming employee id is unique attribute] in buildmap rule
import sailpoint.connector.DelimitedFileConnector;
import sailpoint.object.Identity;
import sailpoint.object.QueryOptions;
import sailpoint.object.Filter;
import java.util.*;
HashMap map = DelimitedFileConnector.defaultBuildMap(cols,record);
String employeeId = map.get("employeeId");
String firstName = map.get("firstName");
String lastName = map.get("lastName");
String userName = null;
System.out.println(employeeId+firstName+lastName);
QueryOptions qo = new QueryOptions();
qo.addFilter(Filter.eq("employeeId",employeeId));
Iterator users = context.search(Identity.class, qo);
while (users.hasNext()) {
Identity user = (Identity)users.next();
userName = user.getName();
}
System.out.println(userName);
if(userName == null){
if(firstName != null && lastName != null){
userName = firstName.trim()+"."+lastName.trim();
}
else if(firstName != null){
userName = firstName.trim();
}
else if(lastName != null){
userName = lastName.trim();
}
boolean isUnique = false;
Identity searchedUser = null;
String temp = userName;
int count = 0;
while(!isUnique){
count = count +1;
searchedUser = context.getObjectByName(Identity.class,temp);
if(searchedUser != null){
temp = userName +""+ count;
}
else{
isUnique = true;
userName = temp;
}
}
userName = userName.toLowerCase();
}
map.put( "userName", userName );
return map;
Comments
Post a Comment