Search in sources :

Example 21 with GroupQuery

use of org.camunda.bpm.engine.identity.GroupQuery in project camunda-bpm-platform by camunda.

the class FetchAndLockRestServiceInteractionTest method setupGroupQueryMock.

private List<String> setupGroupQueryMock(List<Group> groups) {
    GroupQuery mockGroupQuery = mock(GroupQuery.class);
    when(identityServiceMock.createGroupQuery()).thenReturn(mockGroupQuery);
    when(mockGroupQuery.groupMember(anyString())).thenReturn(mockGroupQuery);
    when(mockGroupQuery.list()).thenReturn(groups);
    List<String> groupIds = new ArrayList<String>();
    for (Group groupMock : groups) {
        groupIds.add(groupMock.getId());
    }
    return groupIds;
}
Also used : Group(org.camunda.bpm.engine.identity.Group) GroupQuery(org.camunda.bpm.engine.identity.GroupQuery) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 22 with GroupQuery

use of org.camunda.bpm.engine.identity.GroupQuery in project camunda-bpm-platform by camunda.

the class AbstractAuthenticationFilterTest method setupGroupQueryMock.

protected List<String> setupGroupQueryMock(List<Group> groups) {
    GroupQuery mockGroupQuery = mock(GroupQuery.class);
    when(identityServiceMock.createGroupQuery()).thenReturn(mockGroupQuery);
    when(mockGroupQuery.groupMember(anyString())).thenReturn(mockGroupQuery);
    when(mockGroupQuery.list()).thenReturn(groups);
    List<String> groupIds = new ArrayList<String>();
    for (Group groupMock : groups) {
        groupIds.add(groupMock.getId());
    }
    return groupIds;
}
Also used : Group(org.camunda.bpm.engine.identity.Group) GroupQuery(org.camunda.bpm.engine.identity.GroupQuery) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString)

Example 23 with GroupQuery

use of org.camunda.bpm.engine.identity.GroupQuery in project camunda-bpm-platform by camunda.

the class GroupRestServiceImpl method queryGroups.

public List<GroupDto> queryGroups(GroupQueryDto queryDto, Integer firstResult, Integer maxResults) {
    queryDto.setObjectMapper(getObjectMapper());
    GroupQuery query = queryDto.toQuery(getProcessEngine());
    List<Group> resultList;
    if (firstResult != null || maxResults != null) {
        resultList = executePaginatedQuery(query, firstResult, maxResults);
    } else {
        resultList = query.list();
    }
    return GroupDto.fromGroupList(resultList);
}
Also used : Group(org.camunda.bpm.engine.identity.Group) GroupQuery(org.camunda.bpm.engine.identity.GroupQuery)

Example 24 with GroupQuery

use of org.camunda.bpm.engine.identity.GroupQuery in project camunda-bpm-platform by camunda.

the class IdentityRestServiceImpl method getGroupInfo.

@Override
public GroupInfoDto getGroupInfo(String userId) {
    if (userId == null) {
        throw new InvalidRequestException(Status.BAD_REQUEST, "No user id was supplied");
    }
    IdentityService identityService = getProcessEngine().getIdentityService();
    GroupQuery query = identityService.createGroupQuery();
    List<Group> userGroups = query.groupMember(userId).orderByGroupName().asc().list();
    Set<UserDto> allGroupUsers = new HashSet<UserDto>();
    List<GroupDto> allGroups = new ArrayList<GroupDto>();
    for (Group group : userGroups) {
        List<User> groupUsers = identityService.createUserQuery().memberOfGroup(group.getId()).list();
        for (User user : groupUsers) {
            if (!user.getId().equals(userId)) {
                allGroupUsers.add(new UserDto(user.getId(), user.getFirstName(), user.getLastName()));
            }
        }
        allGroups.add(new GroupDto(group.getId(), group.getName()));
    }
    return new GroupInfoDto(allGroups, allGroupUsers);
}
Also used : Group(org.camunda.bpm.engine.identity.Group) User(org.camunda.bpm.engine.identity.User) UserDto(org.camunda.bpm.engine.rest.dto.task.UserDto) GroupDto(org.camunda.bpm.engine.rest.dto.task.GroupDto) ArrayList(java.util.ArrayList) IdentityService(org.camunda.bpm.engine.IdentityService) GroupQuery(org.camunda.bpm.engine.identity.GroupQuery) GroupInfoDto(org.camunda.bpm.engine.rest.dto.task.GroupInfoDto) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) HashSet(java.util.HashSet)

Example 25 with GroupQuery

use of org.camunda.bpm.engine.identity.GroupQuery in project camunda-bpm-platform by camunda.

the class GroupQueryTest method testQueryByInvalidNameLike.

public void testQueryByInvalidNameLike() {
    GroupQuery query = identityService.createGroupQuery().groupNameLike("%invalid%");
    verifyQueryResults(query, 0);
    try {
        identityService.createGroupQuery().groupNameLike(null).list();
        fail();
    } catch (ProcessEngineException e) {
    }
}
Also used : GroupQuery(org.camunda.bpm.engine.identity.GroupQuery) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Aggregations

GroupQuery (org.camunda.bpm.engine.identity.GroupQuery)34 Group (org.camunda.bpm.engine.identity.Group)22 Test (org.junit.Test)12 Matchers.anyString (org.mockito.Matchers.anyString)10 ArrayList (java.util.ArrayList)6 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)5 User (org.camunda.bpm.engine.identity.User)5 UserQuery (org.camunda.bpm.engine.identity.UserQuery)4 Authentication (org.camunda.bpm.engine.impl.identity.Authentication)4 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)3 Tenant (org.camunda.bpm.engine.identity.Tenant)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Response (com.jayway.restassured.response.Response)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)1 IdentityService (org.camunda.bpm.engine.IdentityService)1 RepositoryService (org.camunda.bpm.engine.RepositoryService)1