Search in sources :

Example 1 with UserSpecPermission

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

the class UserSpecPermissionDaoTest method test.

@Test
@Transactional
public void test() {
    Permission savePermission = savePermission();
    User saveUser = saveUser();
    // 保存是否成功
    UserSpecPermission entity = new UserSpecPermission();
    entity.setId(UuidGenerator.generate());
    entity.setPermission(savePermission);
    entity.setUser(saveUser);
    UserSpecPermission saveEntity = dao.saveUserSpecPermission(entity);
    assertNotNull(saveEntity.getId());
    // 总数量大于0
    long size = dao.countAll();
    assertTrue(size > 0);
    // 分页查询有结果
    List<UserSpecPermission> datas = dao.findAllUserSpecPermission(0, 5);
    assertTrue(datas.size() > 0);
    // 保存到数据库的对象是否和保存的值一致
    UserSpecPermission findByIdEntity = dao.findByUuid(saveEntity.getId());
    assertNotNull(findByIdEntity);
    assertEquals(findByIdEntity.getPermission().getUrl(), saveEntity.getPermission().getUrl());
    assertEquals(findByIdEntity.getUser().getUserName(), saveEntity.getUser().getUserName());
    UserSpecPermission findByRoleAndPermissionEntity = dao.findByUserAndPermission(saveUser, savePermission);
    assertNotNull(findByRoleAndPermissionEntity);
    assertEquals(findByRoleAndPermissionEntity.getPermission().getUrl(), saveEntity.getPermission().getUrl());
    assertEquals(findByRoleAndPermissionEntity.getUser().getUserName(), saveEntity.getUser().getUserName());
    // 根据username查询的数据库对象是否和保存的值一致
    List<UserSpecPermission> findByRoleEntity = dao.findByUser(saveUser);
    assertTrue(findByRoleEntity.size() > 0);
    assertEquals(findByRoleEntity.get(0).getPermission().getUrl(), saveEntity.getPermission().getUrl());
    // 根据username查询的数据库对象是否和保存的值一致
    List<UserSpecPermission> findByPermissionEntity = dao.findByPermission(savePermission);
    assertTrue(findByPermissionEntity.size() > 0);
    assertEquals(findByPermissionEntity.get(0).getUser().getUserName(), saveEntity.getUser().getUserName());
    // 删除后,是否还能找到对象
    dao.deleteUserSpecPermission(saveEntity);
    UserSpecPermission deleteEntity = dao.findByUuid(saveEntity.getId());
    assertNull(deleteEntity);
}
Also used : 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) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with UserSpecPermission

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

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

the class UserServiceImpl method deleteUser.

@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> deleteUser(UserRequest request) throws UnExpectedRequestException {
    // Check Arguments
    checkRequest(request);
    // Check existence of user by id
    Long userId = request.getUserId();
    User userInDb = userDao.findById(userId);
    if (userInDb == null) {
        throw new UnExpectedRequestException("user id {&DOES_NOT_EXIST}, request: " + request);
    }
    // Check personal template.
    checkTemplate(userInDb);
    List<UserRole> userRolesInDb = userRoleDao.findByUser(userInDb);
    if (null != userRolesInDb && !userRolesInDb.isEmpty()) {
        throw new UnExpectedRequestException("{&DELETE_ERROR_USER_ROLE_HAS_FOREIGN_KEY}");
    }
    List<UserSpecPermission> userSpecPermissionsInDb = userSpecPermissionDao.findByUser(userInDb);
    if (null != userSpecPermissionsInDb && !userSpecPermissionsInDb.isEmpty()) {
        throw new UnExpectedRequestException("{&DELETE_ERROR_USER_SPEC_PERMISSION_HAS_FOREIGN_KEY}");
    }
    // Delete user
    userDao.deleteUser(userInDb);
    LOGGER.info("Succeed to delete user, userId: {}, username: {}, current_user: {}", userInDb.getId(), userInDb.getUserName(), HttpUtils.getUserName(httpServletRequest));
    return new GeneralResponse<>("200", "{&DELETE_USER_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) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole) UserSpecPermission(com.webank.wedatasphere.qualitis.entity.UserSpecPermission) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with UserSpecPermission

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

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

Aggregations

UserSpecPermission (com.webank.wedatasphere.qualitis.entity.UserSpecPermission)7 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)6 Transactional (org.springframework.transaction.annotation.Transactional)6 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)5 Permission (com.webank.wedatasphere.qualitis.entity.Permission)4 User (com.webank.wedatasphere.qualitis.entity.User)4 UserSpecPermissionResponse (com.webank.wedatasphere.qualitis.response.UserSpecPermissionResponse)2 RolePermission (com.webank.wedatasphere.qualitis.entity.RolePermission)1 UserRole (com.webank.wedatasphere.qualitis.entity.UserRole)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