@Test public void testListQuery() { ResourceListQueryImpl query = new ResourceListQueryImpl(); query.setLimit(0); query.setOffset(0); Assert.assertEquals(4, usersListProvider.getList(UsersListProvider.USERNAME, query).size()); query.setOffset(3); Assert.assertEquals(1, usersListProvider.getList(UsersListProvider.USERNAME, query).size()); query.setOffset(0); query.setLimit(1); Assert.assertEquals(1, usersListProvider.getList(UsersListProvider.USERNAME, query).size()); }
@Override public Map<String, String> getList(String listName, ResourceListQuery query) { Map<String, String> usersList = new HashMap<>(); int offset = 0; int limit = 0; if (query != null) { if (query.getLimit().isSome()) limit = query.getLimit().get(); if (query.getOffset().isSome()) offset = query.getOffset().get(); } Iterator<User> users = userDirectoryService.findUsers("%", offset, limit); while (users.hasNext()) { User u = users.next(); if (EMAIL.equals(listName) && StringUtils.isNotBlank(u.getEmail())) { usersList.put(u.getUsername(), u.getEmail()); } else if (USERNAME.equals(listName) && StringUtils.isNotBlank(u.getUsername())) { usersList.put(u.getUsername(), u.getUsername()); } else if (NAME.equals(listName) && StringUtils.isNotBlank(u.getName())) { usersList.put(u.getUsername(), u.getName()); } else if (NAME.equals(listName) || NAME_AND_EMAIL.equals(listName) || NAME_AND_USERNAME.equals(listName)) { usersList.put(u.getUsername(), createDisplayName(u, listName)); } else if (NAME_ONLY.equals(listName) && StringUtils.isNotBlank(u.getName())) { usersList.put(u.getName(), u.getName()); } else if (EMAIL_ONLY.equals(listName) && StringUtils.isNotBlank(u.getEmail())) { usersList.put(u.getEmail(), u.getEmail()); } else if (USERDIRECTORY_ONLY.equals(listName) && StringUtils.isNotBlank(u.getProvider())) { usersList.put(u.getProvider(), u.getProvider()); } else if (ROLE_ONLY.equals(listName) && u.getRoles().size() > 0) { for (Role role : u.getRoles()) { usersList.put(role.getName(), role.getName()); } } } return usersList; }
UsersListProvider implements ResourceListProvider { @Override public Map<String, String> getList(String listName, ResourceListQuery query) { Map<String, String> usersList = new HashMap<>(); int offset = 0; int limit = 0; if (query != null) { if (query.getLimit().isSome()) limit = query.getLimit().get(); if (query.getOffset().isSome()) offset = query.getOffset().get(); } Iterator<User> users = userDirectoryService.findUsers("%", offset, limit); while (users.hasNext()) { User u = users.next(); if (EMAIL.equals(listName) && StringUtils.isNotBlank(u.getEmail())) { usersList.put(u.getUsername(), u.getEmail()); } else if (USERNAME.equals(listName) && StringUtils.isNotBlank(u.getUsername())) { usersList.put(u.getUsername(), u.getUsername()); } else if (NAME.equals(listName) && StringUtils.isNotBlank(u.getName())) { usersList.put(u.getUsername(), u.getName()); } else if (NAME.equals(listName) || NAME_AND_EMAIL.equals(listName) || NAME_AND_USERNAME.equals(listName)) { usersList.put(u.getUsername(), createDisplayName(u, listName)); } else if (NAME_ONLY.equals(listName) && StringUtils.isNotBlank(u.getName())) { usersList.put(u.getName(), u.getName()); } else if (EMAIL_ONLY.equals(listName) && StringUtils.isNotBlank(u.getEmail())) { usersList.put(u.getEmail(), u.getEmail()); } else if (USERDIRECTORY_ONLY.equals(listName) && StringUtils.isNotBlank(u.getProvider())) { usersList.put(u.getProvider(), u.getProvider()); } else if (ROLE_ONLY.equals(listName) && u.getRoles().size() > 0) { for (Role role : u.getRoles()) { usersList.put(role.getName(), role.getName()); } } } return usersList; } }
UsersListProvider implements ResourceListProvider { @Override public Map<String, String> getList(String listName, ResourceListQuery query) { Map<String, String> usersList = new HashMap<>(); int offset = 0; int limit = 0; if (query != null) { if (query.getLimit().isSome()) limit = query.getLimit().get(); if (query.getOffset().isSome()) offset = query.getOffset().get(); } Iterator<User> users = userDirectoryService.findUsers("%", offset, limit); while (users.hasNext()) { User u = users.next(); if (EMAIL.equals(listName) && StringUtils.isNotBlank(u.getEmail())) { usersList.put(u.getUsername(), u.getEmail()); } else if (USERNAME.equals(listName) && StringUtils.isNotBlank(u.getUsername())) { usersList.put(u.getUsername(), u.getUsername()); } else if (NAME.equals(listName) && StringUtils.isNotBlank(u.getName())) { usersList.put(u.getUsername(), u.getName()); } else if (NAME.equals(listName) || NAME_AND_EMAIL.equals(listName) || NAME_AND_USERNAME.equals(listName)) { usersList.put(u.getUsername(), createDisplayName(u, listName)); } else if (NAME_ONLY.equals(listName) && StringUtils.isNotBlank(u.getName())) { usersList.put(u.getName(), u.getName()); } else if (EMAIL_ONLY.equals(listName) && StringUtils.isNotBlank(u.getEmail())) { usersList.put(u.getEmail(), u.getEmail()); } else if (USERDIRECTORY_ONLY.equals(listName) && StringUtils.isNotBlank(u.getProvider())) { usersList.put(u.getProvider(), u.getProvider()); } else if (ROLE_ONLY.equals(listName) && u.getRoles().size() > 0) { for (Role role : u.getRoles()) { usersList.put(role.getName(), role.getName()); } } } return usersList; }  }
UsersListProvider implements ResourceListProvider { @Override public Map<String, String> getList(String listName, ResourceListQuery query) { Map<String, String> usersList = new HashMap<>(); int offset = 0; int limit = 0; if (query != null) { if (query.getLimit().isSome()) limit = query.getLimit().get(); if (query.getOffset().isSome()) offset = query.getOffset().get(); } Iterator<User> users = userDirectoryService.findUsers("%", offset, limit); while (users.hasNext()) { User u = users.next(); if (EMAIL.equals(listName) && StringUtils.isNotBlank(u.getEmail())) { usersList.put(u.getUsername(), u.getEmail()); } else if (USERNAME.equals(listName) && StringUtils.isNotBlank(u.getUsername())) { usersList.put(u.getUsername(), u.getUsername()); } else if (NAME.equals(listName) && StringUtils.isNotBlank(u.getName())) { usersList.put(u.getUsername(), u.getName()); } else if (NAME.equals(listName) || NAME_AND_EMAIL.equals(listName) || NAME_AND_USERNAME.equals(listName)) { usersList.put(u.getUsername(), createDisplayName(u, listName)); } else if (NAME_ONLY.equals(listName) && StringUtils.isNotBlank(u.getName())) { usersList.put(u.getName(), u.getName()); } else if (EMAIL_ONLY.equals(listName) && StringUtils.isNotBlank(u.getEmail())) { usersList.put(u.getEmail(), u.getEmail()); } else if (USERDIRECTORY_ONLY.equals(listName) && StringUtils.isNotBlank(u.getProvider())) { usersList.put(u.getProvider(), u.getProvider()); } else if (ROLE_ONLY.equals(listName) && u.getRoles().size() > 0) { for (Role role : u.getRoles()) { usersList.put(role.getName(), role.getName()); } } } return usersList; }  void setUserDirectoryService(UserDirectoryService userDirectoryService); @Override String[] getListNames(); @Override Map<String, String> getList(String listName, ResourceListQuery query); @Override boolean isTranslatable(String listName); @Override String getDefault(); }
UsersListProvider implements ResourceListProvider { @Override public Map<String, String> getList(String listName, ResourceListQuery query) { Map<String, String> usersList = new HashMap<>(); int offset = 0; int limit = 0; if (query != null) { if (query.getLimit().isSome()) limit = query.getLimit().get(); if (query.getOffset().isSome()) offset = query.getOffset().get(); } Iterator<User> users = userDirectoryService.findUsers("%", offset, limit); while (users.hasNext()) { User u = users.next(); if (EMAIL.equals(listName) && StringUtils.isNotBlank(u.getEmail())) { usersList.put(u.getUsername(), u.getEmail()); } else if (USERNAME.equals(listName) && StringUtils.isNotBlank(u.getUsername())) { usersList.put(u.getUsername(), u.getUsername()); } else if (NAME.equals(listName) && StringUtils.isNotBlank(u.getName())) { usersList.put(u.getUsername(), u.getName()); } else if (NAME.equals(listName) || NAME_AND_EMAIL.equals(listName) || NAME_AND_USERNAME.equals(listName)) { usersList.put(u.getUsername(), createDisplayName(u, listName)); } else if (NAME_ONLY.equals(listName) && StringUtils.isNotBlank(u.getName())) { usersList.put(u.getName(), u.getName()); } else if (EMAIL_ONLY.equals(listName) && StringUtils.isNotBlank(u.getEmail())) { usersList.put(u.getEmail(), u.getEmail()); } else if (USERDIRECTORY_ONLY.equals(listName) && StringUtils.isNotBlank(u.getProvider())) { usersList.put(u.getProvider(), u.getProvider()); } else if (ROLE_ONLY.equals(listName) && u.getRoles().size() > 0) { for (Role role : u.getRoles()) { usersList.put(role.getName(), role.getName()); } } } return usersList; }  void setUserDirectoryService(UserDirectoryService userDirectoryService); @Override String[] getListNames(); @Override Map<String, String> getList(String listName, ResourceListQuery query); @Override boolean isTranslatable(String listName); @Override String getDefault(); static final String NAME; static final String NAME_AND_EMAIL; static final String NAME_AND_USERNAME; static final String USERNAME; static final String EMAIL; static final String NAME_ONLY; static final String EMAIL_ONLY; static final String ROLE_ONLY; static final String USERDIRECTORY_ONLY; }