use of com.ctrip.framework.apollo.portal.entity.po.Role in project apollo by ctripcorp.
the class RolePermissionServiceTest method testCreateRoleWithPermissionsWithRoleExisted.
@Test(expected = IllegalStateException.class)
@Sql(scripts = "/sql/permission/insert-test-roles.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void testCreateRoleWithPermissionsWithRoleExisted() throws Exception {
String someRoleName = "someRoleName";
Role role = assembleRole(someRoleName);
rolePermissionService.createRoleWithPermissions(role, null);
}
use of com.ctrip.framework.apollo.portal.entity.po.Role in project apollo by ctripcorp.
the class DefaultRolePermissionService method assignRoleToUsers.
/**
* Assign role to users
*
* @return the users assigned roles
*/
@Transactional
public Set<String> assignRoleToUsers(String roleName, Set<String> userIds, String operatorUserId) {
Role role = findRoleByRoleName(roleName);
Preconditions.checkState(role != null, "Role %s doesn't exist!", roleName);
List<UserRole> existedUserRoles = userRoleRepository.findByUserIdInAndRoleId(userIds, role.getId());
Set<String> existedUserIds = existedUserRoles.stream().map(UserRole::getUserId).collect(Collectors.toSet());
Set<String> toAssignUserIds = Sets.difference(userIds, existedUserIds);
Iterable<UserRole> toCreate = toAssignUserIds.stream().map(userId -> {
UserRole userRole = new UserRole();
userRole.setRoleId(role.getId());
userRole.setUserId(userId);
userRole.setDataChangeCreatedBy(operatorUserId);
userRole.setDataChangeLastModifiedBy(operatorUserId);
return userRole;
}).collect(Collectors.toList());
userRoleRepository.saveAll(toCreate);
return toAssignUserIds;
}
use of com.ctrip.framework.apollo.portal.entity.po.Role 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());
}
use of com.ctrip.framework.apollo.portal.entity.po.Role in project apollo by ctripcorp.
the class ConsumerServiceTest method createRole.
private Role createRole(long roleId, String roleName) {
Role role = new Role();
role.setId(roleId);
role.setRoleName(roleName);
return role;
}
use of com.ctrip.framework.apollo.portal.entity.po.Role in project apollo by ctripcorp.
the class AppControllerTest method generateRoleByIdAndRoleName.
private static Role generateRoleByIdAndRoleName(long id, String roleName) {
Role role = new Role();
role.setId(id);
role.setRoleName(roleName);
return role;
}
Aggregations