@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:
- Added type
String
to the variablebundleName
:
String bundleName = certItem.getBundle();
- Ensured proper usage of curly braces
{}
in all conditional blocks:
if (bundle != null && "business".equalsIgnoreCase(bundle.getType())) {
// ...
}
- Changed
items
tocertItems
in the removal operation:
certItems.removeAll(itemsToExclude);
Regards,
Adam