use of com.webank.wedatasphere.qualitis.response.GeneralResponse in project Qualitis by WeBankFinTech.
the class RolePermissionServiceImpl method modifyRolePermission.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> modifyRolePermission(ModifyRolePermissionRequest request) throws UnExpectedRequestException {
// Check Arguments
checkRequest(request);
// Check existence of role permission
String uuid = request.getUuid();
RolePermission rolePermissionInDb = rolePermissionDao.findByUuid(uuid);
if (rolePermissionInDb == null) {
throw new UnExpectedRequestException("role permission id {&DOES_NOT_EXIST}, request: " + request);
}
LOGGER.info("Succeed to find role_permission, uuid: {}, role_id: {}, permission_id: {}, current_user: {}", uuid, rolePermissionInDb.getRole().getId(), rolePermissionInDb.getPermission().getId(), HttpUtils.getUserName(httpServletRequest));
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 roleIdAndPermissionIdInDb = rolePermissionDao.findByRoleAndPermission(roleInDb, permissionInDb);
if (roleIdAndPermissionIdInDb != null) {
throw new UnExpectedRequestException("role and permission {&ALREADY_EXIST}, request: " + request);
}
// Save role permission
rolePermissionInDb.setRole(roleInDb);
rolePermissionInDb.setPermission(permissionInDb);
RolePermission savedRolePermission = rolePermissionDao.saveRolePermission(rolePermissionInDb);
LOGGER.info("Succeed to modify role_permission, uuid: {}, role_id: {}, permission_id: {}, current_user: {}", uuid, savedRolePermission.getRole().getId(), savedRolePermission.getPermission().getId(), HttpUtils.getUserName(httpServletRequest));
return new GeneralResponse<>("200", "{&MODIFY_ROLE_PERMISSION_SUCCESSFULLY}", null);
}
use of com.webank.wedatasphere.qualitis.response.GeneralResponse in project Qualitis by WeBankFinTech.
the class RoleServiceImpl method getRoleByUser.
@Override
public GeneralResponse<?> getRoleByUser() {
Long userId;
String username = null;
// Get current userId
userId = HttpUtils.getUserId(httpServletRequest);
username = HttpUtils.getUserName(httpServletRequest);
User userInDb = userDao.findById(userId);
// Find user role by user
List<UserRole> userRoles = userRoleDao.findByUser(userInDb);
// Get all roles of user
List<String> roleNames = userRoles.stream().map(userRole -> userRole.getRole().getName()).collect(Collectors.toList());
UserAndRoleResponse response = new UserAndRoleResponse();
response.setRoles(roleNames);
response.setUsername(username);
HttpSession session = httpServletRequest.getSession();
response.setLoginRandom((Integer) session.getAttribute("loginRandom"));
LOGGER.info("Succeed to get role of user, {} role: {}, current_user: {}", username, roleNames.toString(), username);
return new GeneralResponse<>("200", "{&GET_ROLE_SUCCESSFULLY}", response);
}
use of com.webank.wedatasphere.qualitis.response.GeneralResponse in project Qualitis by WeBankFinTech.
the class TransferUserServiceImpl method transferUser.
@Override
public GeneralResponse<?> transferUser(String user) throws UnExpectedRequestException {
User userInDb = userDao.findByUsername(user);
if (userInDb == null) {
throw new UnExpectedRequestException("ProxyUser: " + user + " {&DOES_NOT_EXIST}");
}
Map<String, Object> userMap = ImmutableMap.of("userId", userInDb.getId(), "username", userInDb.getUserName());
HttpSession httpSession = httpServletRequest.getSession();
httpSession.setAttribute("proxyUser", userMap);
return new GeneralResponse<>("200", "{&SUCCEED_TO_TRANSFER_TO_PROXYUSER}", null);
}
use of com.webank.wedatasphere.qualitis.response.GeneralResponse in project Qualitis by WeBankFinTech.
the class UserProxyUserServiceImpl method deleteUserProxyUser.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> deleteUserProxyUser(DeleteUserProxyUserRequest request) throws UnExpectedRequestException {
// Check Arguments
DeleteUserProxyUserRequest.checkRequest(request);
// Find user proxy user by id
UserProxyUser userProxyUserInDb = userProxyUserRepository.findById(request.getUserProxyUserId()).orElse(null);
if (userProxyUserInDb == null) {
throw new UnExpectedRequestException("User proxy user id {&DOES_NOT_EXIST}, request: " + request);
}
userProxyUserRepository.delete(userProxyUserInDb);
LOGGER.info("Succeed to delete user proxy user. user_proxy_user_id: {}", request.getUserProxyUserId());
return new GeneralResponse<>("200", "{&SUCCEED_TO_DELETE_USER_PROXY_USER}", null);
}
use of com.webank.wedatasphere.qualitis.response.GeneralResponse in project Qualitis by WeBankFinTech.
the class UserRoleServiceImpl method deleteUserRole.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> deleteUserRole(DeleteUserRoleRequest request) throws UnExpectedRequestException {
// Check Arguments
checkRequest(request);
// Check existence of user role
String uuid = request.getUuid();
UserRole userRoleInDb = userRoleDao.findByUuid(uuid);
if (userRoleInDb == null) {
throw new UnExpectedRequestException("user role id {&DOES_NOT_EXIST}, request: " + request);
}
// Delete user role
userRoleDao.deleteUserRole(userRoleInDb);
LOGGER.info("Succeed to delete user_role. uuid: {}, current_user: {}", request.getUuid(), HttpUtils.getUserName(httpServletRequest));
return new GeneralResponse<>("200", "{&DELETE_USER_ROLE_SUCCESSFULLY}", null);
}
Aggregations