Search in sources :

Example 11 with User

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

the class UserDaoTest method testUser.

@Test
@Transactional
public void testUser() {
    // 保存是否成功
    User user = new User();
    user.setChineseName("xxx");
    user.setUserName("xxx");
    user.setPassword("xxx");
    User saveUser = userDao.saveUser(user);
    assertTrue(saveUser.getId() != 0);
    // 总数量大于0
    long userSize = userDao.countAll();
    assertTrue(userSize > 0);
    // 分页查询有结果
    List<User> users = userDao.findAllUser(0, 5);
    assertTrue(users.size() > 0);
    // 保存到数据库的对象是否和保存的值一致
    User findUser = userDao.findById(saveUser.getId());
    assertNotNull(findUser);
    assertEquals(findUser.getChineseName(), saveUser.getChineseName());
    assertEquals(findUser.getDepartment(), saveUser.getDepartment());
    assertEquals(findUser.getUserName(), saveUser.getUserName());
    // 根据username查询的数据库对象是否和保存的值一致
    User findByUsernameUser = userDao.findByUsername(saveUser.getUserName());
    assertNotNull(findByUsernameUser);
    assertEquals(findByUsernameUser.getUserName(), saveUser.getUserName());
    // 删除后,是否还能找到对象
    userDao.deleteUser(saveUser);
    User findDelUser = userDao.findById(saveUser.getId());
    assertNull(findDelUser);
}
Also used : User(com.webank.wedatasphere.qualitis.entity.User) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 12 with User

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

the class UserRoleDaoTest method test.

@Test
@Transactional
public void test() {
    User saveUser = saveUser();
    Role saveRole = saveRole();
    // 保存是否成功
    UserRole entity = new UserRole();
    entity.setId(UuidGenerator.generate());
    entity.setUser(saveUser);
    entity.setRole(saveRole);
    UserRole saveEntity = dao.saveUserRole(entity);
    assertNotNull(saveEntity.getId());
    // 总数量大于0
    long size = dao.countAll();
    assertTrue(size > 0);
    // 分页查询有结果
    List<UserRole> datas = dao.findAllUserRole(0, 5);
    assertTrue(datas.size() > 0);
    // 保存到数据库的对象是否和保存的值一致
    UserRole findByIdEntity = dao.findByUuid(saveEntity.getId());
    assertNotNull(findByIdEntity);
    assertEquals(findByIdEntity.getUser().getUserName(), saveEntity.getUser().getUserName());
    assertEquals(findByIdEntity.getRole().getName(), saveEntity.getRole().getName());
    UserRole findByUserAndRoleEntity = dao.findByUserAndRole(saveUser, saveRole);
    assertNotNull(findByUserAndRoleEntity);
    assertEquals(findByUserAndRoleEntity.getUser().getUserName(), saveEntity.getUser().getUserName());
    assertEquals(findByUserAndRoleEntity.getRole().getName(), saveEntity.getRole().getName());
    // 根据username查询的数据库对象是否和保存的值一致
    List<UserRole> findByRoleEntity = dao.findByRole(saveRole);
    assertTrue(findByRoleEntity.size() > 0);
    assertEquals(findByRoleEntity.get(0).getUser().getUserName(), saveEntity.getUser().getUserName());
    // 根据username查询的数据库对象是否和保存的值一致
    List<UserRole> findByUserEntity = dao.findByUser(saveUser);
    assertTrue(findByUserEntity.size() > 0);
    assertEquals(findByUserEntity.get(0).getRole().getName(), saveEntity.getRole().getName());
    // 删除后,是否还能找到对象
    dao.deleteUserRole(saveEntity);
    UserRole deleteEntity = dao.findByUuid(saveEntity.getId());
    assertNull(deleteEntity);
}
Also used : Role(com.webank.wedatasphere.qualitis.entity.Role) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole) User(com.webank.wedatasphere.qualitis.entity.User) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with User

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

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

the class TransferUserServiceImpl method transferUser.

@Override
public GeneralResponse<?> transferUser(String user) throws UnExpectedRequestException {
    User userInDb = userDao.findByUsername(user);
    if (userInDb == null) {
        throw new UnExpectedRequestException("ProxyUser: " + user + " {&DOES_NOT_EXIST}");
    }
    Map<String, Object> userMap = ImmutableMap.of("userId", userInDb.getId(), "username", userInDb.getUserName());
    HttpSession httpSession = httpServletRequest.getSession();
    httpSession.setAttribute("proxyUser", userMap);
    return new GeneralResponse<>("200", "{&SUCCEED_TO_TRANSFER_TO_PROXYUSER}", null);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) User(com.webank.wedatasphere.qualitis.entity.User) HttpSession(javax.servlet.http.HttpSession)

Example 15 with User

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

the class UserServiceImpl method modifyDepartment.

@Override
public GeneralResponse<?> modifyDepartment(ModifyDepartmentRequest request) throws UnExpectedRequestException {
    // Check Arguments
    checkRequest(request);
    User userInDb = userDao.findById(request.getUserId());
    if (null == userInDb) {
        throw new UnExpectedRequestException("userId {&DOES_NOT_EXIST}");
    }
    // Find department by name.
    Department departmentInDb = departmentDao.findByName(request.getDepartmentName());
    if (null == departmentInDb) {
        throw new UnExpectedRequestException("Department of " + request.getDepartmentName() + " {&DOES_NOT_EXIST}");
    }
    userInDb.setDepartment(departmentInDb);
    // Save user
    userDao.saveUser(userInDb);
    LOGGER.info("Succeed to modify department, userId: {}, current_user: {}", userInDb.getId(), userInDb.getUserName());
    return new GeneralResponse<>("200", "{&MODIFY_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) User(com.webank.wedatasphere.qualitis.entity.User)

Aggregations

User (com.webank.wedatasphere.qualitis.entity.User)54 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)38 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)30 Transactional (org.springframework.transaction.annotation.Transactional)23 ArrayList (java.util.ArrayList)22 UserRole (com.webank.wedatasphere.qualitis.entity.UserRole)21 Department (com.webank.wedatasphere.qualitis.entity.Department)15 List (java.util.List)14 RuleMetric (com.webank.wedatasphere.qualitis.entity.RuleMetric)13 PermissionDeniedRequestException (com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException)13 GetAllResponse (com.webank.wedatasphere.qualitis.response.GetAllResponse)12 RuleMetricDepartmentUser (com.webank.wedatasphere.qualitis.entity.RuleMetricDepartmentUser)10 Project (com.webank.wedatasphere.qualitis.project.entity.Project)10 ProjectUser (com.webank.wedatasphere.qualitis.project.entity.ProjectUser)7 Application (com.webank.wedatasphere.qualitis.entity.Application)6 Task (com.webank.wedatasphere.qualitis.entity.Task)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 UserDao (com.webank.wedatasphere.qualitis.dao.UserDao)5 ApplicationResponse (com.webank.wedatasphere.qualitis.response.ApplicationResponse)5 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)5