Exclusion rule to remove IT roles mapped to business roles for certification review

@Aradhana_Mohapatra
In my opinion,

import sailpoint.object.Identity;
import sailpoint.object.Bundle;
import sailpoint.api.SailPointContext;
import sailpoint.tools.GeneralException;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import org.apache.log4j.Level;

String targetIdentity = entity.getCertifiers();
if (Log.isDebugEnabled()) Log.debug("targetIdentity: " + targetIdentity);

List certItems = entity.getItems();
ArrayList rolesToBeExcluded = new ArrayList();

for (CertificationItem certItem : certItems) {
    String bundleName = certItem.getBundle(); // Declare bundleName as String
    if (Log.isDebugEnabled()) Log.debug("bundleName: " + bundleName);

    Bundle bundle = context.getObjectByName(Bundle.class, bundleName);

    if (bundle != null && "business".equalsIgnoreCase(bundle.getType())) { // Ensure bundle is not null and check type
        List<Bundle> requiredRoles = bundle.getRequirements(); // Assuming getRequirements() fetches the required roles
        for (Bundle requiredRole : requiredRoles) {
            rolesToBeExcluded.add(requiredRole.getName()); // Add names of required roles to rolesToBeExcluded
        }
    }
}

// Now, iterate over certItems again to exclude items based on rolesToBeExcluded
ArrayList itemsToExclude = new ArrayList();
for (CertificationItem certItem : certItems) {
    Bundle bundle = context.getObjectByName(Bundle.class, certItem.getBundle());
    if (bundle != null && rolesToBeExcluded.contains(bundle.getName())) {
        itemsToExclude.add(certItem);
    }
}

if (Log.isDebugEnabled()) Log.debug("================== END ======================");

// Remove the IT roles from the items list.
certItems.removeAll(itemsToExclude);

return "This item has been excluded";

Key Points:

  1. Added type String to the variable bundleName:

String bundleName = certItem.getBundle();

  1. Ensured proper usage of curly braces {} in all conditional blocks:
if (bundle != null && "business".equalsIgnoreCase(bundle.getType())) {
    // ...
}
  1. Changed items to certItems in the removal operation:

certItems.removeAll(itemsToExclude);

Regards,
Adam

4 Likes