Search in sources :

Example 6 with Project

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

the class ProjectServiceImpl method addProjectReal.

@Override
public Project addProjectReal(Long userId, String projectName, String cnName, String projectDescription) throws UnExpectedRequestException {
    User user = userDao.findById(userId);
    // Automatically grant the highest authority to the system administrator.
    Role role = roleDao.findByRoleName(ADMIN);
    List<User> admins = userRoleDao.findByRole(role).stream().map(UserRole::getUser).collect(Collectors.toList());
    // Check existence of project by project name.
    Project projectInDb = projectDao.findByNameAndCreateUser(projectName, user.getUserName());
    if (projectInDb != null) {
        throw new UnExpectedRequestException(String.format("{&PROJECT}:%s {&ALREADY_EXIST}", projectName));
    }
    // Save project.
    Project newProject = new Project(projectName, cnName, projectDescription, user.getUserName(), user.getChineseName(), user.getDepartment() != null ? user.getDepartment().getName() : "", ExecutionManagerImpl.PRINT_TIME_FORMAT.format(new Date()));
    // Create project user.
    if (admins.contains(user)) {
        createProjectUser(newProject, user);
    } else {
        createProjectUser(newProject, user);
        for (User currentAdmin : admins) {
            createProjectUser(newProject, currentAdmin);
        }
    }
    return newProject;
}
Also used : Role(com.webank.wedatasphere.qualitis.entity.Role) UserRole(com.webank.wedatasphere.qualitis.entity.UserRole) Project(com.webank.wedatasphere.qualitis.project.entity.Project) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) User(com.webank.wedatasphere.qualitis.entity.User) ProjectUser(com.webank.wedatasphere.qualitis.project.entity.ProjectUser)

Example 7 with Project

use of com.webank.wedatasphere.qualitis.project.entity.Project 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);
}
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) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with Project

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

the class FileRuleServiceImpl method addRuleReal.

private GeneralResponse<RuleResponse> addRuleReal(AddFileRuleRequest request, String loginUser) throws UnExpectedRequestException, PermissionDeniedRequestException {
    // Check Arguments
    AddFileRuleRequest.checkRequest(request, false);
    // Generate Template, TemplateOutputMeta and save
    Template template = ruleTemplateService.addFileTemplate(request);
    // Check existence of project
    Project projectInDb = projectService.checkProjectExistence(request.getProjectId(), loginUser);
    String nowDate = ExecutionManagerImpl.PRINT_TIME_FORMAT.format(new Date());
    // Check permissions of project
    List<Integer> permissions = new ArrayList<>();
    permissions.add(ProjectUserPermissionEnum.DEVELOPER.getCode());
    projectService.checkProjectPermission(projectInDb, loginUser, permissions);
    // Check unique of rule name
    ruleService.checkRuleName(request.getRuleName(), projectInDb, null);
    // Check cluster support
    ruleDataSourceService.checkDataSourceClusterSupport(request.getDatasource().getClusterName());
    RuleGroup ruleGroup;
    if (request.getRuleGroupId() != null) {
        ruleGroup = ruleGroupDao.findById(request.getRuleGroupId());
        if (ruleGroup == null) {
            throw new UnExpectedRequestException(String.format("Rule Group: %s {&DOES_NOT_EXIST}", request.getRuleGroupId()));
        }
    } else {
        ruleGroup = ruleGroupDao.saveRuleGroup(new RuleGroup("Group_" + UUID.randomUUID().toString().replace("-", ""), projectInDb.getId()));
    }
    // Save rule.
    Rule newRule = new Rule();
    newRule.setRuleType(RuleTypeEnum.FILE_TEMPLATE_RULE.getCode());
    newRule.setTemplate(template);
    newRule.setName(request.getRuleName());
    newRule.setCnName(request.getRuleCnName());
    newRule.setDetail(request.getRuleDetail());
    newRule.setAlarm(request.getAlarm());
    newRule.setProject(projectInDb);
    newRule.setRuleTemplateName(template.getName());
    newRule.setRuleGroup(ruleGroup);
    newRule.setAbortOnFailure(request.getAbortOnFailure());
    newRule.setCreateUser(loginUser);
    newRule.setCreateTime(nowDate);
    String csId = request.getCsId();
    boolean cs = false;
    if (StringUtils.isNotBlank(csId)) {
        newRule.setCsId(csId);
        cs = true;
    }
    Rule savedRule = ruleDao.saveRule(newRule);
    LOGGER.info("Succeed to save file rule, rule_id: {}", savedRule.getId());
    List<AlarmConfig> savedAlarmConfigs = new ArrayList<>();
    if (request.getAlarm()) {
        savedAlarmConfigs = alarmConfigService.checkAndSaveFileAlarmVariable(request.getAlarmVariable(), savedRule);
        LOGGER.info("Succeed to save alarm_configs, alarm_configs: {}", savedAlarmConfigs);
    }
    List<RuleDataSource> ruleDataSources = new ArrayList<>();
    ruleDataSources.add(ruleDataSourceService.checkAndSaveFileRuleDataSource(request.getDatasource(), savedRule, cs));
    savedRule.setAlarmConfigs(new HashSet<>(savedAlarmConfigs));
    savedRule.setRuleDataSources(new HashSet<>(ruleDataSources));
    // Update rule count of datasource
    ruleDataSourceService.updateRuleDataSourceCount(savedRule, 1);
    RuleResponse response = new RuleResponse(savedRule);
    LOGGER.info("Succeed to add file rule, rule_id: {}", savedRule.getId());
    return new GeneralResponse<>("200", "{&SUCCEED_TO_ADD_FILE_RULE}", response);
}
Also used : UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) RuleDataSource(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource) RuleResponse(com.webank.wedatasphere.qualitis.rule.response.RuleResponse) ArrayList(java.util.ArrayList) Date(java.util.Date) RuleGroup(com.webank.wedatasphere.qualitis.rule.entity.RuleGroup) Template(com.webank.wedatasphere.qualitis.rule.entity.Template) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) Project(com.webank.wedatasphere.qualitis.project.entity.Project) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) AlarmConfig(com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)

