Search in sources :

Example 1 with ProxyUser

use of com.webank.wedatasphere.qualitis.entity.ProxyUser 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);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) AddProxyUserResponse(com.webank.wedatasphere.qualitis.response.AddProxyUserResponse) ProxyUser(com.webank.wedatasphere.qualitis.entity.ProxyUser) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with ProxyUser

use of com.webank.wedatasphere.qualitis.entity.ProxyUser 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);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) Pageable(org.springframework.data.domain.Pageable) ArrayList(java.util.ArrayList) Sort(org.springframework.data.domain.Sort) AddProxyUserResponse(com.webank.wedatasphere.qualitis.response.AddProxyUserResponse) ProxyUser(com.webank.wedatasphere.qualitis.entity.ProxyUser) GetAllResponse(com.webank.wedatasphere.qualitis.response.GetAllResponse)

Example 3 with ProxyUser

use of com.webank.wedatasphere.qualitis.entity.ProxyUser 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);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) ProxyUser(com.webank.wedatasphere.qualitis.entity.ProxyUser) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with ProxyUser

use of com.webank.wedatasphere.qualitis.entity.ProxyUser in project Qualitis by WeBankFinTech.

the class UserProxyUserServiceImpl method getAllUserProxyUserByProxyUserName.

@Override
public GeneralResponse<?> getAllUserProxyUserByProxyUserName(String proxyUserName, PageRequest request) throws UnExpectedRequestException {
    // Check Arguments
    PageRequest.checkRequest(request);
    // Check existence of proxy user
    ProxyUser proxyUserInDb = proxyUserRepository.findByProxyUserName(proxyUserName);
    if (proxyUserInDb == null) {
        throw new UnExpectedRequestException("ProxyUser name {&DOES_NOT_EXIST}, request: " + request);
    }
    // Find user proxy user by proxy user
    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<UserProxyUser> userProxyUsers = userProxyUserRepository.findByProxyUser(proxyUserInDb, pageable);
    long total = userProxyUserRepository.countByProxyUser(proxyUserInDb);
    List<AddUserProxyUserResponse> userProxyUserResponses = new ArrayList<>();
    for (UserProxyUser userProxyUser : userProxyUsers) {
        AddUserProxyUserResponse tmp = new AddUserProxyUserResponse(userProxyUser);
        userProxyUserResponses.add(tmp);
    }
    GetAllResponse<AddUserProxyUserResponse> response = new GetAllResponse<>();
    response.setTotal(total);
    response.setData(userProxyUserResponses);
    LOGGER.info("Succeed to find all user proxy users by proxy user name, response: {}", response);
    return new GeneralResponse<>("200", "{&SUCCEED_TO_FIND_ALL_PROXY_USERS_BY_PROXY_USER_NAME}", response);
}
Also used : UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) ArrayList(java.util.ArrayList) ProxyUser(com.webank.wedatasphere.qualitis.entity.ProxyUser) UserProxyUser(com.webank.wedatasphere.qualitis.entity.UserProxyUser) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) AddUserProxyUserResponse(com.webank.wedatasphere.qualitis.response.AddUserProxyUserResponse) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) GetAllResponse(com.webank.wedatasphere.qualitis.response.GetAllResponse) UserProxyUser(com.webank.wedatasphere.qualitis.entity.UserProxyUser)

Example 5 with ProxyUser

use of com.webank.wedatasphere.qualitis.entity.ProxyUser in project Qualitis by WeBankFinTech.

the class UserProxyUserServiceImpl method addUserProxyUser.

@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> addUserProxyUser(AddUserProxyUserRequest request) throws UnExpectedRequestException {
    // Check Arguments
    AddUserProxyUserRequest.checkRequest(request);
    // Find user and proxy user by username
    User userInDb = userDao.findByUsername(request.getUsername());
    if (userInDb == null) {
        throw new UnExpectedRequestException("Username {&DOES_NOT_EXIST}, request: " + request);
    }
    ProxyUser proxyUserInDb = proxyUserRepository.findByProxyUserName(request.getProxyUserName());
    if (proxyUserInDb == null) {
        throw new UnExpectedRequestException("ProxyUser {&DOES_NOT_EXIST}, request: " + request);
    }
    UserProxyUser userProxyUserInDb = userProxyUserRepository.findByUserAndProxyUser(userInDb, proxyUserInDb);
    if (userProxyUserInDb != null) {
        throw new UnExpectedRequestException("User proxy user {&ALREADY_EXIST}, request: " + request);
    }
    UserProxyUser newUserProxyUser = new UserProxyUser();
    newUserProxyUser.setProxyUser(proxyUserInDb);
    newUserProxyUser.setUser(userInDb);
    UserProxyUser savedUserProxyUser = userProxyUserRepository.save(newUserProxyUser);
    LOGGER.info("Succeed to save user proxy user. user_proxy_user_id: {}", savedUserProxyUser.getId());
    AddUserProxyUserResponse response = new AddUserProxyUserResponse(savedUserProxyUser);
    return new GeneralResponse<>("200", "{&SUCCEED_TO_SAVE_USER_PROXY_USER}", response);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) AddUserProxyUserResponse(com.webank.wedatasphere.qualitis.response.AddUserProxyUserResponse) ProxyUser(com.webank.wedatasphere.qualitis.entity.ProxyUser) UserProxyUser(com.webank.wedatasphere.qualitis.entity.UserProxyUser) User(com.webank.wedatasphere.qualitis.entity.User) ProxyUser(com.webank.wedatasphere.qualitis.entity.ProxyUser) UserProxyUser(com.webank.wedatasphere.qualitis.entity.UserProxyUser) UserProxyUser(com.webank.wedatasphere.qualitis.entity.UserProxyUser) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ProxyUser (com.webank.wedatasphere.qualitis.entity.ProxyUser)6 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)6 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)5 Transactional (org.springframework.transaction.annotation.Transactional)4 UserProxyUser (com.webank.wedatasphere.qualitis.entity.UserProxyUser)2 AddProxyUserResponse (com.webank.wedatasphere.qualitis.response.AddProxyUserResponse)2 AddUserProxyUserResponse (com.webank.wedatasphere.qualitis.response.AddUserProxyUserResponse)2 GetAllResponse (com.webank.wedatasphere.qualitis.response.GetAllResponse)2 ArrayList (java.util.ArrayList)2 Pageable (org.springframework.data.domain.Pageable)2 Sort (org.springframework.data.domain.Sort)2 User (com.webank.wedatasphere.qualitis.entity.User)1