Skip to content

Commit

Permalink
feat: allow to use like with lower together (#2944)
Browse files Browse the repository at this point in the history
Co-authored-by: Yuriy Movchan <Yuriy.Movchan@gmail.com>
  • Loading branch information
2 people authored and pujavs committed Nov 10, 2022
1 parent 90c549b commit a26ef90
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 8 deletions.
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

0 comments on commit a26ef90

Please sign in to comment.