Remove Dupe entitlements from entitlement catalogue

Hi,
We have a webservice application in which Entitlements are getting created twice onw with app guid invalue and other with correct display name in value (when we run group aggregation dupe entitlements are getting created twice). In order to remove dupe entitlement one with guid value, wrote a custom rule to remove it from entitlement catalogue but not from target system.
I am gettign object cast error to string value. Can anyone suggest what is missing in below code.

import sailpoint.api.SailPointContext;
import sailpoint.object.Filter;
import sailpoint.object.Identity;
import sailpoint.object.ManagedAttribute;
import sailpoint.object.QueryOptions;
import sailpoint.tools.GeneralException;
import org.apache.commons.lang.time.DateUtils;
import sailpoint.object.ObjectClassification;
import sailpoint.api.IncrementalObjectIterator;
import sailpoint.api.Terminator;
import sailpoint.api.*;
import sailpoint.tools.Util;
import java.util.Iterator;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;
QueryOptions qo = new QueryOptions();
queryOptions.addFilter(Filter.eq(“application.name”,“ABC”));
Terminator terminator = new Terminator(context);
Iterator itr = context.search(ManagedAttribute.class ,queryOptions, “id”);
while(itr.hasNext()){

     ManagedAttribute managedAttr = (ManagedAttribute) itr.next();
String DisplayName = managedAttr.getDisplayName();
 String Value = managedAttr.getValue();
 log.error("DispalyName log error1:::"+DisplayName);
 log.error("EntValue log error1:::"+Value);
 String maId =  itr.next()[0];
 if (!DisplayName.equals(Value)){
ManagedAttribute managedAttribute = context.getObjectById(ManagedAttribute.class,maId);
terminator.deleteObject(managedAttribute);

}
}

Hi @Preethi

I just modified your code bit, can you try with this code.

import sailpoint.api.SailPointContext;
import sailpoint.object.Filter;
import sailpoint.object.Identity;
import sailpoint.object.ManagedAttribute;
import sailpoint.object.QueryOptions;
import sailpoint.tools.GeneralException;
import org.apache.commons.lang.time.DateUtils;
import sailpoint.object.ObjectClassification;
import sailpoint.api.IncrementalObjectIterator;
import sailpoint.api.Terminator;
import sailpoint.api.*;
import sailpoint.tools.Util;
import java.util.Iterator;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;

QueryOptions qo = new QueryOptions();
queryOptions.addFilter(Filter.eq(“application.name”,“ABC”));
Terminator terminator = new Terminator(context);
Iterator itr = context.search(ManagedAttribute.class ,queryOptions);
while(itr.hasNext()){
	ManagedAttribute managedAttr = (ManagedAttribute) itr.next();
	String DisplayName = managedAttr.getDisplayName();
	String Value = managedAttr.getValue();
	log.error("DispalyName log error1:::"+DisplayName);
	log.error("EntValue log error1:::"+Value);
	if (!DisplayName.equals(Value)){
		terminator.deleteObject(managedAttr);
	}
}

Hi @Arpitha1
we are getting null pointer exception…

Loggers are added. Can you check your logs and see where the null pointer is coming.

@Preethi
Try using getDisplayableName() instead of getDisplayName(), this may resolve the null pointer exception

@iamksatish
Still getting null pointer exception

@Preethi
In your original code, you’re using a projection query to pull the “id” field which is a String. You’re trying to cast that id string to a ManagedAttribute which won’t work. As for the NPE, you’re naming your QueryOptions variable qo but then calling it queryOptions on the next line. You probably want something like this:

import sailpoint.object.Filter;
import sailpoint.object.ManagedAttribute;
import sailpoint.object.QueryOptions;
import sailpoint.tools.GeneralException;
import sailpoint.api.IncrementalObjectIterator;
import sailpoint.api.Terminator;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;
import sailpoint.api.IncrementalObjectIterator;


    QueryOptions qo = new QueryOptions();
    qo.addFilter(Filter.eq(“application.name”,“ABC”));
    Terminator terminator = new Terminator(context);
    IncrementalObjectIterator iter = new IncrementalObjectIterator(context, ManagedAttribute.class, qo)

    while(itr.hasNext()){
        ManagedAttribute managedAttr = (ManagedAttribute) iter.next();
        String DisplayName = managedAttr.getDisplayName();
        String Value = managedAttr.getValue();
        log.error("DispalyName log error1:::"+DisplayName);
        log.error("EntValue log error1:::"+Value);
        if (null != DisplayName) {
            if (!DisplayName.equals(Value)){
                terminator.deleteObject(managedAttribute);
            }
        }
    }

@drardin That was already corrected. Please find below the updated code where null pointer exception still occurs.

import sailpoint.api.SailPointContext;
import sailpoint.object.Filter;
import sailpoint.object.Identity;
import sailpoint.object.ManagedAttribute;
import sailpoint.object.QueryOptions;
import sailpoint.tools.GeneralException;
import org.apache.commons.lang.time.DateUtils;
import sailpoint.object.ObjectClassification;
import sailpoint.api.IncrementalObjectIterator;
import sailpoint.api.Terminator;
import sailpoint.api.*;
import sailpoint.tools.Util;
import java.util.Iterator;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;

QueryOptions qo = new QueryOptions();
qo.addFilter(Filter.eq(“application.name”,“ABC”));
Terminator terminator = new Terminator(context);
Iterator itr = context.search(ManagedAttribute.class ,qo);
while(itr.hasNext()){
ManagedAttribute managedAttr = (ManagedAttribute) itr.next();
String DisplayName = managedAttr.getDisplayableName();
String Value = managedAttr.getValue();
log.error(“DispalyName log error1:::”+DisplayName);
log.error(“EntValue log error1:::”+Value);
if (null != DisplayName) {
if (!DisplayName.equals(Value)){
terminator.deleteObject(managedAttr);
}}
}

@Preethi try

import sailpoint.api.SailPointContext;
import sailpoint.object.Filter;
import sailpoint.object.Identity;
import sailpoint.object.ManagedAttribute;
import sailpoint.object.QueryOptions;
import sailpoint.tools.GeneralException;
import org.apache.commons.lang.time.DateUtils;
import sailpoint.object.ObjectClassification;
import sailpoint.api.IncrementalObjectIterator;
import sailpoint.api.Terminator;
import sailpoint.api.*;
import sailpoint.tools.Util;
import java.util.Iterator;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.lang3.StringUtils;

QueryOptions qo = new QueryOptions();
qo.addFilter(Filter.eq(“application.name”,“ABC”));
Terminator terminator = new Terminator(context);
Iterator itr = context.search(ManagedAttribute.class ,qo);
while(itr.hasNext()){
ManagedAttribute managedAttr = (ManagedAttribute) itr.next();
String DisplayName = managedAttr.getDisplayableName();
String Value = managedAttr.getValue();
log.error(“DispalyName log error1:::”+DisplayName);
log.error(“EntValue log error1:::”+Value);

if (!StringUtils.equals(DisplayName, Value)){ 
terminator.deleteObject(managedAttr);
context.commitTransaction();
}
}

Also after which log you see nullpointer ?

You might need to null check the itr before the itr.hasNext() call and the managedAttr before the managedAttr.getDisplayableName() call as well then. If that doesn’t fix it, you probably need a lot more logging, because there aren’t very many things left that could be null besides the actual log object itself.