How can I optimize my code using filter to get birthright role

Which IIQ version are you inquiring about?

Version 8.3

Share all details related to your problem, including any error messages you may have received.

import java.util.ArrayList;
import java.util.*;
import sailpoint.api.SailPointContext;
import sailpoint.object.Identity;
import sailpoint.object.QueryOptions;
import sailpoint.object.Filter;
import sailpoint.object.Application;
import sailpoint.object.Link;
import sailpoint.object.ManagedAttribute;
import sailpoint.object.Bundle;
import sailpoint.object.AuditEvent;
import sailpoint.object.IdentityRequest;
import sailpoint.tools.GeneralException;
import sailpoint.object.AuditEvent;
import java.util.List;

int countBirthright=0;
System.out.println(“Birthright Code Execution!!!”);
Set<String> requiredApps = new HashSet();
requiredApps.add(“TSM”);
requiredApps.add(“ForgeRock - EIAM”);
requiredApps.add(“Meta DB - TEST”);

QueryOptions qo10 = new QueryOptions();
Filter f50 = Filter.eq(“inactive”, false);
qo10.addFilter(Filter.notnull(“name”));

qo10.addFilter(f50);

List IdentityList = context.getObjects(Identity.class, qo10);
int temp = IdentityList.size();
String appName;

for (Identity identity : IdentityList) {
List<Link> links = identity.getLinks(); // Correctly treat it as a list
List<String> foundApps = new ArrayList();
for (Link link : links) { // Iterate over the list
appName = link.getApplicationName();
if (requiredApps.contains(appName)) {
foundApps.add(appName);
}
}
if (foundApps.size() == 0) {
countBirthright++;
}

System.out.println(identity.getName());

break;
}
System.out.println("Total Count is "+countBirthright);
return countBirthright;

you could also try building this filter via advanced analytics adanced search option

Yes, but this is some part of mycode which is taking time to execute.

try using hasAccounts API of IdentityService class

You should avoid using context.getObjects
Instead use context.search which returns a iterator and get the identity object during iteration

Use the below code.

import sailpoint.object.Identity;
import sailpoint.object.QueryOptions;
import sailpoint.object.Filter;

int countBirthright=0;

QueryOptions qo = new QueryOptions();
qo.addFilter(Filter.eq("inactive", false));
qo.addFilter(Filter.notnull("name"));

Filter app1 = Filter.eq("links.application.name", "TSM");
Filter app2 = Filter.eq("links.application.name", "ForgeRock - EIAM");
Filter app3 = Filter.eq("links.application.name", "Meta DB - TEST");

Filter appFilter = Filter.or(f1, f2, f3);

qo.addFilter(appFilter);

countBirthright = context.countObjects(Identity.class, qo);

return countBirthright;

Thanks
Krish

5 Likes

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.