Search in sources :

Example 6 with UserRole

use of com.ctrip.framework.apollo.portal.entity.po.UserRole in project apollo by ctripcorp.

the class DefaultRolePermissionService method queryUsersWithRole.

/**
 * Query users with role
 */
public Set<UserInfo> queryUsersWithRole(String roleName) {
    Role role = findRoleByRoleName(roleName);
    if (role == null) {
        return Collections.emptySet();
    }
    List<UserRole> userRoles = userRoleRepository.findByRoleId(role.getId());
    return userRoles.stream().map(userRole -> {
        UserInfo userInfo = new UserInfo();
        userInfo.setUserId(userRole.getUserId());
        return userInfo;
    }).collect(Collectors.toSet());
}
Also used : Role(com.ctrip.framework.apollo.portal.entity.po.Role) UserRole(com.ctrip.framework.apollo.portal.entity.po.UserRole) Date(java.util.Date) Role(com.ctrip.framework.apollo.portal.entity.po.Role) Autowired(org.springframework.beans.factory.annotation.Autowired) Multimap(com.google.common.collect.Multimap) Permission(com.ctrip.framework.apollo.portal.entity.po.Permission) UserInfo(com.ctrip.framework.apollo.portal.entity.bo.UserInfo) HashMultimap(com.google.common.collect.HashMultimap) Lists(com.google.common.collect.Lists) StreamSupport(java.util.stream.StreamSupport) RolePermissionService(com.ctrip.framework.apollo.portal.service.RolePermissionService) UserRole(com.ctrip.framework.apollo.portal.entity.po.UserRole) PortalConfig(com.ctrip.framework.apollo.portal.component.config.PortalConfig) RolePermission(com.ctrip.framework.apollo.portal.entity.po.RolePermission) Collection(java.util.Collection) Set(java.util.Set) ConsumerRoleRepository(com.ctrip.framework.apollo.openapi.repository.ConsumerRoleRepository) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) List(java.util.List) UserRoleRepository(com.ctrip.framework.apollo.portal.repository.UserRoleRepository) RolePermissionRepository(com.ctrip.framework.apollo.portal.repository.RolePermissionRepository) PermissionRepository(com.ctrip.framework.apollo.portal.repository.PermissionRepository) CollectionUtils(org.springframework.util.CollectionUtils) Preconditions(com.google.common.base.Preconditions) RoleRepository(com.ctrip.framework.apollo.portal.repository.RoleRepository) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) UserRole(com.ctrip.framework.apollo.portal.entity.po.UserRole) UserInfo(com.ctrip.framework.apollo.portal.entity.bo.UserInfo)

Aggregations

UserRole (com.ctrip.framework.apollo.portal.entity.po.UserRole)6 Permission (com.ctrip.framework.apollo.portal.entity.po.Permission)3 Role (com.ctrip.framework.apollo.portal.entity.po.Role)3 RolePermission (com.ctrip.framework.apollo.portal.entity.po.RolePermission)3 Date (java.util.Date)3 Transactional (org.springframework.transaction.annotation.Transactional)3 ConsumerRoleRepository (com.ctrip.framework.apollo.openapi.repository.ConsumerRoleRepository)2 AbstractIntegrationTest (com.ctrip.framework.apollo.portal.AbstractIntegrationTest)2 PortalConfig (com.ctrip.framework.apollo.portal.component.config.PortalConfig)2 UserInfo (com.ctrip.framework.apollo.portal.entity.bo.UserInfo)2 PermissionRepository (com.ctrip.framework.apollo.portal.repository.PermissionRepository)2 RolePermissionRepository (com.ctrip.framework.apollo.portal.repository.RolePermissionRepository)2 RoleRepository (com.ctrip.framework.apollo.portal.repository.RoleRepository)2 UserRoleRepository (com.ctrip.framework.apollo.portal.repository.UserRoleRepository)2 RolePermissionService (com.ctrip.framework.apollo.portal.service.RolePermissionService)2 Preconditions (com.google.common.base.Preconditions)2 HashMultimap (com.google.common.collect.HashMultimap)2 Lists (com.google.common.collect.Lists)2 Multimap (com.google.common.collect.Multimap)2 Sets (com.google.common.collect.Sets)2