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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations