use of com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException in project Qualitis by WeBankFinTech.
the class ProxyUserServiceImpl method addProxyUser.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> addProxyUser(AddProxyUserRequest request) throws UnExpectedRequestException {
// Check Arguments
AddProxyUserRequest.checkRequest(request);
// Check existence of proxy user
ProxyUser proxyUserInDb = proxyUserRepository.findByProxyUserName(request.getProxyUserName());
if (proxyUserInDb != null) {
throw new UnExpectedRequestException("ProxyUser name: [" + request.getProxyUserName() + "] {&ALREADY_EXIST}");
}
// Save proxy user
ProxyUser proxyUser = new ProxyUser();
proxyUser.setProxyUserName(request.getProxyUserName());
ProxyUser savedProxyUser = proxyUserRepository.save(proxyUser);
LOGGER.info("Succeed to save proxyUser. proxy_user: {}", savedProxyUser.getProxyUserName());
AddProxyUserResponse response = new AddProxyUserResponse(savedProxyUser);
return new GeneralResponse<>("200", "{&SUCCEED_TO_SAVE_PROXYUSER}", response);
}
use of com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException in project Qualitis by WeBankFinTech.
the class ProxyUserServiceImpl method deleteProxyUser.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> deleteProxyUser(DeleteProxyUserRequest request) throws UnExpectedRequestException {
// Check Arguments
DeleteProxyUserRequest.checkRequest(request);
// Check existence of proxy user
ProxyUser proxyUserInDb = proxyUserRepository.findById(request.getProxyUserId()).orElse(null);
if (proxyUserInDb == null) {
throw new UnExpectedRequestException("ProxyUser id: " + request.getProxyUserId() + " {&DOES_NOT_EXIST}");
}
proxyUserRepository.delete(proxyUserInDb);
LOGGER.info("Succeed to delete proxy user. proxy_user: {}", proxyUserInDb.getProxyUserName());
return new GeneralResponse<>("200", "{&SUCCEED_TO_DELETE_PROXY_USER}", null);
}
use of com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException 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.exception.UnExpectedRequestException 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.exception.UnExpectedRequestException 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);
}
Aggregations