Search in sources :

Example 31 with SearchResultEntry

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

the class LdapOperationsServiceImpl method searchSearchResult.

/*
     * (non-Javadoc)
     *
     * @see org.gluu.site.ldap.PlatformOperationFacade#searchSearchResult(java.lang.
     * String, com.unboundid.ldap.sdk.Filter, org.xdi.ldap.model.SearchScope, int,
     * int, int, java.lang.String, org.xdi.ldap.model.SortOrder,
     * org.xdi.ldap.model.VirtualListViewResponse, java.lang.String)
     */
@Override
public SearchResult searchSearchResult(String dn, Filter filter, SearchScope scope, int startIndex, int count, int searchLimit, String sortBy, SortOrder sortOrder, ListViewResponse vlvResponse, String... attributes) throws Exception {
    if (StringHelper.equalsIgnoreCase(dn, "o=gluu")) {
        (new Exception()).printStackTrace();
    }
    SearchRequest searchRequest;
    if (attributes == null) {
        searchRequest = new SearchRequest(dn, scope, filter);
    } else {
        searchRequest = new SearchRequest(dn, scope, filter, attributes);
    }
    List<SearchResult> searchResultList = new ArrayList<SearchResult>();
    List<SearchResultEntry> searchResultEntries = new ArrayList<SearchResultEntry>();
    List<SearchResultReference> searchResultReferences = new ArrayList<SearchResultReference>();
    searchRequest.setControls(new SimplePagedResultsControl(searchLimit));
    SearchResult searchResult = getConnectionPool().search(searchRequest);
    List<SearchResultEntry> resultSearchResultEntries = searchResult.getSearchEntries();
    int totalResults = resultSearchResultEntries.size();
    if (StringUtils.isNotEmpty(sortBy)) {
        boolean ascending = sortOrder == null || sortOrder.equals(SortOrder.ASCENDING);
        resultSearchResultEntries = sortListByAttributes(resultSearchResultEntries, SearchResultEntry.class, false, ascending, sortBy);
    }
    List<SearchResultEntry> searchResultEntryList = new ArrayList<SearchResultEntry>();
    if (startIndex <= totalResults) {
        int diff = (totalResults - startIndex);
        if (diff <= count) {
            count = (diff + 1) >= count ? count : (diff + 1);
        }
        int startZeroIndex = startIndex - 1;
        searchResultEntryList = resultSearchResultEntries.subList(startZeroIndex, startZeroIndex + count);
    }
    searchResultList.add(searchResult);
    searchResultEntries.addAll(searchResultEntryList);
    searchResultReferences.addAll(searchResult.getSearchReferences());
    SearchResult searchResultTemp = searchResultList.get(0);
    searchResult = new SearchResult(searchResultTemp.getMessageID(), searchResultTemp.getResultCode(), searchResultTemp.getDiagnosticMessage(), searchResultTemp.getMatchedDN(), searchResultTemp.getReferralURLs(), searchResultEntries, searchResultReferences, searchResultEntries.size(), searchResultReferences.size(), searchResultTemp.getResponseControls());
    // Get results info
    vlvResponse.setItemsPerPage(count);
    vlvResponse.setTotalResults(totalResults);
    vlvResponse.setStartIndex(startIndex);
    return searchResult;
}
Also used : SearchRequest(com.unboundid.ldap.sdk.SearchRequest) ArrayList(java.util.ArrayList) SearchResultReference(com.unboundid.ldap.sdk.SearchResultReference) SearchResult(com.unboundid.ldap.sdk.SearchResult) SimplePagedResultsControl(com.unboundid.ldap.sdk.controls.SimplePagedResultsControl) InvalidSimplePageControlException(org.gluu.persist.ldap.exception.InvalidSimplePageControlException) ConnectionException(org.gluu.persist.exception.operation.ConnectionException) SearchException(org.gluu.persist.exception.operation.SearchException) LDAPSearchException(com.unboundid.ldap.sdk.LDAPSearchException) MappingException(org.gluu.persist.exception.mapping.MappingException) LDAPException(com.unboundid.ldap.sdk.LDAPException) DuplicateEntryException(org.gluu.persist.exception.operation.DuplicateEntryException) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry)

Aggregations

SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)31 SearchResult (com.unboundid.ldap.sdk.SearchResult)22 ArrayList (java.util.ArrayList)13 LDAPException (com.unboundid.ldap.sdk.LDAPException)11 SearchException (org.gluu.persist.exception.operation.SearchException)10 MappingException (org.gluu.persist.exception.mapping.MappingException)9 ConnectionException (org.gluu.persist.exception.operation.ConnectionException)9 SearchRequest (com.unboundid.ldap.sdk.SearchRequest)7 EntryPersistenceException (org.gluu.persist.exception.mapping.EntryPersistenceException)7 LdapConnection (com.gitblit.ldap.LdapConnection)6 ParseException (java.text.ParseException)6 AuthenticationException (org.gluu.persist.exception.operation.AuthenticationException)6 SearchScopeException (org.gluu.persist.exception.operation.SearchScopeException)6 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)5 BindResult (com.unboundid.ldap.sdk.BindResult)5 LDAPSearchException (com.unboundid.ldap.sdk.LDAPSearchException)5 TeamModel (com.gitblit.models.TeamModel)4 Attribute (com.unboundid.ldap.sdk.Attribute)4 LinkedList (java.util.LinkedList)4 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)3