From 8ed3007ec3406ac7c0adf81ce339f6672b76a147 Mon Sep 17 00:00:00 2001 From: Yuriy Movchan Date: Fri, 2 Sep 2022 23:40:57 +0300 Subject: [PATCH] feat: update search by example to use multivalued property (#2298) * feat: handle multivalued in search by example in CB ORM #2297 * feat: handle multivalued in search by example in CB ORM #2297 --- .../io/jans/orm/impl/BaseEntryManager.java | 11 +++++++++-- .../couchbase/impl/CouchbaseEntryManager.java | 3 +++ .../io/jans/orm/sql/impl/SqlEntryManager.java | 6 ------ .../jans/scim/model/scim/ScimCustomPerson.java | 18 +++++++++++------- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/jans-orm/core/src/main/java/io/jans/orm/impl/BaseEntryManager.java b/jans-orm/core/src/main/java/io/jans/orm/impl/BaseEntryManager.java index d56ce8c02b1..c9b12d73fc3 100644 --- a/jans-orm/core/src/main/java/io/jans/orm/impl/BaseEntryManager.java +++ b/jans-orm/core/src/main/java/io/jans/orm/impl/BaseEntryManager.java @@ -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; @@ -108,6 +109,8 @@ public abstract class BaseEntryManager im protected O operationService = null; protected PersistenceExtension persistenceExtension = null; + protected FilterProcessor filterProcessor = new FilterProcessor(); + @Override public void persist(Object entry) { if (entry == null) { @@ -2234,6 +2237,10 @@ protected Filter createFilterByEntry(Object entry, Class 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 attributes) { if ((attributes == null) || (attributes.size() == 0)) { return null; @@ -2245,8 +2252,8 @@ protected Filter[] createAttributesFilter(List 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); diff --git a/jans-orm/couchbase/src/main/java/io/jans/orm/couchbase/impl/CouchbaseEntryManager.java b/jans-orm/couchbase/src/main/java/io/jans/orm/couchbase/impl/CouchbaseEntryManager.java index 24550f48fe9..69c9d1a6581 100644 --- a/jans-orm/couchbase/src/main/java/io/jans/orm/couchbase/impl/CouchbaseEntryManager.java +++ b/jans-orm/couchbase/src/main/java/io/jans/orm/couchbase/impl/CouchbaseEntryManager.java @@ -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) { diff --git a/jans-orm/sql/src/main/java/io/jans/orm/sql/impl/SqlEntryManager.java b/jans-orm/sql/src/main/java/io/jans/orm/sql/impl/SqlEntryManager.java index 5a5879b5f01..6b17bca0f9f 100644 --- a/jans-orm/sql/src/main/java/io/jans/orm/sql/impl/SqlEntryManager.java +++ b/jans-orm/sql/src/main/java/io/jans/orm/sql/impl/SqlEntryManager.java @@ -75,7 +75,6 @@ public class SqlEntryManager extends BaseEntryManager imple private Logger log; private final SqlFilterConverter filterConverter; - private FilterProcessor filterProcessor; private static final GenericKeyConverter KEY_CONVERTER = new GenericKeyConverter(false); @@ -84,7 +83,6 @@ public class SqlEntryManager extends BaseEntryManager imple protected SqlEntryManager(SqlOperationService operationService) { this.operationService = operationService; this.filterConverter = new SqlFilterConverter(operationService); - this.filterProcessor = new FilterProcessor(); subscribers = new LinkedList(); } @@ -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); } diff --git a/jans-scim/model/src/main/java/io/jans/scim/model/scim/ScimCustomPerson.java b/jans-scim/model/src/main/java/io/jans/scim/model/scim/ScimCustomPerson.java index d07f3f61c27..bb6ebc47287 100644 --- a/jans-scim/model/src/main/java/io/jans/scim/model/scim/ScimCustomPerson.java +++ b/jans-scim/model/src/main/java/io/jans/scim/model/scim/ScimCustomPerson.java @@ -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 attributeValue) { + public CustomObjectAttribute setCustomAttribute(String attributeName, List attributeValue) { CustomObjectAttribute attribute = new CustomObjectAttribute(attributeName, attributeValue); attribute.setMultiValued(true); typedCustomAttributes.remove(attribute); typedCustomAttributes.add(attribute); + + return attribute; } }