Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow to use like with lower together #2944

Merged
merged 1 commit into from
Nov 9, 2022
Merged
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 @@ -49,6 +49,22 @@ public static void main(String[] args) {
newUser.getCustomAttributes().add(new CustomObjectAttribute("test", "test_value"));
couchbaseEntryManager.persist(newUser);

// Find all with lower and or filters
Filter orFilterWithLower = Filter.createORFilter(Filter.createEqualityFilter(Filter.createLowercaseFilter("description"), "test1"),
Filter.createEqualityFilter(Filter.createLowercaseFilter("description"), "test2"));
List<SimpleUser> usersWithOrFilter = couchbaseEntryManager.findEntries("ou=sessions,o=gluu", SimpleUser.class, orFilterWithLower);
for (SimpleUser user : usersWithOrFilter) {
LOG.info("User with uid: '{}' with DN: '{}'", user.getUserId(), user.getDn());
}

// Find all with lower and or filters
Filter orFilterWithLower2 = Filter.createORFilter(Filter.createSubstringFilter(Filter.createLowercaseFilter("description"), null, new String[] { "test1" }, null),
Filter.createSubstringFilter(Filter.createLowercaseFilter("displayName"), null, new String[] { "test1" }, null));
List<SimpleUser> usersWithOrFilter2 = couchbaseEntryManager.findEntries("ou=sessions,o=gluu", SimpleUser.class, orFilterWithLower2);
for (SimpleUser user : usersWithOrFilter2) {
LOG.info("User with uid: '{}' with DN: '{}'", user.getUserId(), user.getDn());
}

// Find all users which have specified object classes defined in SimpleUser
List<SimpleUser> users = couchbaseEntryManager.findEntries("ou=people,o=jans", SimpleUser.class, null);
for (SimpleUser user : users) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public ConvertedExpression convertToCouchbaseFilter(Filter genericFilter, Map<St
canJoinOrFilters = false;
continue;
}

if (tmpFilter.getMultiValued() != null) {
canJoinOrFilters = false;
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.List;

import io.jans.orm.util.ArrayHelper;
import io.jans.orm.util.StringHelper;

/**
* Simple filter without dependency to specific persistence filter mechanism
Expand Down Expand Up @@ -205,6 +206,10 @@ public final void setSubFinal(String subFinal) {
this.subFinal = subFinal;
}

protected void setMultiValued(Boolean multiValued) {
this.multiValued = multiValued;
}

public final Boolean getMultiValued() {
return multiValued;
}
Expand Down Expand Up @@ -271,22 +276,22 @@ public String toString() {
return sb.append(this.filters[0].toString()).append(this.type.getSign()).append(this.assertionValue).append(')')
.toString();
} else {
return sb.append(this.attributeName).append(this.type.getSign()).append(this.assertionValue).append(')')
return sb.append(toStringAttributeName()).append(this.type.getSign()).append(this.assertionValue).append(')')
.toString();
}
}

if (FilterType.PRESENCE == this.type) {
return sb.append(this.attributeName).append("=").append(this.type.getSign()).append(')').toString();
return sb.append(toStringAttributeName()).append("=").append(this.type.getSign()).append(')').toString();
}

if (FilterType.APPROXIMATE_MATCH == this.type) {
return sb.append(this.attributeName).append(this.type.getSign()).append("=").append(this.assertionValue)
return sb.append(toStringAttributeName()).append(this.type.getSign()).append("=").append(this.assertionValue)
.append(')').toString();
}

if (FilterType.SUBSTRING == this.type) {
sb.append(this.attributeName).append(this.type.getSign());
sb.append(toStringAttributeName()).append(this.type.getSign());
if (this.subInitial != null) {
sb.append(this.subInitial);
sb.append('*');
Expand Down Expand Up @@ -314,4 +319,16 @@ public String toString() {
return super.toString();
}

private String toStringAttributeName() {
if (StringHelper.isNotEmpty(this.attributeName)) {
return this.attributeName;
}

if (ArrayHelper.isNotEmpty(this.filters)) {
return this.filters[0].toString();
}

return "";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public Filter excludeFilter(Filter genericFilter, Filter... excludeFilters) {
return null;
}

Filter resultFilter = new Filter(type, resultFilters.toArray(new Filter[0]));
resultFilter.setAssertionValue(genericFilter.getAssertionValue());

Filter resultFilter = genericFilter.clone();
resultFilter.setFilters(resultFilters.toArray(new Filter[0]));
return resultFilter;
}

Expand Down