use of com.webank.wedatasphere.qualitis.entity.RolePermission in project Qualitis by WeBankFinTech.
the class PermissionServiceImpl method deletePermission.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> deletePermission(DeletePermissionRequest request) throws UnExpectedRequestException {
// Check Arguments
checkRequest(request);
Long permissionId = request.getPermissionId();
// Find permissions by permission id
Permission permissionInDb = permissionDao.findById(permissionId);
if (permissionInDb == null) {
throw new UnExpectedRequestException("{&PERMISSION_ID_NOT_EXIST}, request: " + request);
}
List<RolePermission> rolePermissionsInDb = rolePermissionDao.findByPermission(permissionInDb);
if (null != rolePermissionsInDb && !rolePermissionsInDb.isEmpty()) {
throw new UnExpectedRequestException("{&DELETE_ERROR_ROLE_PERMISSION_HAS_FOREIGN_KEY}");
}
List<UserSpecPermission> userSpecPermissionsInDb = userSpecPermissionDao.findByPermission(permissionInDb);
if (null != userSpecPermissionsInDb && !userSpecPermissionsInDb.isEmpty()) {
throw new UnExpectedRequestException("{&DELETE_ERROR_USER_SPEC_PERMISSION_HAS_FOREIGN_KEY}");
}
permissionDao.deletePermission(permissionInDb);
LOGGER.info("Succeed to delete permission, permissionId: {}, method: {}, url: {}, current_user: {}", permissionId, permissionInDb.getMethod(), permissionInDb.getUrl(), HttpUtils.getUserName(httpServletRequest));
return new GeneralResponse<>("200", "{&DELETE_PERMISSION_SUCCESSFULLY}", null);
}
use of com.webank.wedatasphere.qualitis.entity.RolePermission 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);
}
use of com.webank.wedatasphere.qualitis.entity.RolePermission in project Qualitis by WeBankFinTech.
the class RolePermissionServiceImpl method modifyRolePermission.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> modifyRolePermission(ModifyRolePermissionRequest request) throws UnExpectedRequestException {
// Check Arguments
checkRequest(request);
// Check existence of role permission
String uuid = request.getUuid();
RolePermission rolePermissionInDb = rolePermissionDao.findByUuid(uuid);
if (rolePermissionInDb == null) {
throw new UnExpectedRequestException("role permission id {&DOES_NOT_EXIST}, request: " + request);
}
LOGGER.info("Succeed to find role_permission, uuid: {}, role_id: {}, permission_id: {}, current_user: {}", uuid, rolePermissionInDb.getRole().getId(), rolePermissionInDb.getPermission().getId(), HttpUtils.getUserName(httpServletRequest));
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 roleIdAndPermissionIdInDb = rolePermissionDao.findByRoleAndPermission(roleInDb, permissionInDb);
if (roleIdAndPermissionIdInDb != null) {
throw new UnExpectedRequestException("role and permission {&ALREADY_EXIST}, request: " + request);
}
// Save role permission
rolePermissionInDb.setRole(roleInDb);
rolePermissionInDb.setPermission(permissionInDb);
RolePermission savedRolePermission = rolePermissionDao.saveRolePermission(rolePermissionInDb);
LOGGER.info("Succeed to modify role_permission, uuid: {}, role_id: {}, permission_id: {}, current_user: {}", uuid, savedRolePermission.getRole().getId(), savedRolePermission.getPermission().getId(), HttpUtils.getUserName(httpServletRequest));
return new GeneralResponse<>("200", "{&MODIFY_ROLE_PERMISSION_SUCCESSFULLY}", null);
}
use of com.webank.wedatasphere.qualitis.entity.RolePermission in project Qualitis by WeBankFinTech.
the class RolePermissionServiceImpl method deleteRolePermission.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> deleteRolePermission(DeleteRolePermissionRequest request) throws UnExpectedRequestException {
// Check Arguments
checkRequest(request);
// Find role permission by id
String uuid = request.getUuid();
RolePermission rolePermissionInDb = rolePermissionDao.findByUuid(uuid);
if (rolePermissionInDb == null) {
throw new UnExpectedRequestException("role permission id {&DOES_NOT_EXIST}, request: " + request);
}
// Delete role permission
rolePermissionDao.deleteRolePermission(rolePermissionInDb);
LOGGER.info("Succeed to delete role_permission, uuid: {}, role_id: {}, permission_id: {}, current_user: {}", uuid, rolePermissionInDb.getRole().getId(), rolePermissionInDb.getPermission().getId(), HttpUtils.getUserName(httpServletRequest));
return new GeneralResponse<>("200", "{&DELETE_ROLE_PERMISSION_SUCCESSFULLY}", null);
}
use of com.webank.wedatasphere.qualitis.entity.RolePermission 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);
}
Aggregations