Search in sources :

Example 1 with Sort

use of com.couchbase.client.java.query.dsl.Sort in project jans by JanssenProject.

the class CouchbaseEntryManager method findEntriesImpl.

protected <T> PagedResult<JsonObject> 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);
    ParsedKey keyWithInum = toCouchbaseKey(baseDN);
    ConvertedExpression convertedExpression;
    try {
        convertedExpression = toCouchbaseFilter(searchFilter, propertiesAnnotationsMap);
    } catch (SearchException ex) {
        throw new EntryPersistenceException(String.format("Failed to convert filter %s to expression", searchFilter));
    }
    PagedResult<JsonObject> searchResult = null;
    try {
        CouchbaseBatchOperationWraper<T> batchOperationWraper = null;
        if (batchOperation != null) {
            batchOperationWraper = new CouchbaseBatchOperationWraper<T>(batchOperation, this, entryClass, propertiesAnnotations);
        }
        searchResult = searchImpl(keyWithInum.getKey(), getScanConsistency(convertedExpression), convertedExpression.expression(), 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", keyWithInum.getKey(), convertedExpression));
        }
        return searchResult;
    } catch (Exception ex) {
        throw new EntryPersistenceException(String.format("Failed to find entries with key: %s, expression: %s", keyWithInum.getKey(), convertedExpression), ex);
    }
}
Also used : SearchException(io.jans.orm.exception.operation.SearchException) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) JsonObject(com.couchbase.client.java.document.json.JsonObject) MappingException(io.jans.orm.exception.MappingException) DateTimeException(java.time.DateTimeException) EntryDeleteException(io.jans.orm.exception.EntryDeleteException) DateTimeParseException(java.time.format.DateTimeParseException) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) SearchException(io.jans.orm.exception.operation.SearchException) AuthenticationException(io.jans.orm.exception.AuthenticationException) PropertyAnnotation(io.jans.orm.reflect.property.PropertyAnnotation) ISO_INSTANT(java.time.format.DateTimeFormatter.ISO_INSTANT) Filter(io.jans.orm.search.filter.Filter) ConvertedExpression(io.jans.orm.couchbase.model.ConvertedExpression) ParsedKey(io.jans.orm.impl.model.ParsedKey) Sort(com.couchbase.client.java.query.dsl.Sort)

Aggregations

JsonObject (com.couchbase.client.java.document.json.JsonObject)1 Sort (com.couchbase.client.java.query.dsl.Sort)1 ConvertedExpression (io.jans.orm.couchbase.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 ParsedKey (io.jans.orm.impl.model.ParsedKey)1 PropertyAnnotation (io.jans.orm.reflect.property.PropertyAnnotation)1 Filter (io.jans.orm.search.filter.Filter)1 DateTimeException (java.time.DateTimeException)1 ISO_INSTANT (java.time.format.DateTimeFormatter.ISO_INSTANT)1 DateTimeParseException (java.time.format.DateTimeParseException)1