diff -r 9528693cc885 nuxeo-platform-usermanager-api/src/main/java/org/nuxeo/ecm/platform/usermanager/UserManagerDescriptor.java --- a/nuxeo-platform-usermanager-api/src/main/java/org/nuxeo/ecm/platform/usermanager/UserManagerDescriptor.java Tue Mar 08 17:02:21 2011 +0100 +++ b/nuxeo-platform-usermanager-api/src/main/java/org/nuxeo/ecm/platform/usermanager/UserManagerDescriptor.java Wed Mar 16 20:31:25 2011 +0100 @@ -118,6 +118,44 @@ public void setUserSearchFields(String[] fields) { setSubstringMatchUserSearchFields(fields); } + + public boolean groupSearchFieldsPresent = false; + + @XNode("groups/searchFields") + public void setGroupSearchFieldsPresent(@SuppressWarnings("unused") + String text) { + groupSearchFieldsPresent = true; + } + + @XNode("groups/searchFields@append") + public boolean groupSearchFieldsAppend; + + public Map groupSearchFields = new LinkedHashMap(); + + @XNodeList(value = "groups/searchFields/exactMatchSearchField", componentType = String.class, type = String[].class) + public void setExactMatchGroupSearchFields(String[] fields) { + for (String field : fields) { + groupSearchFields.put(field, MatchType.EXACT); + } + } + + @XNodeList(value = "groups/searchFields/substringMatchSearchField", + componentType = String.class, type = String[].class) + public void setSubstringMatchGroupSearchFields(String[] fields) { + for (String field : fields) { + groupSearchFields.put(field, MatchType.SUBSTRING); + } + } + + /** + * @deprecated use setSubstringMatchGroupSearchFields instead + */ + @Deprecated + @XNodeList(value = "groups/searchFields/searchField", + componentType = String.class, type = String[].class) + public void setGroupSearchFields(String[] fields) { + setSubstringMatchGroupSearchFields(fields); + } public Pattern userPasswordPattern; diff -r 9528693cc885 nuxeo-platform-usermanager-core/src/main/java/org/nuxeo/ecm/platform/usermanager/FakeUserManagerImpl.java --- a/nuxeo-platform-usermanager-core/src/main/java/org/nuxeo/ecm/platform/usermanager/FakeUserManagerImpl.java Tue Mar 08 17:02:21 2011 +0100 +++ b/nuxeo-platform-usermanager-core/src/main/java/org/nuxeo/ecm/platform/usermanager/FakeUserManagerImpl.java Wed Mar 16 20:31:25 2011 +0100 @@ -66,6 +66,8 @@ String userEmailField; Map userSearchFields; + + Map groupSearchFields; Pattern userPasswordPattern; @@ -151,6 +153,21 @@ public Set getUserSearchFields() { return userSearchFields.keySet(); } + + public void setGroupSearchFields(Set groupSearchFields) { + this.groupSearchFields = new LinkedHashMap(); + for (String searchField : groupSearchFields) { + this.groupSearchFields.put(searchField, MatchType.SUBSTRING); + } + } + + public void setGroupSearchFields(Map groupSearchFields) { + this.groupSearchFields = groupSearchFields; + } + + public Set getGroupSearchFields() { + return groupSearchFields.keySet(); + } public void setGroupDirectoryName(String groupDirectoryName) { this.groupDirectoryName = groupDirectoryName; @@ -288,6 +305,7 @@ setUserDirectoryName(descriptor.userDirectoryName); setUserEmailField(descriptor.userEmailField); setUserSearchFields(descriptor.userSearchFields); + setGroupSearchFields(descriptor.groupSearchFields); setUserPasswordPattern(descriptor.userPasswordPattern); setGroupDirectoryName(descriptor.groupDirectoryName); setGroupMembersField(descriptor.groupMembersField); diff -r 9528693cc885 nuxeo-platform-usermanager-core/src/main/java/org/nuxeo/ecm/platform/usermanager/UserManagerImpl.java --- a/nuxeo-platform-usermanager-core/src/main/java/org/nuxeo/ecm/platform/usermanager/UserManagerImpl.java Tue Mar 08 17:02:21 2011 +0100 +++ b/nuxeo-platform-usermanager-core/src/main/java/org/nuxeo/ecm/platform/usermanager/UserManagerImpl.java Wed Mar 16 20:31:25 2011 +0100 @@ -55,6 +55,7 @@ import org.nuxeo.ecm.directory.DirectoryException; import org.nuxeo.ecm.directory.Session; import org.nuxeo.ecm.directory.api.DirectoryService; +import org.nuxeo.ecm.platform.usermanager.UserManager.MatchType; import org.nuxeo.ecm.platform.usermanager.exceptions.GroupAlreadyExistsException; import org.nuxeo.ecm.platform.usermanager.exceptions.UserAlreadyExistsException; import org.nuxeo.runtime.api.Framework; @@ -113,6 +114,8 @@ protected String userEmailField; protected Map userSearchFields; + + protected Map groupSearchFields; protected String groupDirectoryName; @@ -182,6 +185,7 @@ groupListingMode = descriptor.groupListingMode; userEmailField = descriptor.userEmailField; userSearchFields = descriptor.userSearchFields; + groupSearchFields = descriptor.groupSearchFields; userPasswordPattern = descriptor.userPasswordPattern; groupMembersField = descriptor.groupMembersField; groupSubGroupsField = descriptor.groupSubGroupsField; @@ -231,6 +235,10 @@ public Set getUserSearchFields() { return Collections.unmodifiableSet(userSearchFields.keySet()); } + + public Set getGroupSearchFields() { + return Collections.unmodifiableSet(groupSearchFields.keySet()); + } protected void setGroupDirectoryName(String groupDirectoryName) { this.groupDirectoryName = groupDirectoryName; @@ -708,6 +716,7 @@ } public List searchGroups(String pattern) throws ClientException { + /* Session groupDir = null; try { groupDir = dirService.open(groupDirectoryName); @@ -730,6 +739,39 @@ groupDir.close(); } } + */ + + DocumentModelList entries = new DocumentModelListImpl(); + if (pattern == null || pattern.length() == 0) { + entries = searchGroups( + Collections. emptyMap(), null); + } else { + Map uniqueEntries = new HashMap(); + + for (Entry fieldEntry : groupSearchFields.entrySet()) { + Map filter = new HashMap(); + filter.put(fieldEntry.getKey(), pattern); + DocumentModelList fetchedEntries; + if (fieldEntry.getValue() == MatchType.SUBSTRING) { + fetchedEntries = searchUsers(filter, filter.keySet(), null); + } else { + fetchedEntries = searchGroups(filter, null); + } + for (DocumentModel entry : fetchedEntries) { + uniqueEntries.put(entry.getId(), entry); + } + } + log.debug(String.format("found %d unique entries", + uniqueEntries.size())); + entries.addAll(uniqueEntries.values()); + } + + List groups = new ArrayList( + entries.size()); + for (DocumentModel groupEntry : entries) { + groups.add(makeGroup(groupEntry)); + } + return groups; } public String getUserSortField() { diff -r 9528693cc885 nuxeo-platform-usermanager-core/src/test/resources/test-userservice-config.xml --- a/nuxeo-platform-usermanager-core/src/test/resources/test-userservice-config.xml Tue Mar 08 17:02:21 2011 +0100 +++ b/nuxeo-platform-usermanager-core/src/test/resources/test-userservice-config.xml Wed Mar 16 20:31:25 2011 +0100 @@ -38,6 +38,12 @@ members subg parentg + + + groupname + groupname + groupname + search_oh_yeah tehroot