At times there are use cases or for reporting purpose where we need all the direct and indirect reportees of a manager i.e. complete list of users who are reporting the user in who is in the hierarchical reporting structure of given user, below code will help you to find all such direct and indirect reportees of a given user.
import java.util.ArrayList;
import java.util.List;
import sailpoint.object.Identity;
import sailpoint.object.QueryOptions;
import sailpoint.object.Filter;
import sailpoint.api.IncrementalObjectIterator;
import sailpoint.tools.Util;
public List getAllReportees(String identityName){
List allreportees=new ArrayList();
QueryOptions managerQO=new QueryOptions();
managerQO.addFilter(Filter.eq("manager.name", identityName));
// Below conditions can be modified based on your Projects conditions to identify a valid regular user account
managerQO.addFilter(Filter.eq("correlated", true));
managerQO.addFilter(Filter.ne("type", "Service"));
managerQO.addFilter(Filter.ne("inactive", true));
IncrementalObjectIterator<Identity identityIterator=new IncrementalObjectIterator<Identity(context, Identity.class, managerQO);
while(identityIterator.hasNext())
{
Identity ident=(Identity)identityIterator.next();
String userName=ident.getName();
allreportees.add(userName);
if(isManager(userName)){
allreportees.addAll(getAllReportees(userName));
}
}
Util.flushIterator(identityIterator);
return allreportees;
}
public boolean isManager(String identityName){
boolean isManager=false;
QueryOptions managerQO=new QueryOptions();
managerQO.addFilter(Filter.eq("manager.name", identityName));
managerQO.addFilter(Filter.ne("name", identityName));
// Below conditions can be modified based on your Projects conditions to identify a valid regular user account
managerQO.addFilter(Filter.eq("correlated", true));
managerQO.addFilter(Filter.ne("type", "Service"));
managerQO.addFilter(Filter.ne("inactive", true));
IncrementalObjectIterator<Identity identityIterator=new IncrementalObjectIterator<Identity(context, Identity.class, managerQO);
if(identityIterator.hasNext())
{
isManager=true;
}
return isManager;
}
List allReports=new ArrayList();
return getAllReportees("USER_NAME");
Note - This can be used in use cases like where you want to validate the manager cyclic conditions etc.