Search in sources :

Example 56 with Filter

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

the class SqlFilterConverterTest method checkMultivaluedEqFilters.

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

Example 57 with Filter

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

the class SqlFilterConverterTest method checkLowerFilters.

@Test
public void checkLowerFilters() throws SearchException {
    Filter userUidFilter1 = Filter.createEqualityFilter(Filter.createLowercaseFilter("uid"), "test");
    ConvertedExpression expressionUserUid1 = simpleConverter.convertToSqlFilter(userUidFilter1, null, null);
    String queryUserUid1 = toSelectSQL(expressionUserUid1);
    assertEquals(queryUserUid1, "select doc.`*` from `table` as doc where lower(doc.uid) = 'test'");
}
Also used : Filter(io.jans.orm.search.filter.Filter) ConvertedExpression(io.jans.orm.sql.model.ConvertedExpression) Test(org.testng.annotations.Test)

Example 58 with Filter

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

the class SqlFilterConverterTest method checkMultivaluedLeFilters.

@Test
public void checkMultivaluedLeFilters() throws SearchException {
    // LE -- String
    Filter filterLe1 = Filter.createLessOrEqualFilter("uid", "test").multiValued();
    ConvertedExpression expressionLe1 = simpleConverter.convertToSqlFilter(filterLe1, null, null);
    String queryLe1 = toSelectSQL(expressionLe1);
    assertEquals(queryLe1, "select doc.`*` from `table` as doc where doc.uid->'$.v[0]' <= '[\"test\"]'");
    // LE -- Integer
    Filter filterLe2 = Filter.createLessOrEqualFilter("age", 23).multiValued();
    ConvertedExpression expressionLe2 = simpleConverter.convertToSqlFilter(filterLe2, null, null);
    String queryLe2 = toSelectSQL(expressionLe2);
    assertEquals(queryLe2, "select doc.`*` from `table` as doc where doc.age->'$.v[0]' <= '[23]'");
    // LE -- Long
    Filter filterLe3 = Filter.createLessOrEqualFilter("age", 23L).multiValued();
    ConvertedExpression expressionLe3 = simpleConverter.convertToSqlFilter(filterLe3, null, null);
    String queryLe3 = toSelectSQL(expressionLe3);
    assertEquals(queryLe3, "select doc.`*` from `table` as doc where doc.age->'$.v[0]' <= '[23]'");
    // LE -- Date
    Filter filterLe4 = Filter.createLessOrEqualFilter("added", getUtcDateFromMillis(1608130698398L)).multiValued();
    ConvertedExpression expressionLe4 = simpleConverter.convertToSqlFilter(filterLe4, null, null);
    String queryLe4 = toSelectSQL(expressionLe4);
    assertEquals(queryLe4, "select doc.`*` from `table` as doc where doc.added->'$.v[0]' <= '[\"2020-12-16T14:58:18.398\"]'");
    // LE -- Date
    Filter filterLe5 = Filter.createLessOrEqualFilter("added", getUtcDateFromMillis(1608130698398L)).multiValued(3);
    ConvertedExpression expressionLe5 = simpleConverter.convertToSqlFilter(filterLe5, null, null);
    String queryLe5 = toSelectSQL(expressionLe5);
    assertEquals(queryLe5, "select doc.`*` from `table` as doc where doc.added->'$.v[0]' <= '[\"2020-12-16T14:58:18.398\"]' or doc.added->'$.v[1]' <= '[\"2020-12-16T14:58:18.398\"]' or doc.added->'$.v[2]' <= '[\"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 59 with Filter

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

the class SqlFilterConverterTest method checkOrFilters.

@Test
public void checkOrFilters() throws SearchException {
    Filter filterEq1 = Filter.createEqualityFilter("uid", "test");
    Filter filterPresence1 = Filter.createPresenceFilter("mail");
    Filter filterLe1 = Filter.createLessOrEqualFilter("age", 23);
    Filter filterOr1 = Filter.createORFilter(filterPresence1, filterEq1, filterLe1);
    ConvertedExpression expressionAnd1 = simpleConverter.convertToSqlFilter(filterOr1, null, null);
    String queryAnd1 = toSelectSQL(expressionAnd1);
    assertEquals(queryAnd1, "select doc.`*` from `table` as doc where doc.mail is not null or doc.uid = 'test' or doc.age <= 23");
}
Also used : Filter(io.jans.orm.search.filter.Filter) ConvertedExpression(io.jans.orm.sql.model.ConvertedExpression) Test(org.testng.annotations.Test)

Example 60 with Filter

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

the class SqlFilterConverterTest method checkOrWithLowerCaseFilter.

@Test
public void checkOrWithLowerCaseFilter() throws SearchException {
    boolean useLowercaseFilter = true;
    String[] targetArray = new String[] { "test_value" };
    Filter descriptionFilter, displayNameFilter;
    if (useLowercaseFilter) {
        descriptionFilter = Filter.createSubstringFilter(Filter.createLowercaseFilter("description"), null, targetArray, null);
        displayNameFilter = Filter.createSubstringFilter(Filter.createLowercaseFilter("displayName"), null, targetArray, null);
    } else {
        descriptionFilter = Filter.createSubstringFilter("description", null, targetArray, null);
        displayNameFilter = Filter.createSubstringFilter("displayName", null, targetArray, null);
    }
    Filter searchFilter = Filter.createORFilter(descriptionFilter, displayNameFilter);
    Filter typeFilter = Filter.createEqualityFilter("jansScrTyp", "person_authentication");
    Filter filter = Filter.createANDFilter(searchFilter, typeFilter);
    ConvertedExpression expression = simpleConverter.convertToSqlFilter(filter, null, null);
    String query = toSelectSQL(expression);
    assertEquals(query, "select doc.`*` from `table` as doc where (lower(doc.description) like '%test_value%' or lower(doc.displayName) like '%test_value%') and doc.jansScrTyp = 'person_authentication'");
}
Also used : Filter(io.jans.orm.search.filter.Filter) ConvertedExpression(io.jans.orm.sql.model.ConvertedExpression) Test(org.testng.annotations.Test)

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