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))");
}
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'");
}
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\"]'");
}
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");
}
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'");
}
Aggregations