Search in sources :

Example 1 with ProjectLabel

use of com.webank.wedatasphere.qualitis.project.entity.ProjectLabel in project Qualitis by WeBankFinTech.

the class ProjectServiceImpl method addProjectLabels.

@Override
public void addProjectLabels(Set<String> labels, Project project) {
    Map<String, ProjectLabel> map = new HashMap<>(2);
    if (project.getProjectLabels() != null) {
        for (ProjectLabel projectLabel : project.getProjectLabels()) {
            map.put(projectLabel.getLabelName(), projectLabel);
        }
    } else {
        project.setProjectLabels(new HashSet<>());
    }
    if (labels != null && !labels.isEmpty()) {
        Set<ProjectLabel> projectLabels = new HashSet<>();
        for (String labelName : labels) {
            if (map.keySet().contains(labelName)) {
                continue;
            }
            ProjectLabel projectLabel = new ProjectLabel();
            projectLabel.setProject(project);
            projectLabel.setLabelName(labelName);
            projectLabels.add(projectLabel);
        }
        LOGGER.info("Start to save project labels. Labels: {}", Arrays.toString(projectLabels.toArray()));
        projectLabelDao.saveAll(projectLabels);
        for (Iterator<String> iterator = map.keySet().iterator(); iterator.hasNext(); ) {
            if (!labels.contains(iterator.next())) {
                iterator.remove();
            }
        }
        project.setProjectLabels(new HashSet<>(map.values()));
        LOGGER.info("Succeed to save project labels.");
    } else {
        project.setProjectLabels(null);
    }
}
Also used : ProjectLabel(com.webank.wedatasphere.qualitis.project.entity.ProjectLabel)

Example 2 with ProjectLabel

use of com.webank.wedatasphere.qualitis.project.entity.ProjectLabel 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));
}
Also used : Role(com.webank.wedatasphere.qualitis.entity.Role) ProjectEventDao(com.webank.wedatasphere.qualitis.project.dao.ProjectEventDao) ProjectEvent(com.webank.wedatasphere.qualitis.project.entity.ProjectEvent) LoggerFactory(org.slf4j.LoggerFactory) ProjectLabel(com.webank.wedatasphere.qualitis.project.entity.ProjectLabel) Autowired(org.springframework.beans.factory.annotation.Autowired) ProjectUserDao(com.webank.wedatasphere.qualitis.project.dao.ProjectUserDao) StringUtils(org.apache.commons.lang3.StringUtils) PermissionDeniedRequestException(com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException) DeleteFileRuleRequest(com.webank.wedatasphere.qualitis.rule.request.DeleteFileRuleRequest) EventTypeEnum(com.webank.wedatasphere.qualitis.project.constant.EventTypeEnum) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) DeleteRuleRequest(com.webank.wedatasphere.qualitis.rule.request.DeleteRuleRequest) HttpUtils(com.webank.wedatasphere.qualitis.util.HttpUtils) AddProjectRequest(com.webank.wedatasphere.qualitis.project.request.AddProjectRequest) GetAllResponse(com.webank.wedatasphere.qualitis.response.GetAllResponse) ProjectService(com.webank.wedatasphere.qualitis.project.service.ProjectService) ProjectEventService(com.webank.wedatasphere.qualitis.project.service.ProjectEventService) ProjectDetailResponse(com.webank.wedatasphere.qualitis.project.response.ProjectDetailResponse) Context(javax.ws.rs.core.Context) ProjectUserPermissionEnum(com.webank.wedatasphere.qualitis.project.constant.ProjectUserPermissionEnum) PageRequest(com.webank.wedatasphere.qualitis.request.PageRequest) CustomRuleService(com.webank.wedatasphere.qualitis.rule.service.CustomRuleService) Collectors(java.util.stream.Collectors) ExecutionManagerImpl(com.webank.wedatasphere.qualitis.submitter.impl.ExecutionManagerImpl) RuleService(com.webank.wedatasphere.qualitis.rule.service.RuleService) RoleNotFoundException(javax.management.relation.RoleNotFoundException) RoleDao(com.webank.wedatasphere.qualitis.dao.RoleDao) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) ProjectEventResponse(com.webank.wedatasphere.qualitis.project.response.ProjectEventResponse) java.util(java.util) Project(com.webank.wedatasphere.qualitis.project.entity.Project) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole) UserRoleDao(com.webank.wedatasphere.qualitis.dao.UserRoleDao) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) ProjectDao(com.webank.wedatasphere.qualitis.project.dao.ProjectDao) HttpServletRequest(javax.servlet.http.HttpServletRequest) User(com.webank.wedatasphere.qualitis.entity.User) CollectionUtils(org.apache.commons.collections.CollectionUtils) Propagation(org.springframework.transaction.annotation.Propagation) Service(org.springframework.stereotype.Service) ProjectLabelDao(com.webank.wedatasphere.qualitis.project.dao.ProjectLabelDao) AuthorizeProjectUserRequest(com.webank.wedatasphere.qualitis.project.request.AuthorizeProjectUserRequest) ModifyProjectDetailRequest(com.webank.wedatasphere.qualitis.project.request.ModifyProjectDetailRequest) DeleteProjectRequest(com.webank.wedatasphere.qualitis.project.request.DeleteProjectRequest) Logger(org.slf4j.Logger) ProjectTypeEnum(com.webank.wedatasphere.qualitis.project.constant.ProjectTypeEnum) ProjectUser(com.webank.wedatasphere.qualitis.project.entity.ProjectUser) RuleTypeEnum(com.webank.wedatasphere.qualitis.rule.constant.RuleTypeEnum) FileRuleService(com.webank.wedatasphere.qualitis.rule.service.FileRuleService) ProjectResponse(com.webank.wedatasphere.qualitis.project.response.ProjectResponse) DeleteMultiSourceRequest(com.webank.wedatasphere.qualitis.rule.request.multi.DeleteMultiSourceRequest) MultiSourceRuleService(com.webank.wedatasphere.qualitis.rule.service.MultiSourceRuleService) DeleteCustomRuleRequest(com.webank.wedatasphere.qualitis.rule.request.DeleteCustomRuleRequest) RuleDao(com.webank.wedatasphere.qualitis.rule.dao.RuleDao) ProjectUserService(com.webank.wedatasphere.qualitis.project.service.ProjectUserService) UserDao(com.webank.wedatasphere.qualitis.dao.UserDao) Transactional(org.springframework.transaction.annotation.Transactional) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) ProjectUser(com.webank.wedatasphere.qualitis.project.entity.ProjectUser) User(com.webank.wedatasphere.qualitis.entity.User) ProjectUser(com.webank.wedatasphere.qualitis.project.entity.ProjectUser) ProjectLabel(com.webank.wedatasphere.qualitis.project.entity.ProjectLabel) Role(com.webank.wedatasphere.qualitis.entity.Role) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) Project(com.webank.wedatasphere.qualitis.project.entity.Project) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole) ProjectDetailResponse(com.webank.wedatasphere.qualitis.project.response.ProjectDetailResponse) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with ProjectLabel

