Search in sources :

Example 1 with UserSpecPermissionResponse

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

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

Aggregations

UserSpecPermission (com.webank.wedatasphere.qualitis.entity.UserSpecPermission)2 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)2 UserSpecPermissionResponse (com.webank.wedatasphere.qualitis.response.UserSpecPermissionResponse)2 Permission (com.webank.wedatasphere.qualitis.entity.Permission)1 User (com.webank.wedatasphere.qualitis.entity.User)1 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)1 GetAllResponse (com.webank.wedatasphere.qualitis.response.GetAllResponse)1 ArrayList (java.util.ArrayList)1 Transactional (org.springframework.transaction.annotation.Transactional)1