Search in sources :

Example 1 with LDAPSearchException

use of com.unboundid.ldap.sdk.LDAPSearchException in project oxCore by GluuFederation.

the class LdifDataUtility method deleteEntryWithAllSubs.

/**
	 * Remove base entry with all sub entries
	 * 
	 * @param connection
	 *            Connection to LDAP server
	 * @param baseDN
	 *            Base DN entry
	 * @return The result code for the processing that was performed.
	 */
public ResultCode deleteEntryWithAllSubs(LDAPConnection connection, String baseDN) {
    ResultCode resultCode = ResultCode.SUCCESS;
    SearchResult searchResult = null;
    try {
        searchResult = connection.search(baseDN, SearchScope.SUB, "objectClass=*");
        if ((searchResult == null) || (searchResult.getEntryCount() == 0)) {
            return ResultCode.LOCAL_ERROR;
        }
    } catch (LDAPSearchException le) {
        log.error("Failed to search subordinate entries", le);
        return ResultCode.LOCAL_ERROR;
    }
    LinkedList<String> dns = new LinkedList<String>();
    for (SearchResultEntry entry : searchResult.getSearchEntries()) {
        dns.add(entry.getDN());
    }
    ListIterator<String> listIterator = dns.listIterator(dns.size());
    while (listIterator.hasPrevious()) {
        try {
            connection.delete(listIterator.previous());
        } catch (LDAPException le) {
            log.error("Failed to delete entry", le);
            resultCode = ResultCode.LOCAL_ERROR;
            break;
        }
    }
    return resultCode;
}
Also used : LDAPException(com.unboundid.ldap.sdk.LDAPException) LDAPSearchException(com.unboundid.ldap.sdk.LDAPSearchException) SearchResult(com.unboundid.ldap.sdk.SearchResult) ResultCode(com.unboundid.ldap.sdk.ResultCode) LinkedList(java.util.LinkedList) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry)

Aggregations

LDAPException (com.unboundid.ldap.sdk.LDAPException)1 LDAPSearchException (com.unboundid.ldap.sdk.LDAPSearchException)1 ResultCode (com.unboundid.ldap.sdk.ResultCode)1 SearchResult (com.unboundid.ldap.sdk.SearchResult)1 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)1 LinkedList (java.util.LinkedList)1