Search in sources :

Example 56 with UnExpectedRequestException

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

Example 57 with UnExpectedRequestException

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

Example 58 with UnExpectedRequestException

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

Example 59 with UnExpectedRequestException

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

Example 60 with UnExpectedRequestException

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