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