use of com.webank.wedatasphere.qualitis.response.GeneralResponse 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.response.GeneralResponse 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);
}
use of com.webank.wedatasphere.qualitis.response.GeneralResponse in project Qualitis by WeBankFinTech.
the class RoleServiceImpl method addRole.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<RoleResponse> addRole(RoleAddRequest request) throws UnExpectedRequestException {
// Check Arguments
checkRequest(request);
// Check existence of role by role name
String roleName = request.getRoleName();
Role roleInDb = roleDao.findByRoleName(roleName);
if (roleInDb != null) {
throw new UnExpectedRequestException("role name {&ALREADY_EXIST}, request: " + request);
}
// Save new role
Role newRole = new Role();
newRole.setName(roleName);
if (request.getDepartmentName() != null) {
Department departmentInDb = departmentDao.findByName(request.getDepartmentName());
if (departmentInDb == null) {
throw new UnExpectedRequestException("department {&DOES_NOT_EXIST}, name: " + request.getDepartmentName());
}
LOGGER.info("Succeed to find department. Name: " + departmentInDb.getName());
newRole.setDepartment(departmentInDb);
}
Role savedRole = roleDao.saveRole(newRole);
RoleResponse roleResponse = new RoleResponse(savedRole);
LOGGER.info("Succeed to add role, role: {}, current_user: {}", roleResponse, HttpUtils.getUserName(httpServletRequest));
return new GeneralResponse<>("200", "{&CREATE_ROLE_SUCCESSFULLY}", roleResponse);
}
use of com.webank.wedatasphere.qualitis.response.GeneralResponse in project Qualitis by WeBankFinTech.
the class RoleServiceImpl method getAllRole.
@Override
public GeneralResponse<GetAllResponse<RoleResponse>> getAllRole(PageRequest request) throws UnExpectedRequestException {
// Check Arguments
PageRequest.checkRequest(request);
int page = request.getPage();
int size = request.getSize();
List<Role> roles = roleDao.findAllRole(page, size);
long total = roleDao.countAll();
List<RoleResponse> roleResponses = new ArrayList<>();
for (Role role : roles) {
RoleResponse tmp = new RoleResponse(role);
roleResponses.add(tmp);
}
GetAllResponse<RoleResponse> responses = new GetAllResponse<>();
responses.setData(roleResponses);
responses.setTotal(total);
LOGGER.info("Succeed to find all roles, page: {}, size: {}, role: {}, current_user: {}", page, size, responses, HttpUtils.getUserName(httpServletRequest));
return new GeneralResponse<>("200", "{&FIND_ALL_ROLES_SUCCESSFULLY}", responses);
}
use of com.webank.wedatasphere.qualitis.response.GeneralResponse in project Qualitis by WeBankFinTech.
the class ClusterInfoServiceImpl method deleteClusterInfo.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> deleteClusterInfo(DeleteClusterInfoRequest request) throws UnExpectedRequestException {
// 检查参数
checkRequest(request);
// 根据id查找ClusterInfo,不存在则抛出异常
Long clusterInfoId = request.getClusterInfoId();
ClusterInfo clusterInfoInDb = clusterInfoDao.findById(clusterInfoId);
if (clusterInfoInDb == null) {
throw new UnExpectedRequestException("id {&DOES_NOT_EXIST}");
}
// 删除clusterInfo
clusterInfoDao.deleteClusterInfo(clusterInfoInDb);
LOGGER.info("Succeed to delete cluster_info. id: {}", request.getClusterInfoId());
return new GeneralResponse<>("200", "{&DELETE_CLUSTER_INFO_SUCCESSFULLY}", null);
}
Aggregations