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