Search in sources :

Example 81 with UnExpectedRequestException

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

the class UserSpecPermissionServiceImpl method addUserSpecPermission.

@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<UserSpecPermissionResponse> addUserSpecPermission(AddUserSpecPermissionRequest request) throws UnExpectedRequestException {
    // Check Arguments
    checkRequest(request);
    // Check existence of user permission
    long userId = request.getUserId();
    long permissionId = request.getPermissionId();
    User userInDb = userDao.findById(userId);
    if (userInDb == null) {
        throw new UnExpectedRequestException("user id {&DOES_NOT_EXIST}, request: " + request);
    }
    Permission permissionInDb = permissionDao.findById(permissionId);
    if (permissionInDb == null) {
        throw new UnExpectedRequestException("permission id {&DOES_NOT_EXIST}, request: " + request);
    }
    UserSpecPermission userSpecPermissionInDb = userSpecPermissionDao.findByUserAndPermission(userInDb, permissionInDb);
    if (userSpecPermissionInDb != null) {
        throw new UnExpectedRequestException("user id and permission id {&ALREADY_EXIST}, request: " + request);
    }
    // Save new user permissions
    UserSpecPermission newUserSpecPermission = new UserSpecPermission();
    newUserSpecPermission.setUser(userInDb);
    newUserSpecPermission.setPermission(permissionInDb);
    newUserSpecPermission.setId(UuidGenerator.generate());
    UserSpecPermission savedUserSpecPermission = userSpecPermissionDao.saveUserSpecPermission(newUserSpecPermission);
    UserSpecPermissionResponse response = new UserSpecPermissionResponse(savedUserSpecPermission);
    LOGGER.info("Succeed to add user_permission, response: {}, current_user: {}", response, HttpUtils.getUserName(httpServletRequest));
    return new GeneralResponse<>("200", "{&ADD_USER_SPEC_PERMISSION_SUCCESSFULLY}", response);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) User(com.webank.wedatasphere.qualitis.entity.User) UserSpecPermission(com.webank.wedatasphere.qualitis.entity.UserSpecPermission) Permission(com.webank.wedatasphere.qualitis.entity.Permission) UserSpecPermissionResponse(com.webank.wedatasphere.qualitis.response.UserSpecPermissionResponse) UserSpecPermission(com.webank.wedatasphere.qualitis.entity.UserSpecPermission) Transactional(org.springframework.transaction.annotation.Transactional)

Example 82 with UnExpectedRequestException

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

the class PermissionServiceImpl method modifyPermission.

@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> modifyPermission(ModifyPermissionRequest request) throws UnExpectedRequestException {
    // Check Arguments
    checkRequest(request);
    Long id = request.getPermissionId();
    String method = request.getMethod().trim();
    String url = request.getUrl().trim();
    Permission permissionInDb = permissionDao.findById(id);
    if (permissionInDb == null) {
        throw new UnExpectedRequestException("{&PERMISSION_ID_NOT_EXIST}, request: " + request);
    }
    LOGGER.info("Succeed to find permission, permissionId: {}, method: {}, url: {}, current_user: {}", permissionInDb.getId(), permissionInDb.getMethod(), permissionInDb.getUrl(), HttpUtils.getUserName(httpServletRequest));
    permissionInDb.setUrl(url);
    permissionInDb.setMethod(method);
    permissionDao.savePermission(permissionInDb);
    LOGGER.info("Succeed to modify permission, permissionId: {}, method: {}, url: {}, current_user: {}", id, method, url, HttpUtils.getUserName(httpServletRequest));
    return new GeneralResponse<>("200", "{&MODIFY_PERMISSION_SUCCESSFULLY}", null);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) UserSpecPermission(com.webank.wedatasphere.qualitis.entity.UserSpecPermission) Permission(com.webank.wedatasphere.qualitis.entity.Permission) RolePermission(com.webank.wedatasphere.qualitis.entity.RolePermission) Transactional(org.springframework.transaction.annotation.Transactional)

Example 83 with UnExpectedRequestException

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

the class ProxyUserServiceImpl method modifyProxyUser.

@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> modifyProxyUser(ModifyProxyUserRequest request) throws UnExpectedRequestException {
    // Check Arguments
    ModifyProxyUserRequest.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}");
    }
    String oldProxyUserName = proxyUserInDb.getProxyUserName();
    // Modify proxy user name
    proxyUserInDb.setProxyUserName(request.getProxyUserName());
    proxyUserRepository.save(proxyUserInDb);
    LOGGER.info("Succeed to modify proxy user. old proxy_user name: {}, new proxy_user name: {}", oldProxyUserName, proxyUserInDb.getProxyUserName());
    return new GeneralResponse<>("200", "{&SUCCEED_TO_MODIFY_PROXY_USER_NAME}", 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 84 with UnExpectedRequestException

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

the class RolePermissionServiceImpl method deleteRolePermission.

@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> deleteRolePermission(DeleteRolePermissionRequest request) throws UnExpectedRequestException {
    // Check Arguments
    checkRequest(request);
    // Find role permission by id
    String uuid = request.getUuid();
    RolePermission rolePermissionInDb = rolePermissionDao.findByUuid(uuid);
    if (rolePermissionInDb == null) {
        throw new UnExpectedRequestException("role permission id {&DOES_NOT_EXIST}, request: " + request);
    }
    // Delete role permission
    rolePermissionDao.deleteRolePermission(rolePermissionInDb);
    LOGGER.info("Succeed to delete role_permission, uuid: {}, role_id: {}, permission_id: {}, current_user: {}", uuid, rolePermissionInDb.getRole().getId(), rolePermissionInDb.getPermission().getId(), HttpUtils.getUserName(httpServletRequest));
    return new GeneralResponse<>("200", "{&DELETE_ROLE_PERMISSION_SUCCESSFULLY}", null);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) RolePermission(com.webank.wedatasphere.qualitis.entity.RolePermission) Transactional(org.springframework.transaction.annotation.Transactional)

Example 85 with UnExpectedRequestException

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

the class RolePermissionServiceImpl method addRolePermission.

@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<RolePermissionResponse> addRolePermission(AddRolePermissionRequest request) throws UnExpectedRequestException {
    // Check Arguments
    checkRequest(request);
    // Check existence of role and permission
    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 rolePermissionInDb = rolePermissionDao.findByRoleAndPermission(roleInDb, permissionInDb);
    if (rolePermissionInDb != null) {
        throw new UnExpectedRequestException("role and permission {&ALREADY_EXIST}, request: " + request);
    }
    // Save new role permission
    RolePermission newRolePermission = new RolePermission();
    newRolePermission.setPermission(permissionInDb);
    newRolePermission.setRole(roleInDb);
    newRolePermission.setId(UuidGenerator.generate());
    RolePermission savedRolePermission = rolePermissionDao.saveRolePermission(newRolePermission);
    RolePermissionResponse response = new RolePermissionResponse(savedRolePermission);
    LOGGER.info("Succeed to add role_permission, response: {}, current_user: {}", response, HttpUtils.getUserName(httpServletRequest));
    return new GeneralResponse<>("200", "{&ADD_ROLE_PERMISSION_SUCCESSFULLY}", response);
}
Also used : Role(com.webank.wedatasphere.qualitis.entity.Role) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) RolePermissionResponse(com.webank.wedatasphere.qualitis.response.RolePermissionResponse) 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)

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