Search in sources :

Example 61 with UnExpectedRequestException

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);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole) Transactional(org.springframework.transaction.annotation.Transactional)

Example 62 with UnExpectedRequestException

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);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) Department(com.webank.wedatasphere.qualitis.entity.Department) User(com.webank.wedatasphere.qualitis.entity.User)

Example 63 with UnExpectedRequestException

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);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) User(com.webank.wedatasphere.qualitis.entity.User) Transactional(org.springframework.transaction.annotation.Transactional)

Example 64 with UnExpectedRequestException

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);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) User(com.webank.wedatasphere.qualitis.entity.User) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole) UserSpecPermission(com.webank.wedatasphere.qualitis.entity.UserSpecPermission) Transactional(org.springframework.transaction.annotation.Transactional)

Example 65 with UnExpectedRequestException

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);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) Department(com.webank.wedatasphere.qualitis.entity.Department) User(com.webank.wedatasphere.qualitis.entity.User) AddUserResponse(com.webank.wedatasphere.qualitis.response.user.AddUserResponse) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)150 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)97 ArrayList (java.util.ArrayList)56 Transactional (org.springframework.transaction.annotation.Transactional)54 Project (com.webank.wedatasphere.qualitis.project.entity.Project)33 User (com.webank.wedatasphere.qualitis.entity.User)32 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)32 RuleMetric (com.webank.wedatasphere.qualitis.entity.RuleMetric)25 Map (java.util.Map)24 ClusterInfo (com.webank.wedatasphere.qualitis.entity.ClusterInfo)22 List (java.util.List)22 PermissionDeniedRequestException (com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException)19 IOException (java.io.IOException)19 MetaDataAcquireFailedException (com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException)17 Date (java.util.Date)17 HashMap (java.util.HashMap)17 RuleDataSource (com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource)15 RuleGroup (com.webank.wedatasphere.qualitis.rule.entity.RuleGroup)15 Collectors (java.util.stream.Collectors)15 Template (com.webank.wedatasphere.qualitis.rule.entity.Template)14