Search in sources :

Example 1 with Sort

use of io.jans.orm.model.Sort in project jans by JanssenProject.

the class SpannerEntryManager method findEntriesImpl.

protected <T> PagedResult<EntryData> findEntriesImpl(String baseDN, Class<T> entryClass, Filter filter, SearchScope scope, String[] ldapReturnAttributes, String sortBy, SortOrder sortOrder, BatchOperation<T> batchOperation, SearchReturnDataType returnDataType, int start, int count, int chunkSize) {
    // Check entry class
    checkEntryClass(entryClass, false);
    String[] objectClasses = getTypeObjectClasses(entryClass);
    List<PropertyAnnotation> propertiesAnnotations = getEntryPropertyAnnotations(entryClass);
    String[] currentLdapReturnAttributes = ldapReturnAttributes;
    if (ArrayHelper.isEmpty(currentLdapReturnAttributes)) {
        currentLdapReturnAttributes = getAttributes(null, propertiesAnnotations, false);
    }
    Filter searchFilter;
    if (objectClasses.length > 0) {
        LOG.trace("Filter: {}", filter);
        searchFilter = addObjectClassFilter(filter, objectClasses);
    } else {
        searchFilter = filter;
    }
    // Find entries
    LOG.trace("-------------------------------------------------------");
    LOG.trace("Filter: {}", filter);
    LOG.trace("objectClasses count: {} ", objectClasses.length);
    LOG.trace("objectClasses: {}", ArrayHelper.toString(objectClasses));
    LOG.trace("Search filter: {}", searchFilter);
    // Prepare default sort
    Sort[] defaultSort = getDefaultSort(entryClass);
    if (StringHelper.isNotEmpty(sortBy)) {
        Sort requestedSort = buildSort(sortBy, sortOrder);
        if (ArrayHelper.isEmpty(defaultSort)) {
            defaultSort = new Sort[] { requestedSort };
        } else {
            defaultSort = ArrayHelper.arrayMerge(new Sort[] { requestedSort }, defaultSort);
        }
    }
    // Prepare properties types to allow build filter properly
    Map<String, PropertyAnnotation> propertiesAnnotationsMap = prepareEntryPropertiesTypes(entryClass, propertiesAnnotations);
    String key = toSQLKey(baseDN).getKey();
    ConvertedExpression convertedExpression;
    try {
        convertedExpression = toSqlFilter(key, objectClasses[0], searchFilter, propertiesAnnotationsMap);
    } catch (SearchException ex) {
        throw new EntryPersistenceException(String.format("Failed to convert filter '%s' to expression", searchFilter), ex);
    }
    PagedResult<EntryData> searchResult = null;
    try {
        SpannerBatchOperationWraper<T> batchOperationWraper = null;
        if (batchOperation != null) {
            batchOperationWraper = new SpannerBatchOperationWraper<T>(batchOperation, this, entryClass, propertiesAnnotations);
        }
        searchResult = searchImpl(key, objectClasses[0], convertedExpression, scope, currentLdapReturnAttributes, defaultSort, batchOperationWraper, returnDataType, start, count, chunkSize);
        if (searchResult == null) {
            throw new EntryPersistenceException(String.format("Failed to find entries with key: '%s', expression: '%s'", key, convertedExpression));
        }
        return searchResult;
    } catch (SearchException ex) {
        throw new EntryPersistenceException(String.format("Failed to find entries with key: '%s'", key), ex);
    } catch (Exception ex) {
        throw new EntryPersistenceException(String.format("Failed to find entries with key: '%s', expression: '%s'", key, convertedExpression), ex);
    }
}
Also used : EntryData(io.jans.orm.model.EntryData) SearchException(io.jans.orm.exception.operation.SearchException) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) MappingException(io.jans.orm.exception.MappingException) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) EntryDeleteException(io.jans.orm.exception.EntryDeleteException) SearchException(io.jans.orm.exception.operation.SearchException) AuthenticationException(io.jans.orm.exception.AuthenticationException) PropertyAnnotation(io.jans.orm.reflect.property.PropertyAnnotation) Filter(io.jans.orm.search.filter.Filter) ConvertedExpression(io.jans.orm.cloud.spanner.model.ConvertedExpression) Sort(io.jans.orm.model.Sort)

Example 2 with Sort

use of io.jans.orm.model.Sort in project jans by JanssenProject.

the class SpannerEntryManager method getDefaultSort.

protected <T> Sort[] getDefaultSort(Class<T> entryClass) {
    String[] sortByProperties = getEntrySortByNames(entryClass);
    if (ArrayHelper.isEmpty(sortByProperties)) {
        // Fall back to sortBy property name
        sortByProperties = getEntrySortByProperties(entryClass);
        if (ArrayHelper.isEmpty(sortByProperties)) {
            return null;
        }
    }
    Sort[] sort = new Sort[sortByProperties.length];
    for (int i = 0; i < sortByProperties.length; i++) {
        sort[i] = new Sort(sortByProperties[i], SortOrder.ASCENDING);
    }
    return sort;
}
Also used : Sort(io.jans.orm.model.Sort)

Aggregations

Sort (io.jans.orm.model.Sort)2 ConvertedExpression (io.jans.orm.cloud.spanner.model.ConvertedExpression)1 AuthenticationException (io.jans.orm.exception.AuthenticationException)1 EntryDeleteException (io.jans.orm.exception.EntryDeleteException)1 EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)1 MappingException (io.jans.orm.exception.MappingException)1 SearchException (io.jans.orm.exception.operation.SearchException)1 EntryData (io.jans.orm.model.EntryData)1 PropertyAnnotation (io.jans.orm.reflect.property.PropertyAnnotation)1 Filter (io.jans.orm.search.filter.Filter)1