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;
}
Aggregations