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));
}
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);
}
Aggregations