Search in sources :

Example 1 with PermissionResponse

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

the class PermissionServiceImpl method addPermission.

@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<PermissionResponse> addPermission(AddPermissionRequest request) throws UnExpectedRequestException {
    // Check Arguments
    AddPermissionRequest.checkRequest(request);
    String method = request.getMethod().trim();
    String url = request.getUrl().trim();
    // Find permission by method and url
    Permission permissionInDb = permissionDao.findByMethodAndUrl(method, url);
    if (permissionInDb != null) {
        throw new UnExpectedRequestException("{&METHOD_AND_URL_ALREADY_EXIST}, request: " + request);
    }
    Permission newPermission = new Permission();
    newPermission.setMethod(method);
    newPermission.setUrl(url);
    Permission savedPermission = permissionDao.savePermission(newPermission);
    LOGGER.info("Succeed to add permission, id: {}, method: {}, url: {}, current_user: {}", savedPermission.getId(), method, url, HttpUtils.getUserName(httpServletRequest));
    return new GeneralResponse<>("200", "{&ADD_PERMISSION_SUCCESSFULLY}", new PermissionResponse(savedPermission));
}
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) PermissionResponse(com.webank.wedatasphere.qualitis.response.PermissionResponse) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with PermissionResponse

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

Aggregations

Permission (com.webank.wedatasphere.qualitis.entity.Permission)2 RolePermission (com.webank.wedatasphere.qualitis.entity.RolePermission)2 UserSpecPermission (com.webank.wedatasphere.qualitis.entity.UserSpecPermission)2 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)2 PermissionResponse (com.webank.wedatasphere.qualitis.response.PermissionResponse)2 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)1 GetAllResponse (com.webank.wedatasphere.qualitis.response.GetAllResponse)1 Transactional (org.springframework.transaction.annotation.Transactional)1