@Test public void testMixedEntries() throws Exception { try (OperationContext ctx = new OperationContext(session)) { Map<String, String> params = new HashMap<>(); params.put("searchTerm", "adm"); Blob result = (Blob) automationService.run(ctx, SuggestUserEntries.ID, params); assertNotNull(result); JsonAssert json = JsonAssert.on(result.getString()).isArray().length(2); json.childrenContains("id", "Administrator", "administrators"); params.put("searchTerm", "Joh"); result = (Blob) automationService.run(ctx, SuggestUserEntries.ID, params); json = JsonAssert.on(result.getString()).isArray().length(1); json.childrenContains("id", "jdoe"); params.put("searchTerm", "mem"); result = (Blob) automationService.run(ctx, SuggestUserEntries.ID, params); json = JsonAssert.on(result.getString()).isArray().length(1); json.childrenContains("id", "members"); } }
@OperationMethod public Blob run() throws IOException { List<Map<String, Object>> result = new ArrayList<>(); boolean isGroupRestriction = !StringUtils.isBlank(groupRestriction); boolean groupOnly = false; boolean userOnly = isGroupRestriction; if (!isGroupRestriction && searchType != null && !searchType.isEmpty()) { if (searchType.equals(SuggestConstants.USER_TYPE)) { userOnly = true; } else if (searchType.equals(SuggestConstants.GROUP_TYPE)) { groupOnly = true; } } int limit = userSuggestionMaxSearchResults == null ? 0 : userSuggestionMaxSearchResults.intValue(); try { int userSize = 0; int groupSize = 0; if (!groupOnly) { if (limit > 0 && isGroupRestriction) { long currentLimit = limit; int prevUserListSize = -1; for (;;) { DocumentModelList userList = searchUsers(currentLimit); result = usersToMapWithGroupRestrictions(userList); int userListSize = userList.size(); if (userListSize == prevUserListSize || result.size() > limit) { break; } prevUserListSize = userListSize; currentLimit *= 2; if (currentLimit > Integer.MAX_VALUE) { break; } } } else { DocumentModelList userList = searchUsers(limit); result = usersToMapWithGroupRestrictions(userList); } userSize = result.size(); } if (!userOnly) { Schema schema = schemaManager.getSchema(userManager.getGroupSchemaName()); DocumentModelList groupList = userManager.searchGroups(prefix); List<String> admins = new ArrayList<>(); if (hideAdminGroups) { admins = userManager.getAdministratorsGroups(); } groupLoop: for (DocumentModel group : groupList) { if (hideAdminGroups) { for (String adminGroupName : admins) { if (adminGroupName.equals(group.getId())) { break groupLoop; } } } if (hidePowerUsersGroup && POWERUSERS.equals(group.getId())) { break groupLoop; } Map<String, Object> obj = new LinkedHashMap<>(); for (Field field : schema.getFields()) { QName fieldName = field.getName(); String key = fieldName.getLocalName(); Serializable value = group.getPropertyValue(fieldName.getPrefixedName()); obj.put(key, value); } String groupId = group.getId(); obj.put(SuggestConstants.ID, groupId); obj.put(MarshallingConstants.ENTITY_FIELD_NAME, NuxeoGroupJsonWriter.ENTITY_TYPE); SuggestConstants.computeGroupLabel(obj, groupId, userManager.getGroupLabelField(), hideFirstLabel); obj.put(SuggestConstants.TYPE_KEY_NAME, SuggestConstants.GROUP_TYPE); obj.put(SuggestConstants.PREFIXED_ID_KEY_NAME, NuxeoGroup.PREFIX + groupId); SuggestConstants.computeUserGroupIcon(obj, hideIcon); result.add(obj); } groupSize = result.size() - userSize; } if (limit > 0 && (userSize > limit || groupSize > limit || userSize + groupSize > limit)) { throw new SizeLimitExceededException(); } } catch (SizeLimitExceededException e) { return searchOverflowMessage(); } return Blobs.createJSONBlobFromValue(result); }
SuggestUserEntries { @OperationMethod public Blob run() throws IOException { List<Map<String, Object>> result = new ArrayList<>(); boolean isGroupRestriction = !StringUtils.isBlank(groupRestriction); boolean groupOnly = false; boolean userOnly = isGroupRestriction; if (!isGroupRestriction && searchType != null && !searchType.isEmpty()) { if (searchType.equals(SuggestConstants.USER_TYPE)) { userOnly = true; } else if (searchType.equals(SuggestConstants.GROUP_TYPE)) { groupOnly = true; } } int limit = userSuggestionMaxSearchResults == null ? 0 : userSuggestionMaxSearchResults.intValue(); try { int userSize = 0; int groupSize = 0; if (!groupOnly) { if (limit > 0 && isGroupRestriction) { long currentLimit = limit; int prevUserListSize = -1; for (;;) { DocumentModelList userList = searchUsers(currentLimit); result = usersToMapWithGroupRestrictions(userList); int userListSize = userList.size(); if (userListSize == prevUserListSize || result.size() > limit) { break; } prevUserListSize = userListSize; currentLimit *= 2; if (currentLimit > Integer.MAX_VALUE) { break; } } } else { DocumentModelList userList = searchUsers(limit); result = usersToMapWithGroupRestrictions(userList); } userSize = result.size(); } if (!userOnly) { Schema schema = schemaManager.getSchema(userManager.getGroupSchemaName()); DocumentModelList groupList = userManager.searchGroups(prefix); List<String> admins = new ArrayList<>(); if (hideAdminGroups) { admins = userManager.getAdministratorsGroups(); } groupLoop: for (DocumentModel group : groupList) { if (hideAdminGroups) { for (String adminGroupName : admins) { if (adminGroupName.equals(group.getId())) { break groupLoop; } } } if (hidePowerUsersGroup && POWERUSERS.equals(group.getId())) { break groupLoop; } Map<String, Object> obj = new LinkedHashMap<>(); for (Field field : schema.getFields()) { QName fieldName = field.getName(); String key = fieldName.getLocalName(); Serializable value = group.getPropertyValue(fieldName.getPrefixedName()); obj.put(key, value); } String groupId = group.getId(); obj.put(SuggestConstants.ID, groupId); obj.put(MarshallingConstants.ENTITY_FIELD_NAME, NuxeoGroupJsonWriter.ENTITY_TYPE); SuggestConstants.computeGroupLabel(obj, groupId, userManager.getGroupLabelField(), hideFirstLabel); obj.put(SuggestConstants.TYPE_KEY_NAME, SuggestConstants.GROUP_TYPE); obj.put(SuggestConstants.PREFIXED_ID_KEY_NAME, NuxeoGroup.PREFIX + groupId); SuggestConstants.computeUserGroupIcon(obj, hideIcon); result.add(obj); } groupSize = result.size() - userSize; } if (limit > 0 && (userSize > limit || groupSize > limit || userSize + groupSize > limit)) { throw new SizeLimitExceededException(); } } catch (SizeLimitExceededException e) { return searchOverflowMessage(); } return Blobs.createJSONBlobFromValue(result); } }
SuggestUserEntries { @OperationMethod public Blob run() throws IOException { List<Map<String, Object>> result = new ArrayList<>(); boolean isGroupRestriction = !StringUtils.isBlank(groupRestriction); boolean groupOnly = false; boolean userOnly = isGroupRestriction; if (!isGroupRestriction && searchType != null && !searchType.isEmpty()) { if (searchType.equals(SuggestConstants.USER_TYPE)) { userOnly = true; } else if (searchType.equals(SuggestConstants.GROUP_TYPE)) { groupOnly = true; } } int limit = userSuggestionMaxSearchResults == null ? 0 : userSuggestionMaxSearchResults.intValue(); try { int userSize = 0; int groupSize = 0; if (!groupOnly) { if (limit > 0 && isGroupRestriction) { long currentLimit = limit; int prevUserListSize = -1; for (;;) { DocumentModelList userList = searchUsers(currentLimit); result = usersToMapWithGroupRestrictions(userList); int userListSize = userList.size(); if (userListSize == prevUserListSize || result.size() > limit) { break; } prevUserListSize = userListSize; currentLimit *= 2; if (currentLimit > Integer.MAX_VALUE) { break; } } } else { DocumentModelList userList = searchUsers(limit); result = usersToMapWithGroupRestrictions(userList); } userSize = result.size(); } if (!userOnly) { Schema schema = schemaManager.getSchema(userManager.getGroupSchemaName()); DocumentModelList groupList = userManager.searchGroups(prefix); List<String> admins = new ArrayList<>(); if (hideAdminGroups) { admins = userManager.getAdministratorsGroups(); } groupLoop: for (DocumentModel group : groupList) { if (hideAdminGroups) { for (String adminGroupName : admins) { if (adminGroupName.equals(group.getId())) { break groupLoop; } } } if (hidePowerUsersGroup && POWERUSERS.equals(group.getId())) { break groupLoop; } Map<String, Object> obj = new LinkedHashMap<>(); for (Field field : schema.getFields()) { QName fieldName = field.getName(); String key = fieldName.getLocalName(); Serializable value = group.getPropertyValue(fieldName.getPrefixedName()); obj.put(key, value); } String groupId = group.getId(); obj.put(SuggestConstants.ID, groupId); obj.put(MarshallingConstants.ENTITY_FIELD_NAME, NuxeoGroupJsonWriter.ENTITY_TYPE); SuggestConstants.computeGroupLabel(obj, groupId, userManager.getGroupLabelField(), hideFirstLabel); obj.put(SuggestConstants.TYPE_KEY_NAME, SuggestConstants.GROUP_TYPE); obj.put(SuggestConstants.PREFIXED_ID_KEY_NAME, NuxeoGroup.PREFIX + groupId); SuggestConstants.computeUserGroupIcon(obj, hideIcon); result.add(obj); } groupSize = result.size() - userSize; } if (limit > 0 && (userSize > limit || groupSize > limit || userSize + groupSize > limit)) { throw new SizeLimitExceededException(); } } catch (SizeLimitExceededException e) { return searchOverflowMessage(); } return Blobs.createJSONBlobFromValue(result); }  }
SuggestUserEntries { @OperationMethod public Blob run() throws IOException { List<Map<String, Object>> result = new ArrayList<>(); boolean isGroupRestriction = !StringUtils.isBlank(groupRestriction); boolean groupOnly = false; boolean userOnly = isGroupRestriction; if (!isGroupRestriction && searchType != null && !searchType.isEmpty()) { if (searchType.equals(SuggestConstants.USER_TYPE)) { userOnly = true; } else if (searchType.equals(SuggestConstants.GROUP_TYPE)) { groupOnly = true; } } int limit = userSuggestionMaxSearchResults == null ? 0 : userSuggestionMaxSearchResults.intValue(); try { int userSize = 0; int groupSize = 0; if (!groupOnly) { if (limit > 0 && isGroupRestriction) { long currentLimit = limit; int prevUserListSize = -1; for (;;) { DocumentModelList userList = searchUsers(currentLimit); result = usersToMapWithGroupRestrictions(userList); int userListSize = userList.size(); if (userListSize == prevUserListSize || result.size() > limit) { break; } prevUserListSize = userListSize; currentLimit *= 2; if (currentLimit > Integer.MAX_VALUE) { break; } } } else { DocumentModelList userList = searchUsers(limit); result = usersToMapWithGroupRestrictions(userList); } userSize = result.size(); } if (!userOnly) { Schema schema = schemaManager.getSchema(userManager.getGroupSchemaName()); DocumentModelList groupList = userManager.searchGroups(prefix); List<String> admins = new ArrayList<>(); if (hideAdminGroups) { admins = userManager.getAdministratorsGroups(); } groupLoop: for (DocumentModel group : groupList) { if (hideAdminGroups) { for (String adminGroupName : admins) { if (adminGroupName.equals(group.getId())) { break groupLoop; } } } if (hidePowerUsersGroup && POWERUSERS.equals(group.getId())) { break groupLoop; } Map<String, Object> obj = new LinkedHashMap<>(); for (Field field : schema.getFields()) { QName fieldName = field.getName(); String key = fieldName.getLocalName(); Serializable value = group.getPropertyValue(fieldName.getPrefixedName()); obj.put(key, value); } String groupId = group.getId(); obj.put(SuggestConstants.ID, groupId); obj.put(MarshallingConstants.ENTITY_FIELD_NAME, NuxeoGroupJsonWriter.ENTITY_TYPE); SuggestConstants.computeGroupLabel(obj, groupId, userManager.getGroupLabelField(), hideFirstLabel); obj.put(SuggestConstants.TYPE_KEY_NAME, SuggestConstants.GROUP_TYPE); obj.put(SuggestConstants.PREFIXED_ID_KEY_NAME, NuxeoGroup.PREFIX + groupId); SuggestConstants.computeUserGroupIcon(obj, hideIcon); result.add(obj); } groupSize = result.size() - userSize; } if (limit > 0 && (userSize > limit || groupSize > limit || userSize + groupSize > limit)) { throw new SizeLimitExceededException(); } } catch (SizeLimitExceededException e) { return searchOverflowMessage(); } return Blobs.createJSONBlobFromValue(result); }  @OperationMethod Blob run(); }
SuggestUserEntries { @OperationMethod public Blob run() throws IOException { List<Map<String, Object>> result = new ArrayList<>(); boolean isGroupRestriction = !StringUtils.isBlank(groupRestriction); boolean groupOnly = false; boolean userOnly = isGroupRestriction; if (!isGroupRestriction && searchType != null && !searchType.isEmpty()) { if (searchType.equals(SuggestConstants.USER_TYPE)) { userOnly = true; } else if (searchType.equals(SuggestConstants.GROUP_TYPE)) { groupOnly = true; } } int limit = userSuggestionMaxSearchResults == null ? 0 : userSuggestionMaxSearchResults.intValue(); try { int userSize = 0; int groupSize = 0; if (!groupOnly) { if (limit > 0 && isGroupRestriction) { long currentLimit = limit; int prevUserListSize = -1; for (;;) { DocumentModelList userList = searchUsers(currentLimit); result = usersToMapWithGroupRestrictions(userList); int userListSize = userList.size(); if (userListSize == prevUserListSize || result.size() > limit) { break; } prevUserListSize = userListSize; currentLimit *= 2; if (currentLimit > Integer.MAX_VALUE) { break; } } } else { DocumentModelList userList = searchUsers(limit); result = usersToMapWithGroupRestrictions(userList); } userSize = result.size(); } if (!userOnly) { Schema schema = schemaManager.getSchema(userManager.getGroupSchemaName()); DocumentModelList groupList = userManager.searchGroups(prefix); List<String> admins = new ArrayList<>(); if (hideAdminGroups) { admins = userManager.getAdministratorsGroups(); } groupLoop: for (DocumentModel group : groupList) { if (hideAdminGroups) { for (String adminGroupName : admins) { if (adminGroupName.equals(group.getId())) { break groupLoop; } } } if (hidePowerUsersGroup && POWERUSERS.equals(group.getId())) { break groupLoop; } Map<String, Object> obj = new LinkedHashMap<>(); for (Field field : schema.getFields()) { QName fieldName = field.getName(); String key = fieldName.getLocalName(); Serializable value = group.getPropertyValue(fieldName.getPrefixedName()); obj.put(key, value); } String groupId = group.getId(); obj.put(SuggestConstants.ID, groupId); obj.put(MarshallingConstants.ENTITY_FIELD_NAME, NuxeoGroupJsonWriter.ENTITY_TYPE); SuggestConstants.computeGroupLabel(obj, groupId, userManager.getGroupLabelField(), hideFirstLabel); obj.put(SuggestConstants.TYPE_KEY_NAME, SuggestConstants.GROUP_TYPE); obj.put(SuggestConstants.PREFIXED_ID_KEY_NAME, NuxeoGroup.PREFIX + groupId); SuggestConstants.computeUserGroupIcon(obj, hideIcon); result.add(obj); } groupSize = result.size() - userSize; } if (limit > 0 && (userSize > limit || groupSize > limit || userSize + groupSize > limit)) { throw new SizeLimitExceededException(); } } catch (SizeLimitExceededException e) { return searchOverflowMessage(); } return Blobs.createJSONBlobFromValue(result); }  @OperationMethod Blob run(); static final String ID; static final String POWERUSERS; }