Search in sources :

Example 1 with RoleDto

use of com.albedo.java.modules.sys.domain.dto.RoleDto in project albedo by somowhere.

the class RoleResourceIntTest method updateRole.

@Test
@Transactional(rollbackFor = Exception.class)
public void updateRole() throws Exception {
    // Initialize the database
    roleService.saveOrUpdate(roleDto);
    int databaseSizeBeforeUpdate = roleService.list().size();
    // Update the role
    RoleDo updatedRoleDo = roleService.getById(roleDto.getId());
    RoleDto managedRoleVM = new RoleDto();
    managedRoleVM.setName(UPDATED_NAME);
    managedRoleVM.setLevel(UPDATED_LEVEL);
    managedRoleVM.setDataScope(UPDATED_DATASCOPE);
    managedRoleVM.setDescription(UPDATED_DESCRIPTION);
    managedRoleVM.setMenuIdList(Lists.newArrayList(anotherRole.getMenuIdList().get(0)));
    managedRoleVM.setDeptIdList(Lists.newArrayList(anotherRole.getDeptIdList().get(0)));
    managedRoleVM.setId(updatedRoleDo.getId());
    restRoleMockMvc.perform(post(DEFAULT_API_URL).contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(managedRoleVM))).andExpect(status().isOk()).andExpect(jsonPath("$.code").value(CommonConstants.SUCCESS));
    // Validate the Role in the database
    List<RoleDo> roleDoList = roleService.list();
    assertThat(roleDoList).hasSize(databaseSizeBeforeUpdate);
    RoleDo testRoleDo = roleService.getById(updatedRoleDo.getId());
    List<RoleMenuDo> listRoleMenuDoEntities = roleMenuService.list(Wrappers.<RoleMenuDo>query().lambda().eq(RoleMenuDo::getRoleId, testRoleDo.getId()));
    assertThat(listRoleMenuDoEntities.size()).isEqualTo(1);
    assertThat(listRoleMenuDoEntities.get(0).getMenuId()).isEqualTo(anotherRole.getMenuIdList().get(0));
    List<RoleDeptDo> listRoleDeptDo = roleDeptService.list(Wrappers.<RoleDeptDo>query().lambda().eq(RoleDeptDo::getRoleId, testRoleDo.getId()));
    assertThat(listRoleDeptDo.size()).isEqualTo(1);
    assertThat(listRoleDeptDo.get(0).getDeptId()).isEqualTo(anotherRole.getDeptIdList().get(0));
    assertThat(testRoleDo.getName()).isEqualTo(UPDATED_NAME);
    // assertThat(testRole.getParentIds()).contains(UPDATED_PARENT_ID);
    assertThat(testRoleDo.getLevel()).isEqualTo(UPDATED_LEVEL);
    assertThat(testRoleDo.getDescription()).isEqualTo(UPDATED_DESCRIPTION);
    assertThat(testRoleDo.getDelFlag()).isEqualTo(RoleDo.FLAG_NORMAL);
}
Also used : RoleDto(com.albedo.java.modules.sys.domain.dto.RoleDto) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with RoleDto

use of com.albedo.java.modules.sys.domain.dto.RoleDto in project albedo by somowhere.

the class RoleServiceImpl method saveOrUpdate.

@Override
@Transactional(rollbackFor = Exception.class)
public void saveOrUpdate(RoleDto roleDto) {
    boolean add = ObjectUtil.isEmpty(roleDto.getId());
    super.saveOrUpdate(roleDto);
    if (CollUtil.isNotEmpty(roleDto.getMenuIdList())) {
        roleMenuService.remove(Wrappers.<RoleMenuDo>query().lambda().eq(RoleMenuDo::getRoleId, roleDto.getId()));
        List<RoleMenuDo> roleMenuDoList = roleDto.getMenuIdList().stream().map(menuId -> {
            RoleMenuDo roleMenuDo = new RoleMenuDo();
            roleMenuDo.setRoleId(roleDto.getId());
            roleMenuDo.setMenuId(menuId);
            return roleMenuDo;
        }).collect(Collectors.toList());
        roleMenuService.saveBatch(roleMenuDoList);
    }
    if (CollUtil.isNotEmpty(roleDto.getDeptIdList())) {
        roleDeptService.remove(Wrappers.<RoleDeptDo>query().lambda().eq(RoleDeptDo::getRoleId, roleDto.getId()));
        List<RoleDeptDo> roleDeptDoList = roleDto.getDeptIdList().stream().map(deptId -> {
            RoleDeptDo roleDeptDo = new RoleDeptDo();
            roleDeptDo.setRoleId(roleDto.getId());
            roleDeptDo.setDeptId(deptId);
            return roleDeptDo;
        }).collect(Collectors.toList());
        roleDeptService.saveBatch(roleDeptDoList);
    }
    // 清空userinfo
    if (!add) {
        SysCacheUtil.delRoleCaches(roleDto.getId());
    }
}
Also used : UserRepository(com.albedo.java.modules.sys.repository.UserRepository) ObjectUtil(com.albedo.java.common.core.util.ObjectUtil) ArgumentAssert(com.albedo.java.common.core.util.ArgumentAssert) CollUtil(com.albedo.java.common.core.util.CollUtil) RoleDo(com.albedo.java.modules.sys.domain.RoleDo) RoleDto(com.albedo.java.modules.sys.domain.dto.RoleDto) RoleCacheKeyBuilder(com.albedo.java.modules.sys.cache.RoleCacheKeyBuilder) SysCacheUtil(com.albedo.java.modules.sys.util.SysCacheUtil) Service(org.springframework.stereotype.Service) UserDo(com.albedo.java.modules.sys.domain.UserDo) RoleDeptDo(com.albedo.java.modules.sys.domain.RoleDeptDo) RoleRepository(com.albedo.java.modules.sys.repository.RoleRepository) CacheKey(com.albedo.java.common.core.cache.model.CacheKey) Wrappers(com.baomidou.mybatisplus.core.toolkit.Wrappers) RoleMenuDo(com.albedo.java.modules.sys.domain.RoleMenuDo) RoleDeptService(com.albedo.java.modules.sys.service.RoleDeptService) Set(java.util.Set) CommonConstants(com.albedo.java.common.core.constant.CommonConstants) CacheKeyBuilder(com.albedo.java.common.core.cache.model.CacheKeyBuilder) Collectors(java.util.stream.Collectors) SecurityUtil(com.albedo.java.common.security.util.SecurityUtil) RoleMenuService(com.albedo.java.modules.sys.service.RoleMenuService) Serializable(java.io.Serializable) List(java.util.List) AbstractDataCacheServiceImpl(com.albedo.java.plugins.database.mybatis.service.impl.AbstractDataCacheServiceImpl) BizException(com.albedo.java.common.core.exception.BizException) AllArgsConstructor(lombok.AllArgsConstructor) RoleService(com.albedo.java.modules.sys.service.RoleService) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) RoleDeptDo(com.albedo.java.modules.sys.domain.RoleDeptDo) RoleMenuDo(com.albedo.java.modules.sys.domain.RoleMenuDo) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with RoleDto

