Search in sources :

Example 1 with SearchRequestImpl

use of org.uberfire.ext.security.management.impl.SearchRequestImpl in project kie-wb-common by kiegroup.

the class DefaultAdminPageHelper method addSecurityPerspective.

private void addSecurityPerspective() {
    if (hasAccessToPerspective(PerspectiveIds.SECURITY_MANAGEMENT)) {
        adminPage.addTool("root", constants.Roles(), "fa-unlock-alt", "security", () -> {
            final Command accessRoles = () -> {
                Map<String, String> params = new HashMap<>();
                params.put("activeTab", "RolesTab");
                placeManager.goTo(new DefaultPlaceRequest(SECURITY_MANAGEMENT, params));
            };
            accessRoles.execute();
            addAdminBreadcrumbs(SECURITY_MANAGEMENT, constants.SecurityManagement(), accessRoles);
        }, command -> userSystemManager.roles((AbstractEntityManager.SearchResponse<Role> response) -> {
            if (response != null) {
                command.execute(response.getTotal());
            }
        }, (o, throwable) -> false).search(new SearchRequestImpl("", 1, 1, null)));
        adminPage.addTool("root", constants.Groups(), "fa-users", "security", () -> {
            final Command accessGroups = () -> {
                Map<String, String> params = new HashMap<>();
                params.put("activeTab", "GroupsTab");
                placeManager.goTo(new DefaultPlaceRequest(SECURITY_MANAGEMENT, params));
            };
            accessGroups.execute();
            addAdminBreadcrumbs(SECURITY_MANAGEMENT, constants.SecurityManagement(), accessGroups);
        }, command -> userSystemManager.groups((AbstractEntityManager.SearchResponse<Group> response) -> {
            if (response != null) {
                command.execute(response.getTotal());
            }
        }, (o, throwable) -> false).search(new SearchRequestImpl("", 1, 1, null)));
        adminPage.addTool("root", constants.Users(), "fa-user", "security", () -> {
            final Command accessUsers = () -> {
                Map<String, String> params = new HashMap<>();
                params.put("activeTab", "UsersTab");
                placeManager.goTo(new DefaultPlaceRequest(SECURITY_MANAGEMENT, params));
            };
            accessUsers.execute();
            addAdminBreadcrumbs(SECURITY_MANAGEMENT, constants.SecurityManagement(), accessUsers);
        }, command -> userSystemManager.users((AbstractEntityManager.SearchResponse<User> response) -> {
            if (response != null) {
                command.execute(response.getTotal());
            }
        }, (o, throwable) -> false).search(new SearchRequestImpl("", 1, 1, null)));
    }
}
Also used : Command(org.uberfire.mvp.Command) SearchRequestImpl(org.uberfire.ext.security.management.impl.SearchRequestImpl) DefaultPlaceRequest(org.uberfire.mvp.impl.DefaultPlaceRequest) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with SearchRequestImpl

use of org.uberfire.ext.security.management.impl.SearchRequestImpl in project kie-wb-common by kiegroup.

the class AssigneeLiveSearchServiceTest method testSearchSingleUser.

@Test
public void testSearchSingleUser() {
    assigneeLiveSearchService.init(AssigneeType.USER);
    assigneeLiveSearchService.searchEntry("user", callback);
    ArgumentCaptor<SearchRequestImpl> requestArgumentCaptor = ArgumentCaptor.forClass(SearchRequestImpl.class);
    verify(userManager).search(requestArgumentCaptor.capture());
    SearchRequestImpl request = requestArgumentCaptor.getValue();
    assertEquals("user", request.getSearchPattern());
    assertEquals(1, request.getPageSize());
    ArgumentCaptor<RemoteCallback> callbackArgumentCaptor = ArgumentCaptor.forClass(RemoteCallback.class);
    verify(userSystemManager).users(callbackArgumentCaptor.capture(), any());
    RemoteCallback<AbstractEntityManager.SearchResponse<?>> successCallback = callbackArgumentCaptor.getValue();
    successCallback.callback(prepareSingleUserResponse());
    ArgumentCaptor<LiveSearchResults> resultsArgumentCaptor = ArgumentCaptor.forClass(LiveSearchResults.class);
    verify(callback).afterSearch(resultsArgumentCaptor.capture());
    LiveSearchResults<LiveSearchEntry<String>> result = resultsArgumentCaptor.getValue();
    assertEquals(1, result.size());
    assertEquals("user", result.get(0).getValue());
}
Also used : LiveSearchResults(org.uberfire.ext.widgets.common.client.dropdown.LiveSearchResults) LiveSearchEntry(org.uberfire.ext.widgets.common.client.dropdown.LiveSearchEntry) SearchRequestImpl(org.uberfire.ext.security.management.impl.SearchRequestImpl) RemoteCallback(org.jboss.errai.common.client.api.RemoteCallback) Test(org.junit.Test)

Example 3 with SearchRequestImpl

use of org.uberfire.ext.security.management.impl.SearchRequestImpl in project kie-wb-common by kiegroup.

the class AssigneeLiveSearchServiceTest method testSearchSingleGroup.

