use of com.webank.wedatasphere.qualitis.project.entity.ProjectUser in project Qualitis by WeBankFinTech.
the class RuleQueryServiceImpl method query.
/**
* Query rule by creator
*
* @param queryParam
* @return List<RuleQueryProject>
*/
@Override
public List<RuleQueryProject> query(RuleQueryRequest queryParam) {
DataSourceQo param = new DataSourceQo(queryParam);
// Query project user by creator
List<ProjectUser> projectUsers = projectUserDao.findByUsernameAndPermissionsIn(param);
boolean projectUsersNull = (projectUsers == null || projectUsers.isEmpty());
if (projectUsersNull) {
LOGGER.info("[My DataSource] Find no projects of user:{},", queryParam.getUser());
return null;
}
Map<Long, RuleQueryProject> projectMap = new HashMap<>(4);
getProjectsByUserPerm(param, projectUsers, projectMap);
if (projectMap.values().isEmpty()) {
LOGGER.info("[My DataSource] Find no datasources/rules of user, user: {}", queryParam.getUser());
return null;
}
return new ArrayList<>(projectMap.values());
}
use of com.webank.wedatasphere.qualitis.project.entity.ProjectUser in project Qualitis by WeBankFinTech.
the class ProjectUserServiceImpl method getAllProjectUser.
@Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = true, rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<List<ProjectUserResponse>> getAllProjectUser(Long projectId) throws UnExpectedRequestException, PermissionDeniedRequestException {
List<ProjectUserResponse> projectUserResponses = new ArrayList<>();
Project projectInDb = projectDao.findById(projectId);
if (projectInDb == null) {
throw new UnExpectedRequestException("{&PROJECT}: [ID=" + projectId + "] {&DOES_NOT_EXIST}");
}
String userName = HttpUtils.getUserName(httpRequest);
List<ProjectUser> projectUsers = projectUserDao.findByProject(projectInDb);
List<String> projectUserNames = projectUsers.stream().map(ProjectUser::getUserName).collect(Collectors.toList());
if (!projectUserNames.contains(userName)) {
throw new PermissionDeniedRequestException("{&HAS_NO_PERMISSION_TO_ACCESS}", 403);
}
for (ProjectUser currentProjectUser : projectUsers) {
List<String> userNames = projectUserResponses.stream().map(ProjectUserResponse::getAuthorizedUser).collect(Collectors.toList());
String currentUser = currentProjectUser.getUserName();
if (userNames.contains(currentUser)) {
continue;
}
String projectCreator = projectInDb.getCreateUser();
ProjectUserResponse projectUserResponse = new ProjectUserResponse(projectInDb.getName(), projectCreator, currentUser);
List<Integer> permissions = getPermissionList(projectUsers, currentUser);
projectUserResponse.setPermissions(permissions);
projectUserResponses.add(projectUserResponse);
}
return new GeneralResponse<>("200", "{&SUCCESS_TO_GET_PROJECT_USER}", projectUserResponses);
}
use of com.webank.wedatasphere.qualitis.project.entity.ProjectUser in project Qualitis by WeBankFinTech.
the class PredicateTest method test.
@Test
@Transactional
public void test() {
String user = "v_wblwyan_test1";
/*
* ProjectUserDao测试
*/
DataSourceQo param = new DataSourceQo();
param.setUser(user);
param.setUserType(new Integer[] { ProjectUserPermissionEnum.CREATOR.getCode() });
List<ProjectUser> projectUsers = dao.findByUsernameAndPermissionsIn(param);
assertTrue(projectUsers.isEmpty());
param.setUserType(new Integer[] { ProjectUserPermissionEnum.CREATOR.getCode() });
projectUsers = dao.findByUsernameAndPermissionsIn(param);
assertTrue(projectUsers.isEmpty());
param.setUserType(null);
projectUsers = dao.findByUsernameAndPermissionsIn(param);
assertTrue(projectUsers.isEmpty());
param.setUserType(new Integer[] {});
projectUsers = dao.findByUsernameAndPermissionsIn(param);
assertTrue(projectUsers.isEmpty());
/*
*TaskDataSourceDao 测试
*/
List<TaskDataSource> taskDataSources = taskDataSourceDao.findByUserAndDataSource(user, null, null, null, 0, 5);
assertTrue(taskDataSources.isEmpty());
taskDataSources = taskDataSourceDao.findByUserAndDataSource(user, "clusterName_test", null, null, 0, 5);
assertTrue(taskDataSources.isEmpty());
taskDataSources = taskDataSourceDao.findByUserAndDataSource(user, "clusterName_test", "databaseName_test", null, 0, 5);
assertTrue(taskDataSources.isEmpty());
taskDataSources = taskDataSourceDao.findByUserAndDataSource(user, "clusterName_test", "databaseName_test", "tableName_test", 0, 5);
assertTrue(taskDataSources.isEmpty());
long count = taskDataSourceDao.countByUserAndDataSource(user, "clusterName_test", "databaseName_test", null);
assertEquals(0, count);
/*
*RuleDataSourceDao 测试
*/
List<RuleDataSource> ruleDataSources = ruleDataSourceDao.findByProjectUser((long) Integer.MAX_VALUE, null, null, null);
assertTrue(ruleDataSources.isEmpty());
ruleDataSources = ruleDataSourceDao.findByProjectUser((long) Integer.MAX_VALUE, "clusterName_test", null, null);
assertTrue(ruleDataSources.isEmpty());
ruleDataSources = ruleDataSourceDao.findByProjectUser((long) Integer.MAX_VALUE, "clusterName_test", "databaseName_test", null);
assertTrue(ruleDataSources.isEmpty());
ruleDataSources = ruleDataSourceDao.findByProjectUser((long) Integer.MAX_VALUE, "clusterName_test", "databaseName_test", "tableName_test");
assertTrue(ruleDataSources.isEmpty());
}
use of com.webank.wedatasphere.qualitis.project.entity.ProjectUser in project Qualitis by WeBankFinTech.
the class ProjectServiceImpl method createProjectUser.
@Override
public void createProjectUser(Project project, User user) {
Map<String, ProjectUser> projectUserMap = new HashMap<>(4);
ProjectUser creatorProject = new ProjectUser(ProjectUserPermissionEnum.CREATOR.getCode(), project, user.getUserName(), user.getChineseName());
projectUserMap.put(user.getUserName(), creatorProject);
projectUserDao.saveAll(projectUserMap.values());
LOGGER.info("Succeed to save project_user, project_user: {}", projectUserMap.values());
}
use of com.webank.wedatasphere.qualitis.project.entity.ProjectUser 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