use of io.jans.orm.couchbase.model.ConvertedExpression in project jans by JanssenProject.
the class CouchbaseFilterConverterTest method checkOrJoinFilters.
@Test
public void checkOrJoinFilters() throws SearchException {
// And with join
Filter filterEq1 = Filter.createEqualityFilter("uid", "test");
Filter filterEq2 = Filter.createEqualityFilter("uid", "test2");
Filter filterEq3 = Filter.createEqualityFilter("uid", "test3");
Filter filterOr1 = Filter.createORFilter(filterEq1, filterEq2, filterEq3).multiValued(false);
ConvertedExpression expressionOr1 = simpleConverter.convertToCouchbaseFilter(filterOr1, null, null);
String queryOr1 = toSelectSQL(expressionOr1);
assertEquals(queryOr1, "SELECT jans_doc.* FROM `jans` AS jans_doc WHERE ( uid IN [\"test\",\"test2\",\"test3\"] )");
Filter filterOr2 = Filter.createORFilter(filterEq1, filterEq2, filterEq3);
ConvertedExpression expressionOr2 = simpleConverter.convertToCouchbaseFilter(filterOr2, null, null);
String queryOr2 = toSelectSQL(expressionOr2);
assertEquals(queryOr2, "SELECT jans_doc.* FROM `jans` AS jans_doc WHERE ( ( ( uid = \"test\" ) OR ( \"test\" IN uid ) ) OR ( ( uid = \"test2\" ) OR ( \"test2\" IN uid ) ) OR ( ( uid = \"test3\" ) OR ( \"test3\" IN uid ) ) )");
}
use of io.jans.orm.couchbase.model.ConvertedExpression in project jans by JanssenProject.
the class CouchbaseFilterConverterTest method checkSinglevaluedEqFilters.
@Test
public void checkSinglevaluedEqFilters() throws SearchException {
// EQ -- String
Filter filterEq1 = Filter.createEqualityFilter("uid", "test").multiValued(false);
ConvertedExpression expressionEq1 = simpleConverter.convertToCouchbaseFilter(filterEq1, null, null);
String queryEq1 = toSelectSQL(expressionEq1);
assertEquals(queryEq1, "SELECT jans_doc.* FROM `jans` AS jans_doc WHERE uid = \"test\"");
// EQ -- Integer
Filter filterEq2 = Filter.createEqualityFilter("age", 23).multiValued(false);
ConvertedExpression expressionEq2 = simpleConverter.convertToCouchbaseFilter(filterEq2, null, null);
String queryEq2 = toSelectSQL(expressionEq2);
assertEquals(queryEq2, "SELECT jans_doc.* FROM `jans` AS jans_doc WHERE age = 23");
// EQ -- Long
Filter filterEq3 = Filter.createEqualityFilter("age", 23L).multiValued(false);
ConvertedExpression expressionEq3 = simpleConverter.convertToCouchbaseFilter(filterEq3, null, null);
String queryEq3 = toSelectSQL(expressionEq3);
assertEquals(queryEq3, "SELECT jans_doc.* FROM `jans` AS jans_doc WHERE age = 23");
// EQ -- Date
Filter filterEq4 = Filter.createEqualityFilter("added", getUtcDateFromMillis(1608130698398L)).multiValued(false);
ConvertedExpression expressionEq4 = simpleConverter.convertToCouchbaseFilter(filterEq4, null, null);
String queryEq4 = toSelectSQL(expressionEq4);
assertEquals(queryEq4, "SELECT jans_doc.* FROM `jans` AS jans_doc WHERE added = \"Wed Dec 16 14:58:18 UTC 2020\"");
}
use of io.jans.orm.couchbase.model.ConvertedExpression in project jans by JanssenProject.
the class CouchbaseFilterConverterTest method checkMultivaluedEqFilters.
@Test
public void checkMultivaluedEqFilters() throws SearchException {
// EQ -- String
Filter filterEq1 = Filter.createEqualityFilter("uid", "test").multiValued();
ConvertedExpression expressionEq1 = simpleConverter.convertToCouchbaseFilter(filterEq1, null, null);
String queryEq1 = toSelectSQL(expressionEq1);
assertEquals(queryEq1, "SELECT jans_doc.* FROM `jans` AS jans_doc WHERE ANY uid_ IN uid SATISFIES uid_ = \"test\" END");
// EQ -- Integer
Filter filterEq2 = Filter.createEqualityFilter("age", 23).multiValued();
ConvertedExpression expressionEq2 = simpleConverter.convertToCouchbaseFilter(filterEq2, null, null);
String queryEq2 = toSelectSQL(expressionEq2);
assertEquals(queryEq2, "SELECT jans_doc.* FROM `jans` AS jans_doc WHERE ANY age_ IN age SATISFIES age_ = 23 END");
// EQ -- Long
Filter filterEq3 = Filter.createEqualityFilter("age", 23L).multiValued();
ConvertedExpression expressionEq3 = simpleConverter.convertToCouchbaseFilter(filterEq3, null, null);
String queryEq3 = toSelectSQL(expressionEq3);
assertEquals(queryEq3, "SELECT jans_doc.* FROM `jans` AS jans_doc WHERE ANY age_ IN age SATISFIES age_ = 23 END");
// EQ -- Date
Filter filterEq4 = Filter.createEqualityFilter("added", getUtcDateFromMillis(1608130698398L)).multiValued();
ConvertedExpression expressionEq4 = simpleConverter.convertToCouchbaseFilter(filterEq4, null, null);
String queryEq4 = toSelectSQL(expressionEq4);
assertEquals(queryEq4, "SELECT jans_doc.* FROM `jans` AS jans_doc WHERE ANY added_ IN added SATISFIES added_ = \"Wed Dec 16 14:58:18 UTC 2020\" END");
}
use of io.jans.orm.couchbase.model.ConvertedExpression in project jans by JanssenProject.
the class CouchbaseFilterConverterCheckExcludeFilterTest method checkObjectClassExcludeFilter.
@Test
public void checkObjectClassExcludeFilter() throws SearchException {
Filter filterEq1 = Filter.createEqualityFilter("uid", "test");
Filter filterEq2 = Filter.createEqualityFilter(Filter.createLowercaseFilter("uid"), "test");
Filter filterEq3 = Filter.createEqualityFilter("objectClass", "jansPerson");
Filter filterEq4 = Filter.createEqualityFilter("added", getUtcDateFromMillis(1608130698398L)).multiValued();
Filter andFilter = Filter.createANDFilter(filterEq1, filterEq2, filterEq3, filterEq4);
Filter orFilter = Filter.createANDFilter(filterEq1, filterEq2, filterEq3, andFilter, filterEq4);
Filter filter1 = Filter.createANDFilter(filterEq3, orFilter);
ConvertedExpression expression1 = simpleConverter.convertToCouchbaseFilter(filter1, null, null);
String query1 = toSelectSQL(expression1);
assertEquals(query1, "SELECT jans_doc.* FROM `jans` AS jans_doc WHERE ( ( ( objectClass = \"jansPerson\" ) OR ( \"jansPerson\" IN objectClass ) ) AND ( ( ( uid = \"test\" ) OR ( \"test\" IN uid ) ) AND LOWER(uid) = \"test\" AND ( ( objectClass = \"jansPerson\" ) OR ( \"jansPerson\" IN objectClass ) ) AND ( ( ( uid = \"test\" ) OR ( \"test\" IN uid ) ) AND LOWER(uid) = \"test\" AND ( ( objectClass = \"jansPerson\" ) OR ( \"jansPerson\" IN objectClass ) ) AND ANY added_ IN added SATISFIES added_ = \"Wed Dec 16 14:58:18 UTC 2020\" END ) AND ANY added_ IN added SATISFIES added_ = \"Wed Dec 16 14:58:18 UTC 2020\" END ) )");
Filter filter2 = filterProcessor.excludeFilter(filter1, filterEq3);
ConvertedExpression expression2 = simpleConverter.convertToCouchbaseFilter(filter2, null, null);
String query2 = toSelectSQL(expression2);
assertEquals(query2, "SELECT jans_doc.* FROM `jans` AS jans_doc WHERE ( ( ( ( uid = \"test\" ) OR ( \"test\" IN uid ) ) AND LOWER(uid) = \"test\" AND ( ( ( uid = \"test\" ) OR ( \"test\" IN uid ) ) AND LOWER(uid) = \"test\" AND ANY added_ IN added SATISFIES added_ = \"Wed Dec 16 14:58:18 UTC 2020\" END ) AND ANY added_ IN added SATISFIES added_ = \"Wed Dec 16 14:58:18 UTC 2020\" END ) )");
Filter filter3 = filterProcessor.excludeFilter(filter1, Filter.createEqualityFilter("objectClass", null));
ConvertedExpression expression3 = simpleConverter.convertToCouchbaseFilter(filter3, null, null);
String query3 = toSelectSQL(expression3);
assertEquals(query3, "SELECT jans_doc.* FROM `jans` AS jans_doc WHERE ( ( ( ( uid = \"test\" ) OR ( \"test\" IN uid ) ) AND LOWER(uid) = \"test\" AND ( ( ( uid = \"test\" ) OR ( \"test\" IN uid ) ) AND LOWER(uid) = \"test\" AND ANY added_ IN added SATISFIES added_ = \"Wed Dec 16 14:58:18 UTC 2020\" END ) AND ANY added_ IN added SATISFIES added_ = \"Wed Dec 16 14:58:18 UTC 2020\" END ) )");
}
use of io.jans.orm.couchbase.model.ConvertedExpression in project jans by JanssenProject.
the class CouchbaseEntryManager method findEntriesImpl.
protected <T> PagedResult<JsonObject> 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
Sort[] defaultSort = getDefaultSort(entryClass);
if (StringHelper.isNotEmpty(sortBy)) {
Sort requestedSort = buildSort(sortBy, sortOrder);
if (ArrayHelper.isEmpty(defaultSort)) {
defaultSort = new Sort[] { requestedSort };
} else {
defaultSort = ArrayHelper.arrayMerge(new Sort[] { requestedSort }, defaultSort);
}
}
// Prepare properties types to allow build filter properly
Map<String, PropertyAnnotation> propertiesAnnotationsMap = prepareEntryPropertiesTypes(entryClass, propertiesAnnotations);
ParsedKey keyWithInum = toCouchbaseKey(baseDN);
ConvertedExpression convertedExpression;
try {
convertedExpression = toCouchbaseFilter(searchFilter, propertiesAnnotationsMap);
} catch (SearchException ex) {
throw new EntryPersistenceException(String.format("Failed to convert filter %s to expression", searchFilter));
}
PagedResult<JsonObject> searchResult = null;
try {
CouchbaseBatchOperationWraper<T> batchOperationWraper = null;
if (batchOperation != null) {
batchOperationWraper = new CouchbaseBatchOperationWraper<T>(batchOperation, this, entryClass, propertiesAnnotations);
}
searchResult = searchImpl(keyWithInum.getKey(), getScanConsistency(convertedExpression), convertedExpression.expression(), 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 (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to find entries with key: %s, expression: %s", keyWithInum.getKey(), convertedExpression), ex);
}
}
Aggregations