use of com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException 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);
}
use of com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException in project Qualitis by WeBankFinTech.
the class UserServiceImpl method modifyDepartment.
@Override
public GeneralResponse<?> modifyDepartment(ModifyDepartmentRequest request) throws UnExpectedRequestException {
// Check Arguments
checkRequest(request);
User userInDb = userDao.findById(request.getUserId());
if (null == userInDb) {
throw new UnExpectedRequestException("userId {&DOES_NOT_EXIST}");
}
// Find department by name.
Department departmentInDb = departmentDao.findByName(request.getDepartmentName());
if (null == departmentInDb) {
throw new UnExpectedRequestException("Department of " + request.getDepartmentName() + " {&DOES_NOT_EXIST}");
}
userInDb.setDepartment(departmentInDb);
// Save user
userDao.saveUser(userInDb);
LOGGER.info("Succeed to modify department, userId: {}, current_user: {}", userInDb.getId(), userInDb.getUserName());
return new GeneralResponse<>("200", "{&MODIFY_DEPARTMENT_SUCCESSFULLY}", null);
}
use of com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException in project Qualitis by WeBankFinTech.
the class UserServiceImpl method initPassword.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<String> initPassword(UserRequest request) throws UnExpectedRequestException {
// Check Arguments
checkRequest(request);
// Check existence of user by id
Long id = request.getUserId();
User userInDb = userDao.findById(id);
if (userInDb == null) {
throw new UnExpectedRequestException("user id {&DOES_NOT_EXIST}, request: " + request);
}
// Generate random password and save user
String password = RandomPasswordGenerator.generate(16);
String passwordEncoded = Sha256Encoder.encode(password);
userInDb.setPassword(passwordEncoded);
userDao.saveUser(userInDb);
LOGGER.info("Succeed to init password, user_id: {}, current_user: {}", id, HttpUtils.getUserName(httpServletRequest));
return new GeneralResponse<>("200", "{&INIT_PASSWORD_SUCCESSFULLY}", password);
}
use of com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException in project Qualitis by WeBankFinTech.
the class UserServiceImpl method deleteUser.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> deleteUser(UserRequest request) throws UnExpectedRequestException {
// Check Arguments
checkRequest(request);
// Check existence of user by id
Long userId = request.getUserId();
User userInDb = userDao.findById(userId);
if (userInDb == null) {
throw new UnExpectedRequestException("user id {&DOES_NOT_EXIST}, request: " + request);
}
// Check personal template.
checkTemplate(userInDb);
List<UserRole> userRolesInDb = userRoleDao.findByUser(userInDb);
if (null != userRolesInDb && !userRolesInDb.isEmpty()) {
throw new UnExpectedRequestException("{&DELETE_ERROR_USER_ROLE_HAS_FOREIGN_KEY}");
}
List<UserSpecPermission> userSpecPermissionsInDb = userSpecPermissionDao.findByUser(userInDb);
if (null != userSpecPermissionsInDb && !userSpecPermissionsInDb.isEmpty()) {
throw new UnExpectedRequestException("{&DELETE_ERROR_USER_SPEC_PERMISSION_HAS_FOREIGN_KEY}");
}
// Delete user
userDao.deleteUser(userInDb);
LOGGER.info("Succeed to delete user, userId: {}, username: {}, current_user: {}", userInDb.getId(), userInDb.getUserName(), HttpUtils.getUserName(httpServletRequest));
return new GeneralResponse<>("200", "{&DELETE_USER_SUCCESSFULLY}", null);
}
use of com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException in project Qualitis by WeBankFinTech.
the class UserServiceImpl method addUser.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<AddUserResponse> addUser(UserAddRequest request) throws UnExpectedRequestException {
// Check Arguments
checkRequest(request);
// Check existence of user by username
String username = request.getUsername();
User userInDb = userDao.findByUsername(username);
if (userInDb != null) {
throw new UnExpectedRequestException("username: " + username + " {&ALREADY_EXIST}");
}
// Generate random password and save user
User newUser = new User();
String password = RandomPasswordGenerator.generate(16);
String passwordEncoded = Sha256Encoder.encode(password);
newUser.setUserName(username);
newUser.setPassword(passwordEncoded);
newUser.setChineseName(request.getChineseName());
// Find department by department name
Department departmentInDb = departmentDao.findById(request.getDepartmentId());
if (null == departmentInDb) {
throw new UnExpectedRequestException("Department ID of " + request.getDepartmentId() + " {&DOES_NOT_EXIST}");
}
newUser.setDepartment(departmentInDb);
User savedUser = userDao.saveUser(newUser);
AddUserResponse addUserResponse = new AddUserResponse(savedUser, password);
LOGGER.info("Succeed to create user, response: {}, current_user: {}", addUserResponse, HttpUtils.getUserName(httpServletRequest));
return new GeneralResponse<>("200", "{&CREATE_USER_SUCCESSFULLY}", addUserResponse);
}
Aggregations