Search in sources :

Example 21 with Project

use of com.webank.wedatasphere.qualitis.project.entity.Project 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);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) Project(com.webank.wedatasphere.qualitis.project.entity.Project) User(com.webank.wedatasphere.qualitis.entity.User) Gson(com.google.gson.Gson) ProjectDetailResponse(com.webank.wedatasphere.qualitis.project.response.ProjectDetailResponse) Transactional(org.springframework.transaction.annotation.Transactional)

Example 22 with Project

use of com.webank.wedatasphere.qualitis.project.entity.Project 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));
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) Project(com.webank.wedatasphere.qualitis.project.entity.Project) ProjectDetailResponse(com.webank.wedatasphere.qualitis.project.response.ProjectDetailResponse)

Example 23 with Project

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

the class ProjectBatchServiceImpl method getExcelMultiTemplateRuleByProject.

private List<ExcelMultiTemplateRuleByProject> getExcelMultiTemplateRuleByProject(List<Project> projects, String localeStr) {
    List<ExcelMultiTemplateRuleByProject> excelMultiTemplateRuleByProjects = new ArrayList<>();
    for (Project project : projects) {
        List<Rule> rules = ruleDao.findByProject(project);
        List<ExcelMultiTemplateRuleByProject> excelMultiTemplateRules = ruleBatchService.getMultiTemplateRule(rules, localeStr);
        for (ExcelMultiTemplateRuleByProject excelMultiTemplateRule : excelMultiTemplateRules) {
            ExcelMultiTemplateRuleByProject excelMultiTemplateRuleByProject = new ExcelMultiTemplateRuleByProject();
            BeanUtils.copyProperties(excelMultiTemplateRule, excelMultiTemplateRuleByProject);
            excelMultiTemplateRuleByProject.setProjectName(project.getName());
            LOGGER.info("Collect excel line of custom rule: {}", excelMultiTemplateRuleByProject);
            excelMultiTemplateRuleByProjects.add(excelMultiTemplateRuleByProject);
        }
    }
    return excelMultiTemplateRuleByProjects;
}
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) ExcelMultiTemplateRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelMultiTemplateRuleByProject) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule)

Example 24 with Project

use of com.webank.wedatasphere.qualitis.project.entity.Project 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)

Example 25 with Project

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

the class ProjectBatchServiceImpl method downloadProjects.

@Override
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> downloadProjects(DownloadProjectRequest request, HttpServletResponse response) throws UnExpectedRequestException, WriteExcelException, IOException, PermissionDeniedRequestException {
    // Check Arguments
    DownloadProjectRequest.checkRequest(request);
    String loginUser = HttpUtils.getUserName(httpServletRequest);
    List<Project> projectsInDb = new ArrayList<>();
    for (Long projectId : request.getProjectId()) {
        Project projectInDb = projectDao.findById(projectId);
        if (projectInDb == null) {
            throw new UnExpectedRequestException("{&PROJECT_ID} : [" + projectId + "] {&DOES_NOT_EXIST}");
        }
        // Check permissions of project
        List<Integer> permissions = new ArrayList<>();
        permissions.add(ProjectUserPermissionEnum.DEVELOPER.getCode());
        projectService.checkProjectPermission(projectInDb, loginUser, permissions);
        projectsInDb.add(projectInDb);
    }
    // Write project and rules
    return writeProjectAndRules(projectsInDb, response);
}
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) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Project (com.webank.wedatasphere.qualitis.project.entity.Project)46 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)33 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)28 Transactional (org.springframework.transaction.annotation.Transactional)25 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)22 ArrayList (java.util.ArrayList)17 User (com.webank.wedatasphere.qualitis.entity.User)13 PermissionDeniedRequestException (com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException)11 ExcelMultiTemplateRuleByProject (com.webank.wedatasphere.qualitis.project.excel.ExcelMultiTemplateRuleByProject)11 Date (java.util.Date)11 ExcelCustomRuleByProject (com.webank.wedatasphere.qualitis.project.excel.ExcelCustomRuleByProject)9 ExcelTemplateRuleByProject (com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateRuleByProject)9 RuleGroup (com.webank.wedatasphere.qualitis.rule.entity.RuleGroup)9 RuleResponse (com.webank.wedatasphere.qualitis.rule.response.RuleResponse)9 AlarmConfig (com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)8 RuleDataSource (com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource)8 IOException (java.io.IOException)8 ClusterInfoNotConfigException (com.webank.wedatasphere.qualitis.exception.ClusterInfoNotConfigException)6 TaskNotExistException (com.webank.wedatasphere.qualitis.exception.TaskNotExistException)6 MetaDataAcquireFailedException (com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException)6