Search in sources :

Example 76 with UnExpectedRequestException

use of com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException in project Qualitis by WeBankFinTech.

the class UserProxyUserServiceImpl method getAllUserProxyUserByProxyUserName.

@Override
public GeneralResponse<?> getAllUserProxyUserByProxyUserName(String proxyUserName, PageRequest request) throws UnExpectedRequestException {
    // Check Arguments
    PageRequest.checkRequest(request);
    // Check existence of proxy user
    ProxyUser proxyUserInDb = proxyUserRepository.findByProxyUserName(proxyUserName);
    if (proxyUserInDb == null) {
        throw new UnExpectedRequestException("ProxyUser name {&DOES_NOT_EXIST}, request: " + request);
    }
    // Find user proxy user by proxy user
    int page = request.getPage();
    int size = request.getSize();
    Sort sort = new Sort(Sort.Direction.ASC, "id");
    Pageable pageable = org.springframework.data.domain.PageRequest.of(page, size, sort);
    List<UserProxyUser> userProxyUsers = userProxyUserRepository.findByProxyUser(proxyUserInDb, pageable);
    long total = userProxyUserRepository.countByProxyUser(proxyUserInDb);
    List<AddUserProxyUserResponse> userProxyUserResponses = new ArrayList<>();
    for (UserProxyUser userProxyUser : userProxyUsers) {
        AddUserProxyUserResponse tmp = new AddUserProxyUserResponse(userProxyUser);
        userProxyUserResponses.add(tmp);
    }
    GetAllResponse<AddUserProxyUserResponse> response = new GetAllResponse<>();
    response.setTotal(total);
    response.setData(userProxyUserResponses);
    LOGGER.info("Succeed to find all user proxy users by proxy user name, response: {}", response);
    return new GeneralResponse<>("200", "{&SUCCEED_TO_FIND_ALL_PROXY_USERS_BY_PROXY_USER_NAME}", response);
}
Also used : UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) ArrayList(java.util.ArrayList) ProxyUser(com.webank.wedatasphere.qualitis.entity.ProxyUser) UserProxyUser(com.webank.wedatasphere.qualitis.entity.UserProxyUser) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) AddUserProxyUserResponse(com.webank.wedatasphere.qualitis.response.AddUserProxyUserResponse) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) GetAllResponse(com.webank.wedatasphere.qualitis.response.GetAllResponse) UserProxyUser(com.webank.wedatasphere.qualitis.entity.UserProxyUser)

Example 77 with UnExpectedRequestException

use of com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException in project Qualitis by WeBankFinTech.

the class UserProxyUserServiceImpl method addUserProxyUser.

@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> addUserProxyUser(AddUserProxyUserRequest request) throws UnExpectedRequestException {
    // Check Arguments
    AddUserProxyUserRequest.checkRequest(request);
    // Find user and proxy user by username
    User userInDb = userDao.findByUsername(request.getUsername());
    if (userInDb == null) {
        throw new UnExpectedRequestException("Username {&DOES_NOT_EXIST}, request: " + request);
    }
    ProxyUser proxyUserInDb = proxyUserRepository.findByProxyUserName(request.getProxyUserName());
    if (proxyUserInDb == null) {
        throw new UnExpectedRequestException("ProxyUser {&DOES_NOT_EXIST}, request: " + request);
    }
    UserProxyUser userProxyUserInDb = userProxyUserRepository.findByUserAndProxyUser(userInDb, proxyUserInDb);
    if (userProxyUserInDb != null) {
        throw new UnExpectedRequestException("User proxy user {&ALREADY_EXIST}, request: " + request);
    }
    UserProxyUser newUserProxyUser = new UserProxyUser();
    newUserProxyUser.setProxyUser(proxyUserInDb);
    newUserProxyUser.setUser(userInDb);
    UserProxyUser savedUserProxyUser = userProxyUserRepository.save(newUserProxyUser);
    LOGGER.info("Succeed to save user proxy user. user_proxy_user_id: {}", savedUserProxyUser.getId());
    AddUserProxyUserResponse response = new AddUserProxyUserResponse(savedUserProxyUser);
    return new GeneralResponse<>("200", "{&SUCCEED_TO_SAVE_USER_PROXY_USER}", response);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) AddUserProxyUserResponse(com.webank.wedatasphere.qualitis.response.AddUserProxyUserResponse) ProxyUser(com.webank.wedatasphere.qualitis.entity.ProxyUser) UserProxyUser(com.webank.wedatasphere.qualitis.entity.UserProxyUser) User(com.webank.wedatasphere.qualitis.entity.User) ProxyUser(com.webank.wedatasphere.qualitis.entity.ProxyUser) UserProxyUser(com.webank.wedatasphere.qualitis.entity.UserProxyUser) UserProxyUser(com.webank.wedatasphere.qualitis.entity.UserProxyUser) Transactional(org.springframework.transaction.annotation.Transactional)

Example 78 with UnExpectedRequestException

use of com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException in project Qualitis by WeBankFinTech.

the class UserRoleServiceImpl method modifyUserRole.

