Skip to content

Commit

Permalink
feat: update search by example to use multivalued property (#2298)
Browse files Browse the repository at this point in the history
* feat: handle multivalued in search by example in CB ORM #2297

* feat: handle multivalued in search by example in CB ORM #2297
  • Loading branch information
yurem authored Sep 2, 2022
1 parent f770878 commit 8ed3007
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import io.jans.orm.reflect.property.Setter;
import io.jans.orm.reflect.util.ReflectHelper;
import io.jans.orm.search.filter.Filter;
import io.jans.orm.search.filter.FilterProcessor;
import io.jans.orm.util.ArrayHelper;
import io.jans.orm.util.StringHelper;

Expand Down Expand Up @@ -108,6 +109,8 @@ public abstract class BaseEntryManager<O extends PersistenceOperationService> im
protected O operationService = null;
protected PersistenceExtension persistenceExtension = null;

protected FilterProcessor filterProcessor = new FilterProcessor();

@Override
public void persist(Object entry) {
if (entry == null) {
Expand Down Expand Up @@ -2234,6 +2237,10 @@ protected <T> Filter createFilterByEntry(Object entry, Class<T> entryClass, List
return addObjectClassFilter(attributesFilter, objectClasses);
}

protected Filter excludeObjectClassFilters(Filter genericFilter) {
return filterProcessor.excludeFilter(genericFilter, FilterProcessor.OBJECT_CLASS_EQUALITY_FILTER, FilterProcessor.OBJECT_CLASS_PRESENCE_FILTER);
}

protected Filter[] createAttributesFilter(List<AttributeData> attributes) {
if ((attributes == null) || (attributes.size() == 0)) {
return null;
Expand All @@ -2245,8 +2252,8 @@ protected Filter[] createAttributesFilter(List<AttributeData> attributes) {
String attributeName = attribute.getName();
for (Object value : attribute.getValues()) {
Filter filter = Filter.createEqualityFilter(attributeName, value);
if ((attribute.getMultiValued() != null) && attribute.getMultiValued()) {
filter.multiValued();
if (attribute.getMultiValued() != null) {
filter.multiValued(attribute.getMultiValued());
}

results.add(filter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,9 @@ protected Filter addObjectClassFilter(Filter filter, String[] objectClasses) {
return filter;
}

// Make sure that there is only one objectClass in filter
filter = excludeObjectClassFilters(filter);

// In Couchbase implementation we need to use first one as entry type
Filter searchFilter = Filter.createEqualityFilter(OBJECT_CLASS, objectClasses[0]);
if (filter != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public class SqlEntryManager extends BaseEntryManager<SqlOperationService> imple
private Logger log;

private final SqlFilterConverter filterConverter;
private FilterProcessor filterProcessor;

private static final GenericKeyConverter KEY_CONVERTER = new GenericKeyConverter(false);

Expand All @@ -84,7 +83,6 @@ public class SqlEntryManager extends BaseEntryManager<SqlOperationService> imple
protected SqlEntryManager(SqlOperationService operationService) {
this.operationService = operationService;
this.filterConverter = new SqlFilterConverter(operationService);
this.filterProcessor = new FilterProcessor();
subscribers = new LinkedList<DeleteNotifier>();
}

Expand Down Expand Up @@ -800,10 +798,6 @@ private ConvertedExpression toSqlFilterWithEmptyAlias(Filter genericFilter, Map<
return filterConverter.convertToSqlFilter(excludeObjectClassFilters(genericFilter), propertiesAnnotationsMap, processor, true);
}

private Filter excludeObjectClassFilters(Filter genericFilter) {
return filterProcessor.excludeFilter(genericFilter, FilterProcessor.OBJECT_CLASS_EQUALITY_FILTER, FilterProcessor.OBJECT_CLASS_PRESENCE_FILTER);
}

private ParsedKey toSQLKey(String dn) {
return KEY_CONVERTER.convertToKey(dn);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,29 +172,33 @@ public void setUserPassword(String value) {
setCustomAttribute("userPassword", value);
}

public void setAttribute(String attributeName, String[] attributeValue) {
setCustomAttribute(attributeName, Arrays.asList(attributeValue));
public CustomObjectAttribute setAttribute(String attributeName, String[] attributeValue) {
return setCustomAttribute(attributeName, Arrays.asList(attributeValue));
}

public void setAttribute(String attributeName, String attributeValue) {
public CustomObjectAttribute setAttribute(String attributeName, String attributeValue) {
if (attributeValue == null || attributeValue.length() == 0) {
setCustomAttribute(attributeName, Collections.emptyList());
return setCustomAttribute(attributeName, Collections.emptyList());
} else {
setCustomAttribute(attributeName, attributeValue);
return setCustomAttribute(attributeName, attributeValue);
}
}

public void setCustomAttribute(String attributeName, Object attributeValue) {
public CustomObjectAttribute setCustomAttribute(String attributeName, Object attributeValue) {
CustomObjectAttribute attribute = new CustomObjectAttribute(attributeName, attributeValue);
typedCustomAttributes.remove(attribute);
typedCustomAttributes.add(attribute);

return attribute;
}

public void setCustomAttribute(String attributeName, List<Object> attributeValue) {
public CustomObjectAttribute setCustomAttribute(String attributeName, List<Object> attributeValue) {
CustomObjectAttribute attribute = new CustomObjectAttribute(attributeName, attributeValue);
attribute.setMultiValued(true);
typedCustomAttributes.remove(attribute);
typedCustomAttributes.add(attribute);

return attribute;
}

}

0 comments on commit 8ed3007

Please sign in to comment.