use of com.webank.wedatasphere.qualitis.response.GeneralResponse 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.response.GeneralResponse in project Qualitis by WeBankFinTech.
the class ProxyUserServiceImpl method addProxyUser.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> addProxyUser(AddProxyUserRequest request) throws UnExpectedRequestException {
// Check Arguments
AddProxyUserRequest.checkRequest(request);
// Check existence of proxy user
ProxyUser proxyUserInDb = proxyUserRepository.findByProxyUserName(request.getProxyUserName());
if (proxyUserInDb != null) {
throw new UnExpectedRequestException("ProxyUser name: [" + request.getProxyUserName() + "] {&ALREADY_EXIST}");
}
// Save proxy user
ProxyUser proxyUser = new ProxyUser();
proxyUser.setProxyUserName(request.getProxyUserName());
ProxyUser savedProxyUser = proxyUserRepository.save(proxyUser);
LOGGER.info("Succeed to save proxyUser. proxy_user: {}", savedProxyUser.getProxyUserName());
AddProxyUserResponse response = new AddProxyUserResponse(savedProxyUser);
return new GeneralResponse<>("200", "{&SUCCEED_TO_SAVE_PROXYUSER}", response);
}
use of com.webank.wedatasphere.qualitis.response.GeneralResponse in project Qualitis by WeBankFinTech.
the class ProxyUserServiceImpl method getAllProxyUser.
@Override
public GeneralResponse<?> getAllProxyUser(PageRequest request) throws UnExpectedRequestException {
// Check Arguments
PageRequest.checkRequest(request);
// Query by page and size
int page = request.getPage();
int size = request.getSize();
Sort sort = new Sort(Sort.Direction.ASC, "id");
Pageable pageable = org.springframework.data.domain.PageRequest.of(page, size, sort);
List<ProxyUser> proxyUsers = proxyUserRepository.findAll(pageable).getContent();
long total = proxyUserRepository.count();
List<AddProxyUserResponse> proxyUserResponses = new ArrayList<>();
for (ProxyUser proxyUser : proxyUsers) {
AddProxyUserResponse tmp = new AddProxyUserResponse(proxyUser);
proxyUserResponses.add(tmp);
}
GetAllResponse<AddProxyUserResponse> response = new GetAllResponse<>();
response.setTotal(total);
response.setData(proxyUserResponses);
LOGGER.info("Succeed to find all proxyUsers, response: {}", response);
return new GeneralResponse<>("200", "{&SUCCEED_TO_FIND_ALL_PROXYUSERS}", response);
}
use of com.webank.wedatasphere.qualitis.response.GeneralResponse in project Qualitis by WeBankFinTech.
the class ProxyUserServiceImpl method deleteProxyUser.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> deleteProxyUser(DeleteProxyUserRequest request) throws UnExpectedRequestException {
// Check Arguments
DeleteProxyUserRequest.checkRequest(request);
// Check existence of proxy user
ProxyUser proxyUserInDb = proxyUserRepository.findById(request.getProxyUserId()).orElse(null);
if (proxyUserInDb == null) {
throw new UnExpectedRequestException("ProxyUser id: " + request.getProxyUserId() + " {&DOES_NOT_EXIST}");
}
proxyUserRepository.delete(proxyUserInDb);
LOGGER.info("Succeed to delete proxy user. proxy_user: {}", proxyUserInDb.getProxyUserName());
return new GeneralResponse<>("200", "{&SUCCEED_TO_DELETE_PROXY_USER}", null);
}
use of com.webank.wedatasphere.qualitis.response.GeneralResponse 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);
}
Aggregations