Search in sources :

Example 1 with RolePermission

use of com.webank.wedatasphere.qualitis.entity.RolePermission 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 2 with RolePermission

use of com.webank.wedatasphere.qualitis.entity.RolePermission 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)

Example 3 with RolePermission

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

the class RolePermissionServiceImpl method modifyRolePermission.

@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> modifyRolePermission(ModifyRolePermissionRequest request) throws UnExpectedRequestException {
    // Check Arguments
    checkRequest(request);
    // Check existence of role permission
    String uuid = request.getUuid();
    RolePermission rolePermissionInDb = rolePermissionDao.findByUuid(uuid);
    if (rolePermissionInDb == null) {
        throw new UnExpectedRequestException("role permission id {&DOES_NOT_EXIST}, request: " + request);
    }
    LOGGER.info("Succeed to find role_permission, uuid: {}, role_id: {}, permission_id: {}, current_user: {}", uuid, rolePermissionInDb.getRole().getId(), rolePermissionInDb.getPermission().getId(), HttpUtils.getUserName(httpServletRequest));
    long roleId = request.getRoleId();
    long permissionId = request.getPermissionId();
    Role roleInDb = roleDao.findById(roleId);
    if (roleInDb == null) {
        throw new UnExpectedRequestException("role id {&DOES_NOT_EXIST}, request: " + request);
    }
    Permission permissionInDb = permissionDao.findById(permissionId);
    if (permissionInDb == null) {
        throw new UnExpectedRequestException("permission id {&DOES_NOT_EXIST}, request: " + request);
    }
    RolePermission roleIdAndPermissionIdInDb = rolePermissionDao.findByRoleAndPermission(roleInDb, permissionInDb);
    if (roleIdAndPermissionIdInDb != null) {
        throw new UnExpectedRequestException("role and permission {&ALREADY_EXIST}, request: " + request);
    }
    // Save role permission
    rolePermissionInDb.setRole(roleInDb);
    rolePermissionInDb.setPermission(permissionInDb);
    RolePermission savedRolePermission = rolePermissionDao.saveRolePermission(rolePermissionInDb);
    LOGGER.info("Succeed to modify role_permission, uuid: {}, role_id: {}, permission_id: {}, current_user: {}", uuid, savedRolePermission.getRole().getId(), savedRolePermission.getPermission().getId(), HttpUtils.getUserName(httpServletRequest));
    return new GeneralResponse<>("200", "{&MODIFY_ROLE_PERMISSION_SUCCESSFULLY}", null);
}
Also used : Role(com.webank.wedatasphere.qualitis.entity.Role) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) Permission(com.webank.wedatasphere.qualitis.entity.Permission) RolePermission(com.webank.wedatasphere.qualitis.entity.RolePermission) RolePermission(com.webank.wedatasphere.qualitis.entity.RolePermission) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with RolePermission

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

the class RolePermissionServiceImpl method deleteRolePermission.

@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> deleteRolePermission(DeleteRolePermissionRequest request) throws UnExpectedRequestException {
    // Check Arguments
    checkRequest(request);
    // Find role permission by id
    String uuid = request.getUuid();
    RolePermission rolePermissionInDb = rolePermissionDao.findByUuid(uuid);
    if (rolePermissionInDb == null) {
        throw new UnExpectedRequestException("role permission id {&DOES_NOT_EXIST}, request: " + request);
    }
    // Delete role permission
    rolePermissionDao.deleteRolePermission(rolePermissionInDb);
    LOGGER.info("Succeed to delete role_permission, uuid: {}, role_id: {}, permission_id: {}, current_user: {}", uuid, rolePermissionInDb.getRole().getId(), rolePermissionInDb.getPermission().getId(), HttpUtils.getUserName(httpServletRequest));
    return new GeneralResponse<>("200", "{&DELETE_ROLE_PERMISSION_SUCCESSFULLY}", null);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) RolePermission(com.webank.wedatasphere.qualitis.entity.RolePermission) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with RolePermission

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

the class RolePermissionServiceImpl method addRolePermission.

@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<RolePermissionResponse> addRolePermission(AddRolePermissionRequest request) throws UnExpectedRequestException {
    // Check Arguments
    checkRequest(request);
    // Check existence of role and permission
    long roleId = request.getRoleId();
    long permissionId = request.getPermissionId();
    Role roleInDb = roleDao.findById(roleId);
    if (roleInDb == null) {
        throw new UnExpectedRequestException("role id {&DOES_NOT_EXIST}, request: " + request);
    }
    Permission permissionInDb = permissionDao.findById(permissionId);
    if (permissionInDb == null) {
        throw new UnExpectedRequestException("permission id {&DOES_NOT_EXIST}, request: " + request);
    }
    RolePermission rolePermissionInDb = rolePermissionDao.findByRoleAndPermission(roleInDb, permissionInDb);
    if (rolePermissionInDb != null) {
        throw new UnExpectedRequestException("role and permission {&ALREADY_EXIST}, request: " + request);
    }
    // Save new role permission
    RolePermission newRolePermission = new RolePermission();
    newRolePermission.setPermission(permissionInDb);
    newRolePermission.setRole(roleInDb);
    newRolePermission.setId(UuidGenerator.generate());
    RolePermission savedRolePermission = rolePermissionDao.saveRolePermission(newRolePermission);
    RolePermissionResponse response = new RolePermissionResponse(savedRolePermission);
    LOGGER.info("Succeed to add role_permission, response: {}, current_user: {}", response, HttpUtils.getUserName(httpServletRequest));
    return new GeneralResponse<>("200", "{&ADD_ROLE_PERMISSION_SUCCESSFULLY}", response);
}
Also used : Role(com.webank.wedatasphere.qualitis.entity.Role) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) RolePermissionResponse(com.webank.wedatasphere.qualitis.response.RolePermissionResponse) Permission(com.webank.wedatasphere.qualitis.entity.Permission) RolePermission(com.webank.wedatasphere.qualitis.entity.RolePermission) RolePermission(com.webank.wedatasphere.qualitis.entity.RolePermission) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

RolePermission (com.webank.wedatasphere.qualitis.entity.RolePermission)6 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)5 Transactional (org.springframework.transaction.annotation.Transactional)5 Permission (com.webank.wedatasphere.qualitis.entity.Permission)4 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)4 Role (com.webank.wedatasphere.qualitis.entity.Role)3 RolePermissionResponse (com.webank.wedatasphere.qualitis.response.RolePermissionResponse)2 UserSpecPermission (com.webank.wedatasphere.qualitis.entity.UserSpecPermission)1 GetAllResponse (com.webank.wedatasphere.qualitis.response.GetAllResponse)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1