use of com.webank.wedatasphere.qualitis.response.RoleResponse in project Qualitis by WeBankFinTech.
the class RoleServiceImpl method addRole.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<RoleResponse> addRole(RoleAddRequest request) throws UnExpectedRequestException {
// Check Arguments
checkRequest(request);
// Check existence of role by role name
String roleName = request.getRoleName();
Role roleInDb = roleDao.findByRoleName(roleName);
if (roleInDb != null) {
throw new UnExpectedRequestException("role name {&ALREADY_EXIST}, request: " + request);
}
// Save new role
Role newRole = new Role();
newRole.setName(roleName);
if (request.getDepartmentName() != null) {
Department departmentInDb = departmentDao.findByName(request.getDepartmentName());
if (departmentInDb == null) {
throw new UnExpectedRequestException("department {&DOES_NOT_EXIST}, name: " + request.getDepartmentName());
}
LOGGER.info("Succeed to find department. Name: " + departmentInDb.getName());
newRole.setDepartment(departmentInDb);
}
Role savedRole = roleDao.saveRole(newRole);
RoleResponse roleResponse = new RoleResponse(savedRole);
LOGGER.info("Succeed to add role, role: {}, current_user: {}", roleResponse, HttpUtils.getUserName(httpServletRequest));
return new GeneralResponse<>("200", "{&CREATE_ROLE_SUCCESSFULLY}", roleResponse);
}
use of com.webank.wedatasphere.qualitis.response.RoleResponse in project Qualitis by WeBankFinTech.
the class RoleServiceImpl method getAllRole.
@Override
public GeneralResponse<GetAllResponse<RoleResponse>> getAllRole(PageRequest request) throws UnExpectedRequestException {
// Check Arguments
PageRequest.checkRequest(request);
int page = request.getPage();
int size = request.getSize();
List<Role> roles = roleDao.findAllRole(page, size);
long total = roleDao.countAll();
List<RoleResponse> roleResponses = new ArrayList<>();
for (Role role : roles) {
RoleResponse tmp = new RoleResponse(role);
roleResponses.add(tmp);
}
GetAllResponse<RoleResponse> responses = new GetAllResponse<>();
responses.setData(roleResponses);
responses.setTotal(total);
LOGGER.info("Succeed to find all roles, page: {}, size: {}, role: {}, current_user: {}", page, size, responses, HttpUtils.getUserName(httpServletRequest));
return new GeneralResponse<>("200", "{&FIND_ALL_ROLES_SUCCESSFULLY}", responses);
}
Aggregations