import java.util.;
import java.lang.;
import sailpoint.object.QueryOptions;
import sailpoint.object.Filter;
import sailpoint.object.Identity;
import java.util.Iterator;
import java.util.ArrayList;
String source = identity.getAttribute(“source”);
String uniqueId = identity.getAttribute(“name”);
String emailOut = uniqueId + “@test.com”;
String emailOut2 = uniqueId + “@test.net”;
if (source.equalsIgnoreCase(“Outsource”)) {
return emailOut;
}
else if (source.equalsIgnoreCase(“CEBU”)) {
return emailOut2;
}
identity.setAttribute(“email”, null);
context.saveObject(identity);
context.commitTransaction();
String firstname = identity.getFirstname().replaceAll(“\.”,“”);
String middlename = identity.getAttribute(“middleName”);
String lastname = identity.getLastname().replaceAll(“\.”,“”);
if (middlename == null || middlename == void) {
middlename = “”;
} else {
middlename = identity.getAttribute(“middleName”).replaceAll(“\s”,“.”).toLowerCase();
}
String[] brokenFName = firstname.split(" ");
int counterFName = brokenFName.length;
String buildEmail = "";
int counterQuery = 0;
for (int i = counterFName; i > 0 ; i--){
buildEmail += brokenFName[counterQuery] + ".";
String checkEmail = (buildEmail + lastname.replaceAll(“\s”,“”)).toLowerCase() + “@test.com”;
String checkEmail2 = (buildEmail + lastname.replaceAll(“\s”,“”)).toLowerCase() + “@test.net”;
int counterDnN = 0;
//int counterDnN2 = 2;
counterDnN = queryFilter(checkEmail);
counterDnN = queryFilter(checkEmail2);
if (counterDnN == 0 ){
return checkEmail;
} if else (counterDnN != 0 ){
return checkEmail2;
}
//if else (counterDnN2 == 2 ){
//return checkEmail2;
//}
counterQuery++;
}
if (middlename == ""){
checkEmail = (buildEmail + middlename + "." + lastname.replaceAll("\\s","")).toLowerCase() + "@test.com";
counterDnN = queryFilter(checkEmail);
if (counterDnN == 0 ) {
return checkEmail;
} else {
i = 1;
String counterLastname = lastnameCounterWithMiddlename((buildEmail + middlename + "." + lastname.replaceAll("\\s","")).toLowerCase());
return counterLastname;
}
} else {
checkEmail = ((buildEmail + lastname.replaceAll("\\s","")).toLowerCase())+ "@test.com";
counterDnN = queryFilter(checkEmail);
if (counterDnN == 0 ) {
return checkEmail;
} else {
i = 1;
String counterLastname = lastnameCounterWithoutMiddlename((buildEmail + lastname.replaceAll("\\s","")).toLowerCase());
return counterLastname;
}
}
if (middlename == ""){
checkEmail2 = (buildEmail + middlename + "." + lastname.replaceAll("\\s","")).toLowerCase() + "test.net";
counterDnN = queryFilter(checkEmail2);
if (counterDnN != 0 ) {
return checkEmail2;
} else {
i = 1;
String counterLastname = lastnameCounterWithMiddlename((buildEmail + middlename + "." + lastname.replaceAll("\\s","")).toLowerCase());
return counterLastname;
}
} else {
checkEmail2 = ((buildEmail + lastname.replaceAll("\\s","")).toLowerCase())+ "@test.net";
counterDnN = queryFilter(checkEmail2);
if (counterDnN != 0 ) {
return checkEmail2;
} else {
i = 1;
String counterLastname = lastnameCounterWithoutMiddlename((buildEmail + lastname.replaceAll("\\s","")).toLowerCase());
return counterLastname;
}
}
context.decache(identity);