@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> modifyUserRole(ModifyUserRoleRequest request) throws UnExpectedRequestException {
    // Check Arguments
    checkRequest(request);
    // Find user role by id
    String uuid = request.getUuid();
    UserRole userRoleInDb = userRoleDao.findByUuid(uuid);
    if (userRoleInDb == null) {
        throw new UnExpectedRequestException("user role id {&DOES_NOT_EXIST}, request: " + request);
    }
    LOGGER.info("Succeed to find user_role, uuid: {}, user_id: {}, role_id: {}, current_user: {}", uuid, userRoleInDb.getUser().getId(), userRoleInDb.getRole().getId(), HttpUtils.getUserName(httpServletRequest));
    Long userId = request.getUserId();
    Long roleId = request.getRoleId();
    User userInDb = userDao.findById(userId);
    if (userInDb == null) {
        throw new UnExpectedRequestException("userId {&DOES_NOT_EXIST}, request: " + request);
    }
    Role roleInDb = roleDao.findById(roleId);
    if (roleInDb == null) {
        throw new UnExpectedRequestException("roleId {&DOES_NOT_EXIST}, request: " + request);
    }
    UserRole userIdAndRoleIdInDb = userRoleDao.findByUserAndRole(userInDb, roleInDb);
    if (userIdAndRoleIdInDb != null) {
        throw new UnExpectedRequestException("userId and roleId {&ALREADY_EXIST}, request: " + request);
    }
    userRoleInDb.setUser(userInDb);
    userRoleInDb.setRole(roleInDb);
    UserRole savedUserRole = userRoleDao.saveUserRole(userRoleInDb);
    LOGGER.info("Succeed to modify user_role, uuid: {}, user_id: {}, role_id: {}, current_user: {}", uuid, savedUserRole.getUser().getId(), savedUserRole.getRole().getId(), HttpUtils.getUserName(httpServletRequest));
    return new GeneralResponse<>("200", "{&MODIFY_USER_ROLE_SUCCESSFULLY}", null);
}
Also used : Role(com.webank.wedatasphere.qualitis.entity.Role) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole) 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) Transactional(org.springframework.transaction.annotation.Transactional)

Example 79 with UnExpectedRequestException

use of com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException in project Qualitis by WeBankFinTech.

the class UserRoleServiceImpl method addUserRole.

@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<UserRoleResponse> addUserRole(AddUserRoleRequest request) throws UnExpectedRequestException {
    // Check Arguments
    checkRequest(request);
    // Check existence of user, role and user role
    Long userId = request.getUserId();
    Long roleId = request.getRoleId();
    User userInDb = userDao.findById(userId);
    if (userInDb == null) {
        throw new UnExpectedRequestException("userId {&DOES_NOT_EXIST}, request: " + request);
    }
    Role roleInDb = roleDao.findById(roleId);
    if (roleInDb == null) {
        throw new UnExpectedRequestException("roleId {&DOES_NOT_EXIST}, request: " + request);
    }
    UserRole userRoleInDb = userRoleDao.findByUserAndRole(userInDb, roleInDb);
    if (userRoleInDb != null) {
        throw new UnExpectedRequestException("userId and roleId {&ALREADY_EXIST}, request: " + request);
    }
    // Save user role
    UserRole newUserRole = new UserRole();
    newUserRole.setRole(roleInDb);
    newUserRole.setUser(userInDb);
    newUserRole.setId(UuidGenerator.generate());
    UserRole savedUserRole = userRoleDao.saveUserRole(newUserRole);
    UserRoleResponse response = new UserRoleResponse(savedUserRole);
    LOGGER.info("Succeed to add user_role: response: {}, current_user: {}", response, HttpUtils.getUserName(httpServletRequest));
    return new GeneralResponse<>("200", "{&ADD_USER_ROLE_SUCCESSFULLY}", response);
}
Also used : Role(com.webank.wedatasphere.qualitis.entity.Role) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) User(com.webank.wedatasphere.qualitis.entity.User) UserRoleResponse(com.webank.wedatasphere.qualitis.response.UserRoleResponse) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole) Transactional(org.springframework.transaction.annotation.Transactional)

Example 80 with UnExpectedRequestException

use of com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException in project Qualitis by WeBankFinTech.

the class UserServiceImpl method modifyPassword.

@Override
public GeneralResponse<?> modifyPassword(ModifyPasswordRequest request) throws UnExpectedRequestException {
    // Check Arguments
    checkRequest(request);
    // Modify if old password is correct
    Long userId = HttpUtils.getUserId(httpServletRequest);
    User userInDb = userDao.findById(userId);
    if (null == userInDb) {
        throw new UnExpectedRequestException("userId {&DOES_NOT_EXIST}");
    }
    String passwordInDb = userInDb.getPassword();
    if (!passwordInDb.equals(request.getOldPassword())) {
        throw new UnExpectedRequestException("{&OLD_PASSWORD_NOT_CORRECT}");
    }
    userInDb.setPassword(request.getNewPassword());
    // Save user
    userDao.saveUser(userInDb);
    LOGGER.info("Succeed to modify password, userId: {}, current_user: {}", userId, HttpUtils.getUserName(httpServletRequest));
    return new GeneralResponse<>("200", "{&MODIFY_PASSWORD_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)

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