Search in sources :

Example 1 with UserRoleResponse

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

the class UserRoleServiceImpl method findAllUserRole.

@Override
public GeneralResponse<GetAllResponse<UserRoleResponse>> findAllUserRole(PageRequest request) throws UnExpectedRequestException {
    // Check Arguments
    PageRequest.checkRequest(request);
    int page = request.getPage();
    int size = request.getSize();
    List<UserRole> userRoles = userRoleDao.findAllUserRole(page, size);
    long total = userRoleDao.countAll();
    List<UserRoleResponse> userRoleResponses = new ArrayList<>();
    for (UserRole userRole : userRoles) {
        UserRoleResponse response = new UserRoleResponse(userRole);
        userRoleResponses.add(response);
    }
    GetAllResponse<UserRoleResponse> responses = new GetAllResponse<>();
    responses.setTotal(total);
    responses.setData(userRoleResponses);
    LOGGER.info("Succeed to find all user_roles, response: {}, current_user: {}", responses, HttpUtils.getUserName(httpServletRequest));
    return new GeneralResponse<>("200", "{&FIND_ALL_USER_ROLES_SUCCESSFULLY}", responses);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UserRoleResponse(com.webank.wedatasphere.qualitis.response.UserRoleResponse) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole) ArrayList(java.util.ArrayList) GetAllResponse(com.webank.wedatasphere.qualitis.response.GetAllResponse)

Example 2 with UserRoleResponse

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

Aggregations

UserRole (com.webank.wedatasphere.qualitis.entity.UserRole)2 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)2 UserRoleResponse (com.webank.wedatasphere.qualitis.response.UserRoleResponse)2 Role (com.webank.wedatasphere.qualitis.entity.Role)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