Search in sources :

Example 46 with GeneralResponse

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

Example 47 with GeneralResponse

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);
}
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 48 with GeneralResponse

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);
}
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 49 with GeneralResponse

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);
}
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 50 with GeneralResponse

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);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) RolePermissionResponse(com.webank.wedatasphere.qualitis.response.RolePermissionResponse) ArrayList(java.util.ArrayList) RolePermission(com.webank.wedatasphere.qualitis.entity.RolePermission) GetAllResponse(com.webank.wedatasphere.qualitis.response.GetAllResponse)

Aggregations

GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)146 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)96 Transactional (org.springframework.transaction.annotation.Transactional)49 ArrayList (java.util.ArrayList)48 User (com.webank.wedatasphere.qualitis.entity.User)40 GetAllResponse (com.webank.wedatasphere.qualitis.response.GetAllResponse)30 Project (com.webank.wedatasphere.qualitis.project.entity.Project)28 Map (java.util.Map)27 ClusterInfo (com.webank.wedatasphere.qualitis.entity.ClusterInfo)26 MetaDataAcquireFailedException (com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException)24 List (java.util.List)22 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)21 PermissionDeniedRequestException (com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException)17 IOException (java.io.IOException)16 UserRole (com.webank.wedatasphere.qualitis.entity.UserRole)15 Date (java.util.Date)15 Task (com.webank.wedatasphere.qualitis.entity.Task)14 JSONObject (org.json.JSONObject)14 HttpEntity (org.springframework.http.HttpEntity)14 HttpHeaders (org.springframework.http.HttpHeaders)14