Search in sources :

Example 86 with GeneralResponse

use of com.webank.wedatasphere.qualitis.response.GeneralResponse in project Qualitis by WeBankFinTech.

the class UserSpecPermissionServiceImpl method findAllUserSpecPermission.

@Override
public GeneralResponse<GetAllResponse<UserSpecPermissionResponse>> findAllUserSpecPermission(PageRequest request) throws UnExpectedRequestException {
    // Check Arguments
    PageRequest.checkRequest(request);
    int page = request.getPage();
    int size = request.getSize();
    List<UserSpecPermission> userSpecPermissions = userSpecPermissionDao.findAllUserSpecPermission(page, size);
    long total = userSpecPermissionDao.countAll();
    List<UserSpecPermissionResponse> userSpecPermissionResponses = new ArrayList<>();
    for (UserSpecPermission userSpecPermission : userSpecPermissions) {
        UserSpecPermissionResponse tmp = new UserSpecPermissionResponse(userSpecPermission);
        userSpecPermissionResponses.add(tmp);
    }
    GetAllResponse<UserSpecPermissionResponse> responses = new GetAllResponse<>();
    responses.setTotal(total);
    responses.setData(userSpecPermissionResponses);
    LOGGER.info("Succeed to find user_permission. page: {}, size: {}, response: {}, current_user: {}", page, size, responses, HttpUtils.getUserName(httpServletRequest));
    return new GeneralResponse<>("200", "{&FIND_USER_SPEC_PERMISSION_SUCCESSFULLY}", responses);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UserSpecPermissionResponse(com.webank.wedatasphere.qualitis.response.UserSpecPermissionResponse) ArrayList(java.util.ArrayList) GetAllResponse(com.webank.wedatasphere.qualitis.response.GetAllResponse) UserSpecPermission(com.webank.wedatasphere.qualitis.entity.UserSpecPermission)

Example 87 with GeneralResponse

use of com.webank.wedatasphere.qualitis.response.GeneralResponse 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 88 with GeneralResponse

use of com.webank.wedatasphere.qualitis.response.GeneralResponse 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 89 with GeneralResponse

use of com.webank.wedatasphere.qualitis.response.GeneralResponse in project Qualitis by WeBankFinTech.

the class PermissionServiceImpl method getAllPermission.

@Override
public GeneralResponse<GetAllResponse<PermissionResponse>> getAllPermission(PageRequest request) throws UnExpectedRequestException {
    // Check Arguments
    PageRequest.checkRequest(request);
    int page = request.getPage();
    int size = request.getSize();
    List<Permission> permissions = permissionDao.findAllPermission(page, size);
    long total = permissionDao.countAll();
    GetAllResponse<PermissionResponse> getAllPermissionResponse = new GetAllResponse<>();
    getAllPermissionResponse.setTotal(total);
    getAllPermissionResponse.setData(permissions.stream().map(p -> new PermissionResponse(p)).collect(Collectors.toList()));
    LOGGER.info("Succeed to get all permission, page: {}, size: {}, permissions: {}, current_user: {}", page, size, getAllPermissionResponse, HttpUtils.getUserName(httpServletRequest));
    return new GeneralResponse<>("200", "{&FIND_ALL_PERMISSIONS_SUCCESSFULLY}", getAllPermissionResponse);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UserSpecPermission(com.webank.wedatasphere.qualitis.entity.UserSpecPermission) Permission(com.webank.wedatasphere.qualitis.entity.Permission) RolePermission(com.webank.wedatasphere.qualitis.entity.RolePermission) PermissionResponse(com.webank.wedatasphere.qualitis.response.PermissionResponse) GetAllResponse(com.webank.wedatasphere.qualitis.response.GetAllResponse)

Example 90 with GeneralResponse

use of com.webank.wedatasphere.qualitis.response.GeneralResponse 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)

Aggregations

GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)146 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)96 Transactional (org.springframework.transaction.annotation.Transactional)49 ArrayList (java.util.ArrayList)48 User (com.webank.wedatasphere.qualitis.entity.User)40 GetAllResponse (com.webank.wedatasphere.qualitis.response.GetAllResponse)30 Project (com.webank.wedatasphere.qualitis.project.entity.Project)28 Map (java.util.Map)27 ClusterInfo (com.webank.wedatasphere.qualitis.entity.ClusterInfo)26 MetaDataAcquireFailedException (com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException)24 List (java.util.List)22 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)21 PermissionDeniedRequestException (com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException)17 IOException (java.io.IOException)16 UserRole (com.webank.wedatasphere.qualitis.entity.UserRole)15 Date (java.util.Date)15 Task (com.webank.wedatasphere.qualitis.entity.Task)14 JSONObject (org.json.JSONObject)14 HttpEntity (org.springframework.http.HttpEntity)14 HttpHeaders (org.springframework.http.HttpHeaders)14