use of com.webank.wedatasphere.qualitis.response.RolePermissionResponse in project Qualitis by WeBankFinTech.
the class RolePermissionServiceImpl method findAllRolePermission.
@Override
public GeneralResponse<GetAllResponse<RolePermissionResponse>> findAllRolePermission(PageRequest request) throws UnExpectedRequestException {
// Check Arguments
PageRequest.checkRequest(request);
int page = request.getPage();
int size = request.getSize();
List<RolePermission> rolePermissions = rolePermissionDao.findAllRolePermission(page, size);
long total = rolePermissionDao.countAll();
List<RolePermissionResponse> rolePermissionResponses = new ArrayList<>();
for (RolePermission rolePermission : rolePermissions) {
RolePermissionResponse tmp = new RolePermissionResponse(rolePermission);
rolePermissionResponses.add(tmp);
}
GetAllResponse<RolePermissionResponse> responses = new GetAllResponse<>();
responses.setData(rolePermissionResponses);
responses.setTotal(total);
LOGGER.info("Succeed to find all role_permission, response: {}, current_user: {}", responses, HttpUtils.getUserName(httpServletRequest));
return new GeneralResponse<>("200", "{&FIND_ALL_ROLE_PERMISSION_SUCCESSFULLY}", responses);
}
use of com.webank.wedatasphere.qualitis.response.RolePermissionResponse in project Qualitis by WeBankFinTech.
the class RolePermissionServiceImpl method addRolePermission.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<RolePermissionResponse> addRolePermission(AddRolePermissionRequest request) throws UnExpectedRequestException {
// Check Arguments
checkRequest(request);
// Check existence of role and permission
long roleId = request.getRoleId();
long permissionId = request.getPermissionId();
Role roleInDb = roleDao.findById(roleId);
if (roleInDb == null) {
throw new UnExpectedRequestException("role id {&DOES_NOT_EXIST}, request: " + request);
}
Permission permissionInDb = permissionDao.findById(permissionId);
if (permissionInDb == null) {
throw new UnExpectedRequestException("permission id {&DOES_NOT_EXIST}, request: " + request);
}
RolePermission rolePermissionInDb = rolePermissionDao.findByRoleAndPermission(roleInDb, permissionInDb);
if (rolePermissionInDb != null) {
throw new UnExpectedRequestException("role and permission {&ALREADY_EXIST}, request: " + request);
}
// Save new role permission
RolePermission newRolePermission = new RolePermission();
newRolePermission.setPermission(permissionInDb);
newRolePermission.setRole(roleInDb);
newRolePermission.setId(UuidGenerator.generate());
RolePermission savedRolePermission = rolePermissionDao.saveRolePermission(newRolePermission);
RolePermissionResponse response = new RolePermissionResponse(savedRolePermission);
LOGGER.info("Succeed to add role_permission, response: {}, current_user: {}", response, HttpUtils.getUserName(httpServletRequest));
return new GeneralResponse<>("200", "{&ADD_ROLE_PERMISSION_SUCCESSFULLY}", response);
}
Aggregations