Search in sources :

Example 6 with ConvertedExpression

use of io.jans.orm.sql.model.ConvertedExpression 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 7 with ConvertedExpression

use of io.jans.orm.sql.model.ConvertedExpression 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 8 with ConvertedExpression

use of io.jans.orm.sql.model.ConvertedExpression 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)

Example 9 with ConvertedExpression

use of io.jans.orm.sql.model.ConvertedExpression 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 10 with ConvertedExpression

use of io.jans.orm.sql.model.ConvertedExpression 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)

Aggregations

ConvertedExpression (io.jans.orm.sql.model.ConvertedExpression)25 Filter (io.jans.orm.search.filter.Filter)24 Test (org.testng.annotations.Test)19 SearchException (io.jans.orm.exception.operation.SearchException)5 AuthenticationException (io.jans.orm.exception.AuthenticationException)4 EntryDeleteException (io.jans.orm.exception.EntryDeleteException)4 EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)4 MappingException (io.jans.orm.exception.MappingException)4 PropertyAnnotation (io.jans.orm.reflect.property.PropertyAnnotation)4 DateTimeParseException (java.time.format.DateTimeParseException)4 ParsedKey (io.jans.orm.impl.model.ParsedKey)3 EntryData (io.jans.orm.model.EntryData)3 Expression (com.querydsl.core.types.Expression)1 OrderSpecifier (com.querydsl.core.types.OrderSpecifier)1 Predicate (com.querydsl.core.types.Predicate)1 AttributeEnum (io.jans.orm.annotation.AttributeEnum)1 FilterType (io.jans.orm.search.filter.FilterType)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1