use of com.webank.wedatasphere.qualitis.response.AddProxyUserResponse 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.AddProxyUserResponse 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);
}
Aggregations