api.ObjectUtil.getWorkgroupMembers(...);
/**
* Given an Identity that is a workgroup Iterator over the properties
* of a groups' members. This method does a projection query.
*/
public static Iterator<Object[]> getWorkgroupMembers(SailPointContext ctx, Identity identity, List<String> props )
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Rule PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<Rule language="beanshell" name="Workgroup Membership Report">
<Source>
<![CDATA[
import java.io.File;
import java.io.FileInputStream;
import sailpoint.object.Identity;
import sailpoint.object.QueryOptions;
import sailpoint.object.Filter;
import sailpoint.object.EmailTemplate;
import sailpoint.object.EmailOptions;
import sailpoint.object.EmailFileAttachment;
import java.util.List;
import java.lang.StringBuilder;
import sailpoint.api.ObjectUtil;
String header = "Workgroup,members,size\n";
StringBuilder builder=new StringBuilder();
builder.append(header);
boolean hasIdentities = false;
try{
QueryOptions qo = new QueryOptions();
qo.addFilter(Filter.eq("workgroup",Boolean.TRUE));
List workGroups = context.getObjects(Identity.class,qo);
for(Identity ident : workGroups){
List wrkgmemnberList = new ArrayList();
log.warn("Workgroup name - "+ident.getName()+"\nMembers");
Identity workgroup = context.getObjectByName(Identity.class, ident.getName());
if(workgroup.isWorkgroup()){
//Integer size = 0;
Iterator wrkGrpmembers = ObjectUtil.getWorkgroupMembers(context, workgroup, null);
while(wrkGrpmembers.hasNext()){
Object[] object = (Object[]) wrkGrpmembers.next();
Identity ids = (Identity) object[0];
wrkgmemnberList.add(ids.getName());
System.out.println(ids.getName()+" - "+ids.isInactive());
}
if(wrkgmemnberList.size()>0){
builder.append(workgroup.getName()+","+wrkgmemnberList+","+wrkgmemnberList.size()+"\n");
hasIdentities = true;
}
}
}
}catch(Exception e){
e.printStackTrace();
}
if(hasIdentities){
try{
String fileName = "Workgroup Members Report.csv";
byte[] fileData = builder.toString().getBytes();
EmailTemplate emailTemplate = context.getObject( EmailTemplate.class, "Report Completion" );
EmailOptions emailOptions = new EmailOptions();
List toAddress = Arrays.asList(new String[]{"JP@xxx.com"});
emailOptions.setTo(toAddress);
emailOptions.setVariable("reportName", "Workgroup Members Report");
EmailFileAttachment attachment = new EmailFileAttachment( fileName, EmailFileAttachment.MimeType.MIME_CSV, fileData );
emailOptions.addAttachment( attachment );
context.sendEmailNotification( emailTemplate, emailOptions );
}
catch(Exception e){
log.error("Failed to send User Status Report");
log.error(e.toString());
}
}
return "Goodbye!";
]]>
</Source>
</Rule>