use of com.webank.wedatasphere.qualitis.entity.UserRole 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.UserRole in project Qualitis by WeBankFinTech.
the class UserRoleServiceImpl method modifyUserRole.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> modifyUserRole(ModifyUserRoleRequest request) throws UnExpectedRequestException {
// Check Arguments
checkRequest(request);
// Find user role by id
String uuid = request.getUuid();
UserRole userRoleInDb = userRoleDao.findByUuid(uuid);
if (userRoleInDb == null) {
throw new UnExpectedRequestException("user role id {&DOES_NOT_EXIST}, request: " + request);
}
LOGGER.info("Succeed to find user_role, uuid: {}, user_id: {}, role_id: {}, current_user: {}", uuid, userRoleInDb.getUser().getId(), userRoleInDb.getRole().getId(), HttpUtils.getUserName(httpServletRequest));
Long userId = request.getUserId();
Long roleId = request.getRoleId();
User userInDb = userDao.findById(userId);
if (userInDb == null) {
throw new UnExpectedRequestException("userId {&DOES_NOT_EXIST}, request: " + request);
}
Role roleInDb = roleDao.findById(roleId);
if (roleInDb == null) {
throw new UnExpectedRequestException("roleId {&DOES_NOT_EXIST}, request: " + request);
}
UserRole userIdAndRoleIdInDb = userRoleDao.findByUserAndRole(userInDb, roleInDb);
if (userIdAndRoleIdInDb != null) {
throw new UnExpectedRequestException("userId and roleId {&ALREADY_EXIST}, request: " + request);
}
userRoleInDb.setUser(userInDb);
userRoleInDb.setRole(roleInDb);
UserRole savedUserRole = userRoleDao.saveUserRole(userRoleInDb);
LOGGER.info("Succeed to modify user_role, uuid: {}, user_id: {}, role_id: {}, current_user: {}", uuid, savedUserRole.getUser().getId(), savedUserRole.getRole().getId(), HttpUtils.getUserName(httpServletRequest));
return new GeneralResponse<>("200", "{&MODIFY_USER_ROLE_SUCCESSFULLY}", null);
}
use of com.webank.wedatasphere.qualitis.entity.UserRole in project Qualitis by WeBankFinTech.
the class UserRoleServiceImpl method findAllUserRole.
@Override
public GeneralResponse<GetAllResponse<UserRoleResponse>> findAllUserRole(PageRequest request) throws UnExpectedRequestException {
// Check Arguments
PageRequest.checkRequest(request);
int page = request.getPage();
int size = request.getSize();
List<UserRole> userRoles = userRoleDao.findAllUserRole(page, size);
long total = userRoleDao.countAll();
List<UserRoleResponse> userRoleResponses = new ArrayList<>();
for (UserRole userRole : userRoles) {
UserRoleResponse response = new UserRoleResponse(userRole);
userRoleResponses.add(response);
}
GetAllResponse<UserRoleResponse> responses = new GetAllResponse<>();
responses.setTotal(total);
responses.setData(userRoleResponses);
LOGGER.info("Succeed to find all user_roles, response: {}, current_user: {}", responses, HttpUtils.getUserName(httpServletRequest));
return new GeneralResponse<>("200", "{&FIND_ALL_USER_ROLES_SUCCESSFULLY}", responses);
}
use of com.webank.wedatasphere.qualitis.entity.UserRole in project Qualitis by WeBankFinTech.
the class UserRoleServiceImpl method addUserRole.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<UserRoleResponse> addUserRole(AddUserRoleRequest request) throws UnExpectedRequestException {
// Check Arguments
checkRequest(request);
// Check existence of user, role and user role
Long userId = request.getUserId();
Long roleId = request.getRoleId();
User userInDb = userDao.findById(userId);
if (userInDb == null) {
throw new UnExpectedRequestException("userId {&DOES_NOT_EXIST}, request: " + request);
}
Role roleInDb = roleDao.findById(roleId);
if (roleInDb == null) {
throw new UnExpectedRequestException("roleId {&DOES_NOT_EXIST}, request: " + request);
}
UserRole userRoleInDb = userRoleDao.findByUserAndRole(userInDb, roleInDb);
if (userRoleInDb != null) {
throw new UnExpectedRequestException("userId and roleId {&ALREADY_EXIST}, request: " + request);
}
// Save user role
UserRole newUserRole = new UserRole();
newUserRole.setRole(roleInDb);
newUserRole.setUser(userInDb);
newUserRole.setId(UuidGenerator.generate());
UserRole savedUserRole = userRoleDao.saveUserRole(newUserRole);
UserRoleResponse response = new UserRoleResponse(savedUserRole);
LOGGER.info("Succeed to add user_role: response: {}, current_user: {}", response, HttpUtils.getUserName(httpServletRequest));
return new GeneralResponse<>("200", "{&ADD_USER_ROLE_SUCCESSFULLY}", response);
}
use of com.webank.wedatasphere.qualitis.entity.UserRole in project Qualitis by WeBankFinTech.
the class ProjectServiceImpl method modifyProjectDetail.
@Override
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> modifyProjectDetail(ModifyProjectDetailRequest request, boolean workflow) throws UnExpectedRequestException, PermissionDeniedRequestException, RoleNotFoundException {
// Check Arguments
ModifyProjectDetailRequest.checkRequest(request);
// Check existence of project
Project projectInDb = projectDao.findById(request.getProjectId());
if (projectInDb == null) {
throw new UnExpectedRequestException("project id {&DOES_NOT_EXIST}");
}
LOGGER.info("Succeed to get project. project: {}", projectInDb);
// Get userId
Long userId = HttpUtils.getUserId(httpServletRequest);
User user;
if (userId == null) {
user = userDao.findByUsername(request.getUsername());
if (user == null) {
throw new UnExpectedRequestException(String.format("{&FAILED_TO_FIND_USER} %s", request.getUsername()));
}
} else {
user = userDao.findById(userId);
if (user == null) {
throw new UnExpectedRequestException(String.format("{&FAILED_TO_FIND_USER} %s", userId));
}
}
// Check if user has permission modifying project
List<Integer> permissions = new ArrayList<>();
permissions.add(ProjectUserPermissionEnum.BUSSMAN.getCode());
permissions.add(ProjectUserPermissionEnum.DEVELOPER.getCode());
checkProjectPermission(projectInDb, user.getUserName(), permissions);
// Check project name
Project otherProject = projectDao.findByNameAndCreateUser(request.getProjectName(), user.getUserName());
if (otherProject != null && !otherProject.getId().equals(projectInDb.getId())) {
throw new UnExpectedRequestException(String.format("Project name: %s already exist", request.getProjectName()));
}
// Save project.
String oldLabels = "";
String newLabels = "";
if (CollectionUtils.isNotEmpty(projectInDb.getProjectLabels())) {
oldLabels = projectInDb.getProjectLabels().stream().map(ProjectLabel::getLabelName).collect(Collectors.joining());
}
if (CollectionUtils.isNotEmpty(request.getProjectLabelStrs())) {
newLabels = request.getProjectLabelStrs().stream().collect(Collectors.joining());
}
if (!oldLabels.equals(newLabels)) {
projectEventService.recordModifyProject(projectInDb, user.getUserName(), "Project labels", oldLabels, newLabels, EventTypeEnum.MODIFY_PROJECT.getCode());
}
if (StringUtils.isNotEmpty(projectInDb.getCnName()) && !projectInDb.getCnName().equals(request.getCnName())) {
projectEventService.recordModifyProject(projectInDb, user.getUserName(), "Chinese Name", projectInDb.getCnName(), request.getCnName(), EventTypeEnum.MODIFY_PROJECT.getCode());
}
if (!projectInDb.getName().equals(request.getProjectName())) {
projectEventService.recordModifyProject(projectInDb, user.getUserName(), "English Name", projectInDb.getName(), request.getProjectName(), EventTypeEnum.MODIFY_PROJECT.getCode());
}
if (!projectInDb.getDescription().equals(request.getDescription())) {
projectEventService.recordModifyProject(projectInDb, user.getUserName(), "Describe", projectInDb.getDescription(), request.getDescription(), EventTypeEnum.MODIFY_PROJECT.getCode());
}
projectInDb.setCnName(request.getCnName());
projectInDb.setName(request.getProjectName());
projectInDb.setDescription(request.getDescription());
// Delete old projectLabel.
projectLabelDao.deleteByProject(projectInDb);
LOGGER.info("Succeed to delete all project_label, project_id: {}", request.getProjectId());
// Create new project labels.
addProjectLabels(request.getProjectLabelStrs(), projectInDb);
// Record modify user
projectInDb.setModifyUser(user.getUserName());
projectInDb.setModifyTime(ExecutionManagerImpl.PRINT_TIME_FORMAT.format(new Date()));
Project savedProject = projectDao.saveProject(projectInDb);
LOGGER.info("Succeed to modify project. project: {}", savedProject);
if (workflow) {
// Clear old project user.
List<ProjectUser> projectUsers = projectUserDao.findByProject(projectInDb);
Role role = roleDao.findByRoleName(ADMIN);
List<String> admins = userRoleDao.findByRole(role).stream().map(UserRole::getUser).map(User::getUserName).collect(Collectors.toList());
projectUsers = projectUsers.stream().filter(projectUser -> !admins.contains(projectUser.getUserName())).filter(projectUser -> !projectUser.getUserName().equals(request.getUsername())).collect(Collectors.toList());
for (ProjectUser projectUser : projectUsers) {
projectUserDao.deleteByProjectAndUserName(projectInDb, projectUser.getUserName());
}
}
authorizeUsers(projectInDb, user, request.getAuthorizeProjectUserRequests(), true);
return new GeneralResponse<>("200", "{&MODIFY_PROJECT_DETAIL_SUCCESSFULLY}", new ProjectDetailResponse(savedProject, null));
}
Aggregations