use of com.webank.wedatasphere.qualitis.entity.User 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.entity.User in project Qualitis by WeBankFinTech.
the class UserServiceImpl method autoAddUser.
@Override
@Transactional(rollbackFor = { Exception.class })
public void autoAddUser(String username) throws RoleNotFoundException {
User newUser = new User();
String password = username;
String passwordEncoded = Sha256Encoder.encode(password);
newUser.setUserName(username);
newUser.setPassword(passwordEncoded);
User savedUser = userDao.saveUser(newUser);
Role role = roleDao.findByRoleName("PROJECTOR");
if (role == null) {
throw new RoleNotFoundException();
}
UserRole userRole = new UserRole();
userRole.setId(UuidGenerator.generate());
userRole.setRole(role);
userRole.setUser(savedUser);
userRoleDao.saveUserRole(userRole);
LOGGER.info("Succeed to save user_role. uuid: {}, user_id: {}, role_id: {}", userRole.getId(), savedUser.getId(), role.getId());
}
use of com.webank.wedatasphere.qualitis.entity.User 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.entity.User in project Qualitis by WeBankFinTech.
the class UserServiceImpl method findAllUser.
@Override
public GeneralResponse<GetAllResponse<UserResponse>> findAllUser(PageRequest request) throws UnExpectedRequestException {
// Check Arguments
PageRequest.checkRequest(request);
int page = request.getPage();
int size = request.getSize();
List<User> users = userDao.findAllUser(page, size);
long total = userDao.countAll();
List<UserResponse> userResponses = new ArrayList<>();
for (User user : users) {
UserResponse tmp = new UserResponse(user);
userResponses.add(tmp);
}
GetAllResponse<UserResponse> response = new GetAllResponse<>();
response.setTotal(total);
response.setData(userResponses);
LOGGER.info("Succeed to find all users, response: {}, current_user: {}", response, HttpUtils.getUserName(httpServletRequest));
return new GeneralResponse<>("200", "{&FIND_ALL_USERS_SUCCESSFULLY}", response);
}
use of com.webank.wedatasphere.qualitis.entity.User 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