Search in sources :

Example 61 with GeneralResponse

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

Example 62 with GeneralResponse

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

Example 63 with GeneralResponse

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

Example 64 with GeneralResponse

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

Example 65 with GeneralResponse

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

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