Search in sources :

Example 61 with Filter

use of io.jans.orm.search.filter.Filter in project jans by JanssenProject.

the class SqlFilterConverterTest method checkMultivaluedPresenceFilters.

@Test
public void checkMultivaluedPresenceFilters() throws SearchException {
    // Presence -- String
    Filter filterPresence1 = Filter.createPresenceFilter("uid").multiValued();
    ConvertedExpression expressionPresence1 = simpleConverter.convertToSqlFilter(filterPresence1, null, null);
    String queryPresence1 = toSelectSQL(expressionPresence1);
    assertEquals(queryPresence1, "select doc.`*` from `table` as doc where doc.uid->'$.v[0]' is not null");
    // Presence -- String -- Multivalued = 3
    Filter filterPresence2 = Filter.createPresenceFilter("uid").multiValued(3);
    ConvertedExpression expressionPresence2 = simpleConverter.convertToSqlFilter(filterPresence2, null, null);
    String queryPresence2 = toSelectSQL(expressionPresence2);
    assertEquals(queryPresence2, "select doc.`*` from `table` as doc where doc.uid->'$.v[0]' is not null or doc.uid->'$.v[1]' is not null or doc.uid->'$.v[2]' is not null");
}
Also used : Filter(io.jans.orm.search.filter.Filter) ConvertedExpression(io.jans.orm.sql.model.ConvertedExpression) Test(org.testng.annotations.Test)

Example 62 with Filter

use of io.jans.orm.search.filter.Filter in project jans by JanssenProject.

the class SqlFilterConverterTest method checkPresenceFilters.

@Test
public void checkPresenceFilters() throws SearchException {
    // Presence -- String
    Filter filterPresence = Filter.createPresenceFilter("uid");
    ConvertedExpression expressionPresence = simpleConverter.convertToSqlFilter(filterPresence, null, null);
    String queryPresence = toSelectSQL(expressionPresence);
    assertEquals(queryPresence, "select doc.`*` from `table` as doc where doc.uid is not null");
}
Also used : Filter(io.jans.orm.search.filter.Filter) ConvertedExpression(io.jans.orm.sql.model.ConvertedExpression) Test(org.testng.annotations.Test)

Example 63 with Filter

use of io.jans.orm.search.filter.Filter in project jans by JanssenProject.

the class SqlFilterConverterTest method checkEqFilters.

@Test
public void checkEqFilters() throws SearchException {
    // EQ -- String
    Filter filterEq1 = Filter.createEqualityFilter("uid", "test");
    ConvertedExpression expressionEq1 = simpleConverter.convertToSqlFilter(filterEq1, null, null);
    String queryEq1 = toSelectSQL(expressionEq1);
    assertEquals(queryEq1, "select doc.`*` from `table` as doc where doc.uid = 'test'");
    // EQ -- Integer
    Filter filterEq2 = Filter.createEqualityFilter("age", 23);
    ConvertedExpression expressionEq2 = simpleConverter.convertToSqlFilter(filterEq2, null, null);
    String queryEq2 = toSelectSQL(expressionEq2);
    assertEquals(queryEq2, "select doc.`*` from `table` as doc where doc.age = 23");
    // EQ -- Long
    Filter filterEq3 = Filter.createEqualityFilter("age", 23L);
    ConvertedExpression expressionEq3 = simpleConverter.convertToSqlFilter(filterEq3, null, null);
    String queryEq3 = toSelectSQL(expressionEq3);
    assertEquals(queryEq3, "select doc.`*` from `table` as doc where doc.age = 23");
    // EQ -- Date
    Filter filterEq4 = Filter.createEqualityFilter("added", getUtcDateFromMillis(1608130698398L));
    ConvertedExpression expressionEq4 = simpleConverter.convertToSqlFilter(filterEq4, null, null);
    String queryEq4 = toSelectSQL(expressionEq4);
    assertEquals(queryEq4, "select doc.`*` from `table` as doc where doc.added = '2020-12-16T14:58:18.398'");
}
Also used : Filter(io.jans.orm.search.filter.Filter) ConvertedExpression(io.jans.orm.sql.model.ConvertedExpression) Test(org.testng.annotations.Test)

Example 64 with Filter

use of io.jans.orm.search.filter.Filter in project jans by JanssenProject.

the class SqlFilterConverterTest method checkMultivaluedLowerFilters.