use of com.webank.wedatasphere.qualitis.project.entity.ProjectLabel in project Qualitis by WeBankFinTech.

the class ProjectBatchServiceImpl method getExcelProject.

private List<ExcelProject> getExcelProject(List<Project> projects) {
    List<ExcelProject> excelProjects = new ArrayList<>();
    for (Project project : projects) {
        ExcelProject excelProject = new ExcelProject();
        excelProject.setProjectName(project.getName());
        excelProject.setProjectDescription(project.getDescription());
        Set<ProjectLabel> projectLabels = project.getProjectLabels();
        StringBuffer labelBuffer = new StringBuffer();
        if (projectLabels != null && !projectLabels.isEmpty()) {
            for (ProjectLabel projectLabel : projectLabels) {
                labelBuffer.append(projectLabel.getLabelName() + " ");
            }
            excelProject.setProjectLabels(labelBuffer.toString());
        }
        LOGGER.info("Collect excel line: {}", excelProject);
        excelProjects.add(excelProject);
    }
    return excelProjects;
}
Also used : ExcelMultiTemplateRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelMultiTemplateRuleByProject) ExcelCustomRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelCustomRuleByProject) ExcelTemplateRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateRuleByProject) Project(com.webank.wedatasphere.qualitis.project.entity.Project) ProjectLabel(com.webank.wedatasphere.qualitis.project.entity.ProjectLabel)

Aggregations

ProjectLabel (com.webank.wedatasphere.qualitis.project.entity.ProjectLabel)3 Project (com.webank.wedatasphere.qualitis.project.entity.Project)2 RoleDao (com.webank.wedatasphere.qualitis.dao.RoleDao)1 UserDao (com.webank.wedatasphere.qualitis.dao.UserDao)1 UserRoleDao (com.webank.wedatasphere.qualitis.dao.UserRoleDao)1 Role (com.webank.wedatasphere.qualitis.entity.Role)1 User (com.webank.wedatasphere.qualitis.entity.User)1 UserRole (com.webank.wedatasphere.qualitis.entity.UserRole)1 PermissionDeniedRequestException (com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException)1 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)1 EventTypeEnum (com.webank.wedatasphere.qualitis.project.constant.EventTypeEnum)1 ProjectTypeEnum (com.webank.wedatasphere.qualitis.project.constant.ProjectTypeEnum)1 ProjectUserPermissionEnum (com.webank.wedatasphere.qualitis.project.constant.ProjectUserPermissionEnum)1 ProjectDao (com.webank.wedatasphere.qualitis.project.dao.ProjectDao)1 ProjectEventDao (com.webank.wedatasphere.qualitis.project.dao.ProjectEventDao)1 ProjectLabelDao (com.webank.wedatasphere.qualitis.project.dao.ProjectLabelDao)1 ProjectUserDao (com.webank.wedatasphere.qualitis.project.dao.ProjectUserDao)1 ProjectEvent (com.webank.wedatasphere.qualitis.project.entity.ProjectEvent)1 ProjectUser (com.webank.wedatasphere.qualitis.project.entity.ProjectUser)1 ExcelCustomRuleByProject (com.webank.wedatasphere.qualitis.project.excel.ExcelCustomRuleByProject)1