here i wanted to exclude roles that are disable. Only roles(bundles) that are Enabled should be displayed
QueryOptions qo = new QueryOptions();
Iterator it = context.search(Bundle.class, qo);
StringBuilder csvBuilder = new StringBuilder();
// Updated CSV header to include Role Name, Role Type, and Missing Entitlement
csvBuilder.append("Role Name,Role Type,Missing Entitlement\n");
while (it.hasNext()) {
Bundle bundle = it.next();
// Get role name and split to remove anything after the comma
String roleName = bundle.getName().split(",")[0].trim();
// Get role type (assuming the method is getRoleType())
String roleType = bundle.getType(); // Adjust this method based on your environment if needed.
List profiles = bundle.getProfiles();
for (Profile profile : Util.safeIterable(profiles)) {
List constraints = profile.getConstraints();
for (Filter cons : Util.safeIterable(constraints)) {
Application app = profile.getApplication();
if (app != null) {
Schema accountSchema = app.getAccountSchema();
if (accountSchema != null) {
if (cons instanceof Filter.LeafFilter) {
String property = cons.getProperty();
Object value = ((Filter.LeafFilter) cons).getValue();
List valueList = new ArrayList();
// Check if the value is a List or String
if (value instanceof List) {
valueList.addAll((List) value);
} else if (value instanceof String) {
valueList.add((String) value);
}
for (String entName : valueList) {
if (property != null && entName != null) {
// Get the part of entName before the first comma
String entitlementName = entName.split(",")[0].trim();
// Check if the entitlement exists in the ManagedAttribute catalog
ManagedAttribute ent = ManagedAttributer.get(context, app, property, entitlementName);
if (ent == null) {
// Entitlement is missing in the catalog
// Append Role Name, Role Type, and Missing Entitlement to the CSV
csvBuilder.append(String.format("%s,%s,%s\n", roleName, roleType, entitlementName));
}
}
}
}
}
}
}
}
}