Search in sources :

Example 1 with RolePermissionResponse

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

the class RolePermissionServiceImpl method findAllRolePermission.

@Override
public GeneralResponse<GetAllResponse<RolePermissionResponse>> findAllRolePermission(PageRequest request) throws UnExpectedRequestException {
    // Check Arguments
    PageRequest.checkRequest(request);
    int page = request.getPage();
    int size = request.getSize();
    List<RolePermission> rolePermissions = rolePermissionDao.findAllRolePermission(page, size);
    long total = rolePermissionDao.countAll();
    List<RolePermissionResponse> rolePermissionResponses = new ArrayList<>();
    for (RolePermission rolePermission : rolePermissions) {
        RolePermissionResponse tmp = new RolePermissionResponse(rolePermission);
        rolePermissionResponses.add(tmp);
    }
    GetAllResponse<RolePermissionResponse> responses = new GetAllResponse<>();
    responses.setData(rolePermissionResponses);
    responses.setTotal(total);
    LOGGER.info("Succeed to find all role_permission, response: {}, current_user: {}", responses, HttpUtils.getUserName(httpServletRequest));
    return new GeneralResponse<>("200", "{&FIND_ALL_ROLE_PERMISSION_SUCCESSFULLY}", responses);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) RolePermissionResponse(com.webank.wedatasphere.qualitis.response.RolePermissionResponse) ArrayList(java.util.ArrayList) RolePermission(com.webank.wedatasphere.qualitis.entity.RolePermission) GetAllResponse(com.webank.wedatasphere.qualitis.response.GetAllResponse)

Example 2 with RolePermissionResponse

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

RolePermission (com.webank.wedatasphere.qualitis.entity.RolePermission)2 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)2 RolePermissionResponse (com.webank.wedatasphere.qualitis.response.RolePermissionResponse)2 Permission (com.webank.wedatasphere.qualitis.entity.Permission)1 Role (com.webank.wedatasphere.qualitis.entity.Role)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