@Test
public void checkMultivaluedLowerFilters() throws SearchException {
    Filter userUidFilter = Filter.createEqualityFilter(Filter.createLowercaseFilter("uid"), "test").multiValued();
    ConvertedExpression expressionUserUid = simpleConverter.convertToSqlFilter(userUidFilter, null, null);
    String queryUserUid = toSelectSQL(expressionUserUid);
    assertEquals(queryUserUid, "select doc.`*` from `table` as doc where JSON_CONTAINS(lower(doc.uid)->'$.v', CAST('[\"test\"]' AS JSON))");
}
Also used : Filter(io.jans.orm.search.filter.Filter) ConvertedExpression(io.jans.orm.sql.model.ConvertedExpression) Test(org.testng.annotations.Test)

Example 65 with Filter

use of io.jans.orm.search.filter.Filter in project jans by JanssenProject.

the class SqlEntryManager 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
    OrderSpecifier<?>[] defaultSort = getDefaultSort(entryClass);
    if (StringHelper.isNotEmpty(sortBy)) {
        OrderSpecifier<?> requestedSort = buildSort(sortBy, sortOrder);
        if (ArrayHelper.isEmpty(defaultSort)) {
            defaultSort = new OrderSpecifier[] { requestedSort };
        } else {
            defaultSort = ArrayHelper.arrayMerge(new OrderSpecifier[] { requestedSort }, defaultSort);
        }
    }
    // Prepare properties types to allow build filter properly
    Map<String, PropertyAnnotation> propertiesAnnotationsMap = prepareEntryPropertiesTypes(entryClass, propertiesAnnotations);
    ParsedKey keyWithInum = toSQLKey(baseDN);
    ConvertedExpression convertedExpression;
    try {
        convertedExpression = toSqlFilter(searchFilter, propertiesAnnotationsMap);
    } catch (SearchException ex) {
        throw new EntryPersistenceException(String.format("Failed to convert filter '%s' to expression", searchFilter));
    }
    PagedResult<EntryData> searchResult = null;
    try {
        SqlBatchOperationWraper<T> batchOperationWraper = null;
        if (batchOperation != null) {
            batchOperationWraper = new SqlBatchOperationWraper<T>(batchOperation, this, entryClass, propertiesAnnotations);
        }
        searchResult = searchImpl(keyWithInum.getKey(), 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'", keyWithInum.getKey(), convertedExpression));
        }
        return searchResult;
    } catch (SearchException ex) {
        throw new EntryPersistenceException(String.format("Failed to find entries with key: '%s'", keyWithInum.getKey()), ex);
    } catch (Exception ex) {
        throw new EntryPersistenceException(String.format("Failed to find entries with key: '%s', expression: '%s'", keyWithInum.getKey(), 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) DateTimeParseException(java.time.format.DateTimeParseException) AuthenticationException(io.jans.orm.exception.AuthenticationException) PropertyAnnotation(io.jans.orm.reflect.property.PropertyAnnotation) Filter(io.jans.orm.search.filter.Filter) ConvertedExpression(io.jans.orm.sql.model.ConvertedExpression) ParsedKey(io.jans.orm.impl.model.ParsedKey) OrderSpecifier(com.querydsl.core.types.OrderSpecifier)

Aggregations

Filter (io.jans.orm.search.filter.Filter)188 Test (org.testng.annotations.Test)50 EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)32 ConvertedExpression (io.jans.orm.couchbase.model.ConvertedExpression)28 SearchException (io.jans.orm.exception.operation.SearchException)25 ConvertedExpression (io.jans.orm.sql.model.ConvertedExpression)24 MappingException (io.jans.orm.exception.MappingException)22 ArrayList (java.util.ArrayList)21 AuthenticationException (io.jans.orm.exception.AuthenticationException)20 PropertyAnnotation (io.jans.orm.reflect.property.PropertyAnnotation)19 EntryDeleteException (io.jans.orm.exception.EntryDeleteException)18 Date (java.util.Date)14 List (java.util.List)14 SqlEntryManager (io.jans.orm.sql.impl.SqlEntryManager)11 SqlEntryManagerSample (io.jans.orm.sql.persistence.SqlEntryManagerSample)11 CustomAttribute (io.jans.orm.model.base.CustomAttribute)9 CustomObjectAttribute (io.jans.orm.model.base.CustomObjectAttribute)9 DateTimeParseException (java.time.format.DateTimeParseException)9 SpannerEntryManager (io.jans.orm.cloud.spanner.impl.SpannerEntryManager)8 SpannerEntryManagerSample (io.jans.orm.cloud.spanner.persistence.SpannerEntryManagerSample)8