use of io.jans.orm.sql.model.ConvertedExpression 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.sql.model.ConvertedExpression 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.sql.model.ConvertedExpression 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);
}
}
use of io.jans.orm.sql.model.ConvertedExpression in project jans by JanssenProject.
the class SqlFilterConverter method convertToSqlFilter.
@SuppressWarnings({ "unchecked", "rawtypes" })
public ConvertedExpression convertToSqlFilter(Filter genericFilter, Map<String, PropertyAnnotation> propertiesAnnotationsMap, Function<? super Filter, Boolean> processor, boolean skipAlias) throws SearchException {
Map<String, Class<?>> jsonAttributes = new HashMap<>();
ConvertedExpression convertedExpression = convertToSqlFilterImpl(genericFilter, propertiesAnnotationsMap, jsonAttributes, processor, skipAlias);
return convertedExpression;
}
use of io.jans.orm.sql.model.ConvertedExpression in project jans by JanssenProject.
the class SqlFilterConverterTest method checkNotFilters.
@Test
public void checkNotFilters() throws SearchException {
Filter notFilter1 = Filter.createNOTFilter(Filter.createLessOrEqualFilter("age", 23));
ConvertedExpression expressionNot1 = simpleConverter.convertToSqlFilter(notFilter1, null, null);
String queryUserUid1 = toSelectSQL(expressionNot1);
assertEquals(queryUserUid1, "select doc.`*` from `table` as doc where not doc.age <= 23");
Filter notFilter2 = Filter.createNOTFilter(Filter.createANDFilter(Filter.createLessOrEqualFilter("age", 23), Filter.createGreaterOrEqualFilter("age", 25)));
ConvertedExpression expressionNot2 = simpleConverter.convertToSqlFilter(notFilter2, null, null);
String queryUserUid2 = toSelectSQL(expressionNot2);
assertEquals(queryUserUid2, "select doc.`*` from `table` as doc where not (doc.age <= 23 and doc.age >= 25)");
}
Aggregations