protected AbstractEntityManager.SearchRequest getSearchRequest(final AbstractEntityManager.SearchRequest request) { return request != null ? request : new SearchRequestImpl(); }
protected AbstractEntityManager.SearchRequest getSearchRequest(final AbstractEntityManager.SearchRequest request) { return request != null ? request : new SearchRequestImpl(); }
@Override public List<String> getAllUsers() { try { final List<User> users = userManagerService.search(new SearchRequestImpl("", 1, Integer.MAX_VALUE)).getResults(); return users.stream().map(User::getIdentifier).collect(Collectors.toList()); } catch (NoImplementationAvailableException e) { return Collections.singletonList("admin"); } }
@Override public void search(final String pattern, final int maxResults, final LiveSearchCallback<String> callback) { final List<String> filteredCustomEntries; if (pattern == null || pattern.isEmpty()) { filteredCustomEntries = customEntries; } else { filteredCustomEntries = customEntries.stream() .filter(entry -> entry.contains(pattern)) .collect(Collectors.toList()); } RemoteCallback<AbstractEntityManager.SearchResponse<?>> searchResponseRemoteCallback = response -> processFilterResponse(response, filteredCustomEntries, maxResults, callback); ErrorCallback<Message> searchErrorCallback = (message, throwable) -> processError(callback); SearchRequestImpl request = new SearchRequestImpl(pattern, 1, maxResults); if (AssigneeType.USER.equals(type)) { userSystemManager.users(searchResponseRemoteCallback, searchErrorCallback).search(request); } else { userSystemManager.groups(searchResponseRemoteCallback, searchErrorCallback).search(request); } }
@Override protected void showSearch() { showLoadingView(); // Call backend service. userSystemManager.users(new RemoteCallback<AbstractEntityManager.SearchResponse<User>>() { @Override public void callback(final AbstractEntityManager.SearchResponse<User> response) { // Configure the entities list view. final EntitiesList.Callback<User> callback = createCallback(); entitiesList.show(response, callback); // Show the explorer view. view.show(context, viewCallback); hideLoadingView(); } }, errorCallback).search(new SearchRequestImpl(searchPattern, currentPage, PAGE_SIZE)); }
@Test(expected = RuntimeException.class) public void testSearchPageZero() { List<Group> groups = new ArrayList<Group>(1); // First page cannot be 0. AbstractEntityManager.SearchRequest request = new SearchRequestImpl("", 0, 5); AbstractEntityManager.SearchResponse<Group> response = searchEngine.search(groups, request); }
@Override protected void showSearch() { showLoadingView(); // Call backend service. userSystemManager.users(new RemoteCallback<AbstractEntityManager.SearchResponse<User>>() { @Override public void callback(final AbstractEntityManager.SearchResponse<User> response) { // Configure the entities list view. final EntitiesList.Callback<User> callback = createCallback(); entitiesList.show(response, callback); // Show the explorer view. view.show(context, viewCallback); hideLoadingView(); } }, errorCallback).search(new SearchRequestImpl(searchPattern, currentPage, PAGE_SIZE)); }
@Test(expected = RuntimeException.class) public void testSearchPageZero() { List<Group> groups = new ArrayList<Group>(1); // First page cannot be 0. AbstractEntityManager.SearchRequest request = new SearchRequestImpl("", 0, 5); AbstractEntityManager.SearchResponse<Group> response = searchEngine.search(groups, request); }
@Override protected void showSearch() { showLoadingView(); // Call backend service. userSystemManager.roles(new RemoteCallback<AbstractEntityManager.SearchResponse<Role>>() { @Override public void callback(final AbstractEntityManager.SearchResponse<Role> response) { if (response != null) { final EntitiesList.Callback<Role> callback = createCallback(); entitiesList.show(response, callback); // Show the explorer's view. view.show(context, viewCallback); hideLoadingView(); } } }, errorCallback).search(new SearchRequestImpl(searchPattern, currentPage, pageSize, context != null ? context.getConstrainedEntities() : null)); } }
@Override protected void showSearch() { showLoadingView(); // Call backend service. userSystemManager.roles(new RemoteCallback<AbstractEntityManager.SearchResponse<Role>>() { @Override public void callback(final AbstractEntityManager.SearchResponse<Role> response) { if (response != null) { final EntitiesList.Callback<Role> callback = createCallback(); entitiesList.show(response, callback); // Show the explorer's view. view.show(context, viewCallback); hideLoadingView(); } } }, errorCallback).search(new SearchRequestImpl(searchPattern, currentPage, pageSize, context != null ? context.getConstrainedEntities() : null)); } }
@Override protected void showSearch() { showLoadingView(); // Call backend service. userSystemManager.groups(new RemoteCallback<AbstractEntityManager.SearchResponse<Group>>() { @Override public void callback(final AbstractEntityManager.SearchResponse<Group> response) { if (response != null) { final EntitiesList.Callback<Group> callback = createCallback(); entitiesList.show(response, callback); // Show the explorer's view. view.show(context, viewCallback); hideLoadingView(); } } }, errorCallback).search(new SearchRequestImpl(searchPattern, currentPage, pageSize, context != null ? context.getConstrainedEntities() : null)); }
@Override protected void showSearch() { showLoadingView(); // Call backend service. userSystemManager.groups(new RemoteCallback<AbstractEntityManager.SearchResponse<Group>>() { @Override public void callback(final AbstractEntityManager.SearchResponse<Group> response) { if (response != null) { final EntitiesList.Callback<Group> callback = createCallback(); entitiesList.show(response, callback); // Show the explorer's view. view.show(context, viewCallback); hideLoadingView(); } } }, errorCallback).search(new SearchRequestImpl(searchPattern, currentPage, pageSize, context != null ? context.getConstrainedEntities() : null)); }
@Override public void searchEntry(String key, LiveSearchCallback<String> callback) { SearchRequestImpl request = new SearchRequestImpl(key, 1, 1); ErrorCallback<Message> searchErrorCallback = (message, throwable) -> processError(callback); RemoteCallback<AbstractEntityManager.SearchResponse<?>> searchResponseRemoteCallback = response -> searchEntry(key, response, callback); if (AssigneeType.USER.equals(type)) { userSystemManager.users(searchResponseRemoteCallback, searchErrorCallback).search(request); } else { userSystemManager.groups(searchResponseRemoteCallback, searchErrorCallback).search(request); } }
@Test public void testSearch() { GroupManager groupManager = mock(GroupManager.class); doAnswer(new Answer<Group>() { @Override public Group answer(InvocationOnMock invocationOnMock) throws Throwable { String name = (String) invocationOnMock.getArguments()[0]; Group g = mock(Group.class); when(g.getName()).thenReturn(name); return g; } }).when(groupManager).get(anyString()); when(userSystemManager.groups()).thenReturn(groupManager); AbstractEntityManager.SearchResponse<Role> response = tested.search(new SearchRequestImpl("", 1, 10)); assertNotNull(response); int total = response.getTotal(); assertEquals(total, 3); boolean hasNextPage = response.hasNextPage(); assertEquals(hasNextPage, false); List<Role> results = response.getResults(); assertEquals(results.size(), 3); }
@Test public void testSearchRoleNotExists() { GroupManager groupManager = mock(GroupManager.class); doAnswer(new Answer<Group>() { @Override public Group answer(InvocationOnMock invocationOnMock) throws Throwable { String name = (String) invocationOnMock.getArguments()[0]; Group g = mock(Group.class); when(g.getName()).thenReturn(name); return g; } }).when(groupManager).get(anyString()); doThrow(new GroupNotFoundException("admin")).when(groupManager).get("admin"); when(userSystemManager.groups()).thenReturn(groupManager); AbstractEntityManager.SearchResponse<Role> response = tested.search(new SearchRequestImpl("", 1, 10)); assertNotNull(response); int total = response.getTotal(); assertEquals(total, 3); boolean hasNextPage = response.hasNextPage(); assertEquals(hasNextPage, false); List<Role> results = response.getResults(); assertEquals(results.size(), 3); }
@Test public void testSearch() { GroupManager groupManager = mock(GroupManager.class); doAnswer(new Answer<Group>() { @Override public Group answer(InvocationOnMock invocationOnMock) throws Throwable { String name = (String) invocationOnMock.getArguments()[0]; Group g = mock(Group.class); when(g.getName()).thenReturn(name); return g; } }).when(groupManager).get(anyString()); when(userSystemManager.groups()).thenReturn(groupManager); AbstractEntityManager.SearchResponse<Role> response = tested.search(new SearchRequestImpl("", 1, 10)); assertNotNull(response); int total = response.getTotal(); assertEquals(total, 3); boolean hasNextPage = response.hasNextPage(); assertEquals(hasNextPage, false); List<Role> results = response.getResults(); assertEquals(results.size(), 3); }
@Test public void testSearchRoleNotExists() { GroupManager groupManager = mock(GroupManager.class); doAnswer(new Answer<Group>() { @Override public Group answer(InvocationOnMock invocationOnMock) throws Throwable { String name = (String) invocationOnMock.getArguments()[0]; Group g = mock(Group.class); when(g.getName()).thenReturn(name); return g; } }).when(groupManager).get(anyString()); doThrow(new GroupNotFoundException("admin")).when(groupManager).get("admin"); when(userSystemManager.groups()).thenReturn(groupManager); AbstractEntityManager.SearchResponse<Role> response = tested.search(new SearchRequestImpl("", 1, 10)); assertNotNull(response); int total = response.getTotal(); assertEquals(total, 3); boolean hasNextPage = response.hasNextPage(); assertEquals(hasNextPage, false); List<Role> results = response.getResults(); assertEquals(results.size(), 3); }
(o, throwable) -> false).search(new SearchRequestImpl("", 1, 1, (o, throwable) -> false).search(new SearchRequestImpl("", 1, 1, (o, throwable) -> false).search(new SearchRequestImpl("", 1, 1,
@Test public void testSearchSingle() { List<Group> groups = createTestGroups("group", 20); AbstractEntityManager.SearchRequest request = new SearchRequestImpl("group18", 1, 5); AbstractEntityManager.SearchResponse<Group> response = searchEngine.search(groups, request); assertNotNull(response); int total = response.getTotal(); assertEquals(total, 1); boolean hasNextPage = response.hasNextPage(); assertEquals(hasNextPage, false); List<Group> results = response.getResults(); assertEquals(results.size(), 1); Group g = results.get(0); assertEquals("group18", g.getName()); }
@Test public void testSearchSingle() { List<Group> groups = createTestGroups("group", 20); AbstractEntityManager.SearchRequest request = new SearchRequestImpl("group18", 1, 5); AbstractEntityManager.SearchResponse<Group> response = searchEngine.search(groups, request); assertNotNull(response); int total = response.getTotal(); assertEquals(total, 1); boolean hasNextPage = response.hasNextPage(); assertEquals(hasNextPage, false); List<Group> results = response.getResults(); assertEquals(results.size(), 1); Group g = results.get(0); assertEquals("group18", g.getName()); }