use of com.webank.wedatasphere.qualitis.response.GeneralResponse in project Qualitis by WeBankFinTech.
the class UserSpecPermissionServiceImpl method deleteUserSpecPermission.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> deleteUserSpecPermission(DeleteUserSpecPermissionRequest request) throws UnExpectedRequestException {
// Check Arguments
checkRequest(request);
// Check existence of user permission by id
String uuid = request.getUuid();
UserSpecPermission userSpecPermissionInDb = userSpecPermissionDao.findByUuid(uuid);
if (userSpecPermissionInDb == null) {
throw new UnExpectedRequestException("user_spec_permission id {&DOES_NOT_EXIST}, request: " + request);
}
// Delete user permission
userSpecPermissionDao.deleteUserSpecPermission(userSpecPermissionInDb);
LOGGER.info("Succeed to delete user_permission, uuid: {}, current_user: {}", uuid, HttpUtils.getUserName(httpServletRequest));
return new GeneralResponse<>("200", "{&DELETE_USER_SPEC_PERMISSION_SUCCESSFULLY}", null);
}
use of com.webank.wedatasphere.qualitis.response.GeneralResponse in project Qualitis by WeBankFinTech.
the class UserSpecPermissionServiceImpl method modifyUserSpecPermission.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> modifyUserSpecPermission(ModifyUserSpecPermissionRequest request) throws UnExpectedRequestException {
// Check Arguments
checkRequest(request);
// Find user permission by id
String uuid = request.getUuid();
UserSpecPermission userSpecPermissionInDb = userSpecPermissionDao.findByUuid(uuid);
if (userSpecPermissionInDb == null) {
throw new UnExpectedRequestException("user_spec_permission id {&DOES_NOT_EXIST}, request: " + request);
}
LOGGER.info("Succeed to find user_permission. uuid: {}, user_id: {}, permission_id: {}, current_user: {}", uuid, userSpecPermissionInDb.getUser().getId(), userSpecPermissionInDb.getPermission().getId(), HttpUtils.getUserName(httpServletRequest));
// Check existence of user and permission
long userId = request.getUserId();
long permissionId = request.getPermissionId();
User userInDb = userDao.findById(userId);
if (userInDb == null) {
throw new UnExpectedRequestException("user id {&DOES_NOT_EXIST}, request: " + request);
}
Permission permissionInDb = permissionDao.findById(permissionId);
if (permissionInDb == null) {
throw new UnExpectedRequestException("permission id {&DOES_NOT_EXIST}, request: " + request);
}
UserSpecPermission userIdAndPermissionIdInDb = userSpecPermissionDao.findByUserAndPermission(userInDb, permissionInDb);
if (userIdAndPermissionIdInDb != null) {
throw new UnExpectedRequestException("user id and permission id {&ALREADY_EXIST}, request: " + request);
}
// Save user permission
userSpecPermissionInDb.setPermission(permissionInDb);
userSpecPermissionInDb.setUser(userInDb);
UserSpecPermission savedUserSpecPermission = userSpecPermissionDao.saveUserSpecPermission(userSpecPermissionInDb);
LOGGER.info("Succeed to find user_permission. uuid: {}, user_id: {}, permission_id: {}, current_user: {}", uuid, savedUserSpecPermission.getUser().getId(), savedUserSpecPermission.getPermission().getId(), HttpUtils.getUserName(httpServletRequest));
return new GeneralResponse<>("200", "{&MODIFY_USER_SPEC_PERMISSION_SUCCESSFULLY}", null);
}
use of com.webank.wedatasphere.qualitis.response.GeneralResponse in project Qualitis by WeBankFinTech.
the class DepartmentServiceImpl method addDepartment.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<DepartmentResponse> addDepartment(DepartmentAddRequest request) throws UnExpectedRequestException {
Department departmentInDb = departmentDao.findByName(request.getDepartmentName());
if (departmentInDb != null) {
LOGGER.error("Department already exist.");
throw new UnExpectedRequestException("Department {&ALREADY_EXIST}");
}
Department department = new Department();
department.setName(request.getDepartmentName());
Department savedDepartment = departmentDao.saveDepartment(department);
LOGGER.info("Succeed to create department, saved department info is : {}", savedDepartment.toString());
return new GeneralResponse<>("200", "{&ADD_DEPARTMENT_SUCCESSFULLY}", new DepartmentResponse(savedDepartment));
}
use of com.webank.wedatasphere.qualitis.response.GeneralResponse in project Qualitis by WeBankFinTech.
the class DepartmentServiceImpl method findAllDepartment.
@Override
public GeneralResponse<GetAllResponse<DepartmentResponse>> findAllDepartment(PageRequest request) throws UnExpectedRequestException {
PageRequest.checkRequest(request);
int page = request.getPage();
int size = request.getSize();
long total = departmentDao.countDepartment();
List<Department> departmentList = departmentDao.findAllDepartment(page, size);
List<DepartmentResponse> departmentResponses = new ArrayList<>(departmentList.size());
for (Department department : departmentList) {
departmentResponses.add(new DepartmentResponse(department));
}
GetAllResponse<DepartmentResponse> responses = new GetAllResponse<>();
responses.setData(departmentResponses);
responses.setTotal(total);
LOGGER.info("Succeed to find all departments, page: {}, size: {}, departments: {}", page, size, responses);
return new GeneralResponse("200", "{&GET_DEPARTMENT_SUCCESSFULLY}", responses);
}
use of com.webank.wedatasphere.qualitis.response.GeneralResponse in project Qualitis by WeBankFinTech.
the class DepartmentServiceImpl method deleteDepartment.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> deleteDepartment(Long departmentId) throws UnExpectedRequestException {
if (departmentId == null) {
throw new UnExpectedRequestException("department id {&CAN_NOT_BE_NULL_OR_EMPTY}");
}
Department departmentInDb = departmentDao.findById(departmentId);
if (departmentInDb == null) {
LOGGER.error("Department donot exist.");
throw new UnExpectedRequestException("Department {&DOES_NOT_EXIST}");
}
// Check user exists.
checkUser(departmentInDb);
// Check role exists.
checkRole(departmentInDb);
departmentDao.deleteDepartment(departmentInDb);
LOGGER.info("Succeed to delete department, saved department id is : {}", departmentId);
return new GeneralResponse<>("200", "{&DELETE_DEPARTMENT_SUCCESSFULLY}", null);
}
Aggregations