use of com.webank.wedatasphere.qualitis.project.response.ProjectDetailResponse in project Qualitis by WeBankFinTech.
the class ProjectServiceImpl method addProject.
@Override
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<ProjectDetailResponse> addProject(AddProjectRequest request, Long userId) throws UnExpectedRequestException {
// Check Arguments.
AddProjectRequest.checkRequest(request);
Project newProject = addProjectReal(userId, request.getProjectName(), request.getCnName(), request.getDescription());
newProject.setProjectType(ProjectTypeEnum.NORMAL_PROJECT.getCode());
Project savedProject = projectDao.saveProject(newProject);
// Labels of project.
Set<String> labels = request.getProjectLabels();
addProjectLabels(labels, savedProject);
ProjectDetailResponse response = new ProjectDetailResponse(savedProject, null);
LOGGER.info("Succeed to add project, response: {}", response);
return new GeneralResponse<>("200", "{&ADD_PROJECT_SUCCESSFULLY}", response);
}
use of com.webank.wedatasphere.qualitis.project.response.ProjectDetailResponse in project Qualitis by WeBankFinTech.
the class ProjectServiceImpl method getProjectDetail.
@Override
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<ProjectDetailResponse> getProjectDetail(Long projectId, PageRequest pageRequest) throws UnExpectedRequestException, PermissionDeniedRequestException {
// Check existence of project
Project projectInDb = projectDao.findById(projectId);
if (projectInDb == null) {
throw new UnExpectedRequestException("Project id {&DOES_NOT_EXIST}");
}
String username = HttpUtils.getUserName(httpServletRequest);
// Check if user has permission get project.
List<Integer> permissions = new ArrayList<>();
permissions.add(ProjectUserPermissionEnum.BUSSMAN.getCode());
checkProjectPermission(projectInDb, username, permissions);
// Find rules by project
List<Rule> rules = ruleDao.findByProjectWithPage(projectInDb, pageRequest.getPage(), pageRequest.getSize());
int total = ruleDao.countByProject(projectInDb);
ProjectDetailResponse projectDetailResponse = new ProjectDetailResponse(projectInDb, rules);
projectDetailResponse.setTotal(total);
LOGGER.info("Succeed to get get project detail. project_id: {}, response: {}", projectId, projectDetailResponse);
return new GeneralResponse<>("200", "{&GET_PROJECT_DETAIL_SUCCESSFULLY}", projectDetailResponse);
}
use of com.webank.wedatasphere.qualitis.project.response.ProjectDetailResponse 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));
}
use of com.webank.wedatasphere.qualitis.project.response.ProjectDetailResponse in project Qualitis by WeBankFinTech.
the class OuterWorkflowProjectServiceImpl method addWorkflowProject.
@Override
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { RuntimeException.class, UnExpectedRequestException.class, RoleNotFoundException.class })
public GeneralResponse<ProjectDetailResponse> addWorkflowProject(AddProjectRequest request, String username) throws UnExpectedRequestException, RoleNotFoundException, PermissionDeniedRequestException {
LOGGER.info("Add workflow project request: " + new Gson().toJson(request));
// Check Arguments
Set<String> labels = request.getProjectLabels();
AddProjectRequest.checkRequest(request);
if (request.getUsername() == null) {
throw new UnExpectedRequestException("Username: {&CAN_NOT_BE_NULL_OR_EMPTY}");
}
// Check existence of user
User userInDb = userDao.findByUsername(username);
if (userInDb == null) {
userService.autoAddUser(username);
userInDb = userDao.findByUsername(username);
}
// Check existence of project by project name.
Project projectInDb = projectDao.findByNameAndCreateUser(request.getProjectName(), username);
boolean needSuffix = false;
if (projectInDb != null) {
if (projectInDb.getProjectType().equals(ProjectTypeEnum.WORKFLOW_PROJECT.getCode())) {
ProjectDetailResponse response = new ProjectDetailResponse(projectInDb, null);
LOGGER.info("Succeed to find exists workflow project, response: {}", response);
return new GeneralResponse<>("200", "{&GET_PROJECT_DETAIL_SUCCESSFULLY}", response);
} else {
needSuffix = true;
}
}
Project newProject = projectService.addProjectReal(userInDb.getId(), needSuffix ? request.getProjectName() + "_workflow" : request.getProjectName(), request.getCnName(), request.getDescription());
newProject.setProjectType(ProjectTypeEnum.WORKFLOW_PROJECT.getCode());
Project savedProject = projectDao.saveProject(newProject);
projectService.addProjectLabels(labels, savedProject);
// Authorized users.
projectService.authorizeUsers(savedProject, userInDb, request.getAuthorizeProjectUserRequests(), false);
ProjectDetailResponse response = new ProjectDetailResponse(savedProject, null);
LOGGER.info("Succeed to add workflow project, response: {}", response);
return new GeneralResponse<>("200", "{&ADD_PROJECT_SUCCESSFULLY}", response);
}
use of com.webank.wedatasphere.qualitis.project.response.ProjectDetailResponse in project Qualitis by WeBankFinTech.
the class OuterWorkflowProjectServiceImpl method getWorkflowProject.
@Override
public GeneralResponse<ProjectDetailResponse> getWorkflowProject(GetProjectRequest request) throws UnExpectedRequestException {
GetProjectRequest.checkRequest(request);
Project projectInDb = projectDao.findByNameAndCreateUser(request.getName(), request.getUsername());
if (projectInDb == null) {
return new GeneralResponse<>("200", "{&GET_PROJECT_DETAIL_SUCCESSFULLY}", new ProjectDetailResponse(Long.parseLong("-1")));
}
return new GeneralResponse<>("200", "{&GET_PROJECT_DETAIL_SUCCESSFULLY}", new ProjectDetailResponse(projectInDb));
}
Aggregations