Example 9 with Project

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

the class FileRuleServiceImpl method deleteRule.

@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> deleteRule(DeleteFileRuleRequest request) throws UnExpectedRequestException, PermissionDeniedRequestException {
    // Check Arguments
    DeleteFileRuleRequest.checkRequest(request);
    // Check existence of rule
    Rule ruleInDb = ruleDao.findById(request.getRuleId());
    if (ruleInDb == null || !ruleInDb.getRuleType().equals(RuleTypeEnum.FILE_TEMPLATE_RULE.getCode())) {
        throw new UnExpectedRequestException("Rule id [" + request.getRuleId() + "]) {&IS_NOT_A_RULE_WITH_TEMPLATE}");
    }
    ruleDataSourceService.updateRuleDataSourceCount(ruleInDb, -1);
    String loginUser = HttpUtils.getUserName(httpServletRequest);
    Project projectInDb = projectService.checkProjectExistence(ruleInDb.getProject().getId(), loginUser);
    // Check permissions of project
    List<Integer> permissions = new ArrayList<>();
    permissions.add(ProjectUserPermissionEnum.DEVELOPER.getCode());
    projectService.checkProjectPermission(projectInDb, loginUser, permissions);
    // Update rule count of datasource
    ruleDataSourceService.updateRuleDataSourceCount(ruleInDb, -1);
    return deleteRuleReal(ruleInDb);
}
Also used : UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) Project(com.webank.wedatasphere.qualitis.project.entity.Project) ArrayList(java.util.ArrayList) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with Project

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

the class MultiSourceRuleServiceImpl method deleteMultiSourceRule.

@Override
@Transactional(rollbackFor = { UnExpectedRequestException.class, Exception.class })
public GeneralResponse<?> deleteMultiSourceRule(DeleteMultiSourceRequest request) throws UnExpectedRequestException, PermissionDeniedRequestException {
    // Check Arguments
    DeleteMultiSourceRequest.checkRequest(request);
    String loginUser = HttpUtils.getUserName(httpServletRequest);
    // Check existence of rule and check if multi-table rule
    Rule ruleInDb = ruleDao.findById(request.getMultiRuleId());
    if (ruleInDb == null) {
        throw new UnExpectedRequestException("rule_id [" + request.getMultiRuleId() + "] {&DOES_NOT_EXIST}");
    }
    // Check existence of project
    Project projectInDb = projectService.checkProjectExistence(ruleInDb.getProject().getId(), loginUser);
    // Check permissions of project
    List<Integer> permissions = new ArrayList<>();
    permissions.add(ProjectUserPermissionEnum.DEVELOPER.getCode());
    projectService.checkProjectPermission(projectInDb, loginUser, permissions);
    if (!ruleInDb.getRuleType().equals(RuleTypeEnum.MULTI_TEMPLATE_RULE.getCode())) {
        throw new UnExpectedRequestException("rule_id: [" + request.getMultiRuleId() + "]) {&IS_NOT_A_MULTI_TEMPLATE_RULE}");
    }
    // Update rule count of datasource
    ruleDataSourceService.updateRuleDataSourceCount(ruleInDb, -1);
    // Delete rule
    return deleteMultiRuleReal(ruleInDb);
}
Also used : UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) Project(com.webank.wedatasphere.qualitis.project.entity.Project) 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