@Test
public void testSearchSingleGroup() {
    assigneeLiveSearchService.init(AssigneeType.GROUP);
    assigneeLiveSearchService.searchEntry("it", callback);
    ArgumentCaptor<SearchRequestImpl> requestArgumentCaptor = ArgumentCaptor.forClass(SearchRequestImpl.class);
    verify(groupManager).search(requestArgumentCaptor.capture());
    SearchRequestImpl request = requestArgumentCaptor.getValue();
    assertEquals("it", request.getSearchPattern());
    assertEquals(1, request.getPageSize());
    ArgumentCaptor<RemoteCallback> callbackArgumentCaptor = ArgumentCaptor.forClass(RemoteCallback.class);
    verify(userSystemManager).groups(callbackArgumentCaptor.capture(), any());
    RemoteCallback<AbstractEntityManager.SearchResponse<?>> successCallback = callbackArgumentCaptor.getValue();
    successCallback.callback(prepareSingleGroupResponse());
    ArgumentCaptor<LiveSearchResults> resultsArgumentCaptor = ArgumentCaptor.forClass(LiveSearchResults.class);
    verify(callback).afterSearch(resultsArgumentCaptor.capture());
    LiveSearchResults<LiveSearchEntry<String>> result = resultsArgumentCaptor.getValue();
    assertEquals(1, result.size());
    assertEquals("it", result.get(0).getValue());
}
Also used : LiveSearchResults(org.uberfire.ext.widgets.common.client.dropdown.LiveSearchResults) LiveSearchEntry(org.uberfire.ext.widgets.common.client.dropdown.LiveSearchEntry) SearchRequestImpl(org.uberfire.ext.security.management.impl.SearchRequestImpl) RemoteCallback(org.jboss.errai.common.client.api.RemoteCallback) Test(org.junit.Test)

Example 4 with SearchRequestImpl

use of org.uberfire.ext.security.management.impl.SearchRequestImpl in project kie-wb-common by kiegroup.

the class AssigneeLiveSearchService method search.

@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);
    }
}
Also used : ErrorCallback(org.jboss.errai.common.client.api.ErrorCallback) Group(org.jboss.errai.security.shared.api.Group) Set(java.util.Set) RemoteCallback(org.jboss.errai.common.client.api.RemoteCallback) SearchRequestImpl(org.uberfire.ext.security.management.impl.SearchRequestImpl) Collectors(java.util.stream.Collectors) EntryCreationLiveSearchService(org.uberfire.ext.widgets.common.client.dropdown.EntryCreationLiveSearchService) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) LiveSearchResults(org.uberfire.ext.widgets.common.client.dropdown.LiveSearchResults) Inject(javax.inject.Inject) List(java.util.List) Message(org.jboss.errai.bus.client.api.messaging.Message) Dependent(javax.enterprise.context.Dependent) AbstractEntityManager(org.uberfire.ext.security.management.api.AbstractEntityManager) User(org.jboss.errai.security.shared.api.identity.User) Optional(java.util.Optional) LiveSearchCallback(org.uberfire.ext.widgets.common.client.dropdown.LiveSearchCallback) AssigneeType(org.kie.workbench.common.stunner.bpmn.forms.model.AssigneeType) ClientUserSystemManager(org.uberfire.ext.security.management.client.ClientUserSystemManager) Message(org.jboss.errai.bus.client.api.messaging.Message) SearchRequestImpl(org.uberfire.ext.security.management.impl.SearchRequestImpl)

Example 5 with SearchRequestImpl

use of org.uberfire.ext.security.management.impl.SearchRequestImpl in project kie-wb-common by kiegroup.

the class AssigneeLiveSearchService method searchEntry.

@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);
    }
}
Also used : ErrorCallback(org.jboss.errai.common.client.api.ErrorCallback) Group(org.jboss.errai.security.shared.api.Group) Set(java.util.Set) RemoteCallback(org.jboss.errai.common.client.api.RemoteCallback) SearchRequestImpl(org.uberfire.ext.security.management.impl.SearchRequestImpl) Collectors(java.util.stream.Collectors) EntryCreationLiveSearchService(org.uberfire.ext.widgets.common.client.dropdown.EntryCreationLiveSearchService) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) LiveSearchResults(org.uberfire.ext.widgets.common.client.dropdown.LiveSearchResults) Inject(javax.inject.Inject) List(java.util.List) Message(org.jboss.errai.bus.client.api.messaging.Message) Dependent(javax.enterprise.context.Dependent) AbstractEntityManager(org.uberfire.ext.security.management.api.AbstractEntityManager) User(org.jboss.errai.security.shared.api.identity.User) Optional(java.util.Optional) LiveSearchCallback(org.uberfire.ext.widgets.common.client.dropdown.LiveSearchCallback) AssigneeType(org.kie.workbench.common.stunner.bpmn.forms.model.AssigneeType) ClientUserSystemManager(org.uberfire.ext.security.management.client.ClientUserSystemManager) Message(org.jboss.errai.bus.client.api.messaging.Message) SearchRequestImpl(org.uberfire.ext.security.management.impl.SearchRequestImpl)

Aggregations

SearchRequestImpl (org.uberfire.ext.security.management.impl.SearchRequestImpl)7 RemoteCallback (org.jboss.errai.common.client.api.RemoteCallback)6 LiveSearchResults (org.uberfire.ext.widgets.common.client.dropdown.LiveSearchResults)6 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Optional (java.util.Optional)2 Set (java.util.Set)2 TreeSet (java.util.TreeSet)2 Collectors (java.util.stream.Collectors)2 Dependent (javax.enterprise.context.Dependent)2 Inject (javax.inject.Inject)2 Message (org.jboss.errai.bus.client.api.messaging.Message)2 ErrorCallback (org.jboss.errai.common.client.api.ErrorCallback)2 Group (org.jboss.errai.security.shared.api.Group)2 User (org.jboss.errai.security.shared.api.identity.User)2 AssigneeType (org.kie.workbench.common.stunner.bpmn.forms.model.AssigneeType)2 AbstractEntityManager (org.uberfire.ext.security.management.api.AbstractEntityManager)2 ClientUserSystemManager (org.uberfire.ext.security.management.client.ClientUserSystemManager)2 EntryCreationLiveSearchService (org.uberfire.ext.widgets.common.client.dropdown.EntryCreationLiveSearchService)2