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);
}
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());
}
}
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;
}
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;
}
Aggregations