use of com.albedo.java.modules.sys.domain.dto.RoleDto in project albedo by somowhere.

the class RoleServiceImpl method getOneDto.

@Override
public RoleDto getOneDto(Serializable id) {
    RoleDto oneVo = super.getOneDto(id);
    oneVo.setMenuIdList(roleMenuService.list(Wrappers.<RoleMenuDo>query().lambda().eq(RoleMenuDo::getRoleId, id)).stream().map(RoleMenuDo::getMenuId).collect(Collectors.toList()));
    oneVo.setDeptIdList(findDeptIdsByRoleId(id));
    return oneVo;
}
Also used : RoleDto(com.albedo.java.modules.sys.domain.dto.RoleDto) RoleMenuDo(com.albedo.java.modules.sys.domain.RoleMenuDo)

Example 4 with RoleDto

use of com.albedo.java.modules.sys.domain.dto.RoleDto in project albedo by somowhere.

the class RoleResourceIntTest method createEntity.

/**
 * Create a Role.
 * <p>
 * This is a static method, as tests for other entities might also need it, if they
 * test an domain which has a required relationship to the Role domain.
 */
public RoleDto createEntity() {
    RoleDto roleDto = new RoleDto();
    roleDto.setName(DEFAULT_NAME);
    roleDto.setDataScope(DEFAULT_DATASCOPE);
    roleDto.setLevel(DEFAULT_LEVEL);
    roleDto.setDescription(DEFAULT_DESCRIPTION);
    return roleDto;
}
Also used : RoleDto(com.albedo.java.modules.sys.domain.dto.RoleDto)

Aggregations

RoleDto (com.albedo.java.modules.sys.domain.dto.RoleDto)4 RoleMenuDo (com.albedo.java.modules.sys.domain.RoleMenuDo)2 Transactional (org.springframework.transaction.annotation.Transactional)2 CacheKey (com.albedo.java.common.core.cache.model.CacheKey)1 CacheKeyBuilder (com.albedo.java.common.core.cache.model.CacheKeyBuilder)1 CommonConstants (com.albedo.java.common.core.constant.CommonConstants)1 BizException (com.albedo.java.common.core.exception.BizException)1 ArgumentAssert (com.albedo.java.common.core.util.ArgumentAssert)1 CollUtil (com.albedo.java.common.core.util.CollUtil)1 ObjectUtil (com.albedo.java.common.core.util.ObjectUtil)1 SecurityUtil (com.albedo.java.common.security.util.SecurityUtil)1 RoleCacheKeyBuilder (com.albedo.java.modules.sys.cache.RoleCacheKeyBuilder)1 RoleDeptDo (com.albedo.java.modules.sys.domain.RoleDeptDo)1 RoleDo (com.albedo.java.modules.sys.domain.RoleDo)1 UserDo (com.albedo.java.modules.sys.domain.UserDo)1 RoleRepository (com.albedo.java.modules.sys.repository.RoleRepository)1 UserRepository (com.albedo.java.modules.sys.repository.UserRepository)1 RoleDeptService (com.albedo.java.modules.sys.service.RoleDeptService)1 RoleMenuService (com.albedo.java.modules.sys.service.RoleMenuService)1 RoleService (com.albedo.java.modules.sys.service.RoleService)1