@Transactional fun createRoleWithPermissions(role: Role, permissionIds: Set<Long?>?): Role? { val current: Role = findRoleByRoleName(role.getRoleName()) Preconditions.checkState(current == null, "Role %s already exists!", role.getRoleName()) val createdRole: Role = roleRepository.save(role) if (!CollectionUtils.isEmpty(permissionIds)) { val rolePermissions: Iterable<RolePermission> = FluentIterable.from(permissionIds).transform(null) rolePermissionRepository.save(rolePermissions) } return createdRole }
Create role with permissions , note that role name should be unique