Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.springframework.data.ldap.repository.support;

import java.util.Collection;

import org.springframework.ldap.filter.AndFilter;
import org.springframework.ldap.filter.EqualsFilter;
import org.springframework.ldap.filter.Filter;
Expand All @@ -33,6 +35,7 @@
*
* @author Mattias Hellborg Arthursson
* @author Eddu Melendez
* @author Ashish Vaghela
*/
class LdapSerializer implements Visitor<Object, Void> {

Expand Down Expand Up @@ -94,11 +97,35 @@ public Object visit(Operation<?> expr, Void context) {
return new GreaterThanOrEqualsFilter(attribute(expr), value(expr));
} else if (operator == Ops.LOE) {
return new LessThanOrEqualsFilter(attribute(expr), value(expr));
} else if (operator == Ops.IN) {
return inFilter(expr);
}

throw new UnsupportedOperationException("Unsupported operator " + operator.toString());
}

private Filter inFilter(Operation<?> expr) {

if (expr.getArg(1) instanceof Path) {
String attribute = odm.attributeFor(entityType, (String) expr.getArg(1).accept(this, null));
return new EqualsFilter(attribute, (String) expr.getArg(0).accept(this, null));
}

if (expr.getArg(1) instanceof Constant<?> constant && constant.getConstant() instanceof Collection<?> values) {

String attribute = attribute(expr);
OrFilter filter = new OrFilter();

for (Object value : values) {
filter.or(new EqualsFilter(attribute, value.toString()));
}

return filter;
}

throw new UnsupportedOperationException("Unsupported operand for IN operator: " + expr.getArg(1));
}

private String value(Operation<?> expr) {
return (String) expr.getArg(1).accept(this, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
/**
* @author Mattias Hellborg Arthursson
* @author Eddu Melendez
* @author Ashish Vaghela
*/
class QuerydslFilterGeneratorTests {

Expand Down Expand Up @@ -134,4 +135,31 @@ void testNull() {

assertThat(result).hasToString("(!(cn=*))");
}

@Test // GH-82
void testCollectionContains() {

Expression<?> expression = person.description.contains("test");
Filter result = tested.handle(expression);

assertThat(result).hasToString("(description=test)");
}

@Test // GH-82
void testIn() {

Expression<?> expression = person.fullName.in("John Doe", "Jane Doe");
Filter result = tested.handle(expression);

assertThat(result).hasToString("(|(cn=John Doe)(cn=Jane Doe))");
}

@Test // GH-82
void testInWithSingleValue() {

Expression<?> expression = person.fullName.in("John Doe");
Filter result = tested.handle(expression);

assertThat(result).hasToString("(cn=John Doe)");
}
}
Loading