Search in sources :

Example 6 with RuleResponse

use of com.webank.wedatasphere.qualitis.rule.response.RuleResponse in project Qualitis by WeBankFinTech.

the class MultiSourceRuleServiceImpl method modifyRuleDetailReal.

private GeneralResponse<RuleResponse> modifyRuleDetailReal(ModifyMultiSourceRequest request, String loginUser) throws UnExpectedRequestException, PermissionDeniedRequestException {
    // Check Arguments
    CommonChecker.checkObject(request, "request");
    String csId = request.getCsId();
    boolean cs = false;
    if (StringUtils.isNotBlank(csId)) {
        cs = true;
    }
    ModifyMultiSourceRequest.checkRequest(request, cs);
    // Check existence of rule
    Rule ruleInDb = ruleDao.findById(request.getRuleId());
    if (ruleInDb == null) {
        throw new UnExpectedRequestException("rule_id [" + request.getRuleId() + "] {&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.getRuleId() + "]) {&IS_NOT_A_MULTI_TEMPLATE_RULE}");
    }
    LOGGER.info("Succeed to find multi rule. rule_id: {}", ruleInDb.getId());
    // Check existence of project name
    ruleService.checkRuleName(request.getRuleName(), ruleInDb.getProject(), ruleInDb.getId());
    // Check if cluster name supported
    ruleDataSourceService.checkDataSourceClusterSupport(request.getClusterName());
    // Check existence of rule id and if multi-table rule
    Template templateInDb = ruleTemplateService.checkRuleTemplate(request.getMultiSourceRuleTemplateId());
    if (!templateInDb.getTemplateType().equals(RuleTemplateTypeEnum.MULTI_SOURCE_TEMPLATE.getCode())) {
        throw new UnExpectedRequestException("Template id :" + request.getMultiSourceRuleTemplateId() + " {&IS_NOT_A_MULTI_SOURCE_TEMPLATE}");
    }
    // Delete rule config by rule
    alarmConfigService.deleteByRule(ruleInDb);
    LOGGER.info("Succeed to delete all alarm_config. rule_id: {}", ruleInDb.getId());
    // Delete rule datasource by rule
    ruleDataSourceService.deleteByRule(ruleInDb);
    LOGGER.info("Succeed to delete all rule_dataSources. rule_id: {}", ruleInDb.getId());
    // Update rule count of datasource
    ruleDataSourceService.updateRuleDataSourceCount(ruleInDb, -1);
    // Delete rule datasource mapping by rule
    ruleDataSourceMappingService.deleteByRule(ruleInDb);
    LOGGER.info("Succeed to delete all rule_dataSource_mapping. rule_id: {}", ruleInDb.getId());
    // Delete rule variable by rule
    ruleVariableService.deleteByRule(ruleInDb);
    LOGGER.info("Succeed to delete all rule_variable. rule_id: {}", ruleInDb.getId());
    // Delete child rule
    if (ruleInDb.getChildRule() != null) {
        ruleDao.deleteRule(ruleInDb.getChildRule());
        LOGGER.info("Succeed to delete all child rule. rule_id: {}", ruleInDb.getId());
    }
    AddMultiSourceRuleRequest addMultiSourceRuleRequest = new AddMultiSourceRuleRequest();
    BeanUtils.copyProperties(request, addMultiSourceRuleRequest);
    String leftUuid = UuidGenerator.generate();
    String rightUuid = UuidGenerator.generate();
    Rule savedRule = generateRule(addMultiSourceRuleRequest, projectInDb, true, ruleInDb, false, cs, leftUuid, rightUuid, loginUser);
    if (templateInDb.getChildTemplate() != null) {
        // Generate child rule
        AddMultiSourceRuleRequest childRequest = generateChildRequest(addMultiSourceRuleRequest, templateInDb.getChildTemplate());
        Rule childRule = generateRule(childRequest, null, false, null, true, cs, leftUuid, rightUuid, loginUser);
        childRule.setParentRule(savedRule);
        ruleDao.saveRule(childRule);
        LOGGER.info("Succeed to generate child rule");
    }
    RuleResponse response = new RuleResponse(savedRule);
    LOGGER.info("Succeed to modify multi source rule, rule_id: {}", savedRule.getId());
    // projectEventService.record(savedRule.getProject().getId(), loginUser, "modify", "multi source rule[name= " + savedRule.getName() + "].", EventTypeEnum.MODIFY_PROJECT.getCode());
    return new GeneralResponse<>("200", "{&MODIFY_MULTI_RULE_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) RuleResponse(com.webank.wedatasphere.qualitis.rule.response.RuleResponse)

Example 7 with RuleResponse

use of com.webank.wedatasphere.qualitis.rule.response.RuleResponse in project Qualitis by WeBankFinTech.

the class RuleServiceImpl method addRuleReal.

private GeneralResponse<RuleResponse> addRuleReal(AddRuleRequest request, String loginUser) throws UnExpectedRequestException, PermissionDeniedRequestException {
    // Check Arguments
    AddRuleRequest.checkRequest(request, false);
    // Check existence of rule template
    Template templateInDb = ruleTemplateService.checkRuleTemplate(request.getRuleTemplateId());
    // Check datasource size
    checkDataSourceNumber(templateInDb, request.getDatasource());
    // Check if cluster supported
    checkDataSourceClusterLimit(request.getDatasource());
    // Check Arguments size
    checkRuleArgumentSize(request.getTemplateArgumentRequests(), templateInDb);
    // Check existence of project
    Project projectInDb = projectService.checkProjectExistence(request.getProjectId(), loginUser);
    // Check permissions of project
    List<Integer> permissions = new ArrayList<>();
    permissions.add(ProjectUserPermissionEnum.DEVELOPER.getCode());
    projectService.checkProjectPermission(projectInDb, loginUser, permissions);
    // Check existence of rule name
    checkRuleName(request.getRuleName(), projectInDb, null);
    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()));
    }
    // Create and save rule
    Rule newRule = new Rule();
    setBasicInfo(newRule, ruleGroup, templateInDb, projectInDb, request, loginUser);
    String csId = request.getCsId();
    // For workflow node context.
    boolean cs = false;
    if (StringUtils.isNotBlank(csId)) {
        newRule.setCsId(csId);
        cs = true;
    }
    Rule savedRule = ruleDao.saveRule(newRule);
    LOGGER.info("Succeed to save rule, rule_id: {}", savedRule.getId());
    // Save alarm_config,ruleVariable and ruleDataSource
    // Generate rule variable and save
    LOGGER.info("Start to generate and save rule_variable.");
    // For repeat fps table name when concurrent task is running.
    addUuid(request.getDatasource());
    List<RuleVariable> ruleVariables = autoAdaptArgumentAndGetRuleVariable(templateInDb, request.getDatasource(), request.getTemplateArgumentRequests(), savedRule);
    List<RuleVariable> savedRuleVariables = ruleVariableService.saveRuleVariable(ruleVariables);
    LOGGER.info("Succeed to save rule_variables, rule_variables: {}", savedRuleVariables);
    List<AlarmConfig> savedAlarmConfigs = new ArrayList<>();
    if (request.getAlarm()) {
        savedAlarmConfigs = alarmConfigService.checkAndSaveAlarmVariable(request.getAlarmVariable(), savedRule);
        LOGGER.info("Succeed to save alarm_configs, alarm_configs: {}", savedAlarmConfigs);
    }
    List<RuleDataSource> savedRuleDataSource = ruleDataSourceService.checkAndSaveRuleDataSource(request.getDatasource(), savedRule, cs, loginUser);
    LOGGER.info("Succeed to save rule_dataSources, rule_dataSources: {}, context service: {}", savedRuleDataSource, cs);
    savedRule.setRuleVariables(new HashSet<>(savedRuleVariables));
    savedRule.setAlarmConfigs(new HashSet<>(savedAlarmConfigs));
    savedRule.setRuleDataSources(new HashSet<>(savedRuleDataSource));
    // Update rule count of datasource
    ruleDataSourceService.updateRuleDataSourceCount(savedRule, 1);
    RuleResponse response = new RuleResponse(savedRule);
    LOGGER.info("Succeed to add rule, rule_id: {}", response.getRuleId());
    return new GeneralResponse<>("200", "{&ADD_RULE_SUCCESSFULLY}", response);
}
Also used : UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) RuleResponse(com.webank.wedatasphere.qualitis.rule.response.RuleResponse) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) Project(com.webank.wedatasphere.qualitis.project.entity.Project)

Example 8 with RuleResponse

use of com.webank.wedatasphere.qualitis.rule.response.RuleResponse in project Qualitis by WeBankFinTech.

the class CustomRuleServiceImpl method addCustomRuleReal.

private GeneralResponse<RuleResponse> addCustomRuleReal(AddCustomRuleRequest request, String loginUser) throws UnExpectedRequestException, PermissionDeniedRequestException {
    // Check Arguments
    AddCustomRuleRequest.checkRequest(request);
    String nowDate = ExecutionManagerImpl.PRINT_TIME_FORMAT.format(new Date());
    // Generate Template, TemplateStatisticsInputMeta and save
    Template template = ruleTemplateService.addCustomTemplate(request);
    TemplateDataSourceType templateDataSourceType = new TemplateDataSourceType();
    if (request.getLinkisDataSourceType() == null) {
        templateDataSourceType.setDataSourceTypeId(TemplateDataSourceTypeEnum.HIVE.getCode());
    } else {
        templateDataSourceType.setDataSourceTypeId(TemplateDataSourceTypeEnum.MYSQL.getCode());
    }
    templateDataSourceType.setTemplate(template);
    templateDataSourceTypeDao.save(templateDataSourceType);
    // Save rule, rule_alarm_config and ruleDataSource
    // Check existence of project
    Project projectInDb = projectService.checkProjectExistence(request.getProjectId(), loginUser);
    // 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 if cluster name is supported
    ruleDataSourceService.checkDataSourceClusterSupport(request.getClusterName());
    RuleGroup ruleGroup;
    if (request.getRuleGroupId() != null) {
        ruleGroup = ruleGroupDao.findById(request.getRuleGroupId());
        if (ruleGroup == null) {
            throw new UnExpectedRequestException(String.format("Rule Group: %s {&CAN_NOT_BE_NULL_OR_EMPTY}", request.getRuleGroupId()));
        }
    } else {
        ruleGroup = ruleGroupDao.saveRuleGroup(new RuleGroup("Group_" + UUID.randomUUID().toString().replace("-", ""), projectInDb.getId()));
    }
    Rule newRule = new Rule();
    // Set basic info.
    setBasicInfo(newRule, projectInDb, ruleGroup, template, loginUser, nowDate, request);
    String csId = request.getCsId();
    // For context service.
    boolean cs = false;
    if (StringUtils.isNotBlank(csId)) {
        newRule.setCsId(csId);
        cs = true;
    }
    String fileId = request.getFileId();
    // For fps file check.
    boolean fps = false;
    if (StringUtils.isNotBlank(fileId)) {
        fps = true;
    }
    String sqlCheckArea = request.getSqlCheckArea();
    // For fps file check.
    boolean sqlCheck = false;
    if (StringUtils.isNotBlank(sqlCheckArea)) {
        sqlCheck = true;
    }
    Rule savedRule = ruleDao.saveRule(newRule);
    LOGGER.info("Succeed to save custom rule, rule_id: {}", savedRule.getId());
    List<AlarmConfig> savedAlarmConfigs = new ArrayList<>();
    if (request.getAlarm()) {
        savedAlarmConfigs = alarmConfigService.checkAndSaveCustomAlarmVariable(request.getAlarmVariable(), savedRule);
        LOGGER.info("Succeed to save alarm_configs, alarm_configs: {}", savedAlarmConfigs);
    }
    List<RuleDataSource> ruleDataSources = ruleDataSourceService.checkAndSaveCustomRuleDataSource(request.getClusterName(), request.getProxyUser(), loginUser, savedRule, cs, sqlCheck, request.getLinkisDataSourceId(), request.getLinkisDataSourceVersionId(), request.getLinkisDataSourceName(), request.getLinkisDataSourceType());
    savedRule.setAlarmConfigs(new HashSet<>(savedAlarmConfigs));
    if (CollectionUtils.isNotEmpty(ruleDataSources)) {
        savedRule.setRuleDataSources(new HashSet<>(ruleDataSources));
    }
    // Update rule count of datasource
    ruleDataSourceService.updateRuleDataSourceCount(savedRule, 1);
    RuleResponse response = new RuleResponse(savedRule);
    LOGGER.info("Succeed to add custom rule, rule_id: {}", savedRule.getId());
    return new GeneralResponse<>("200", "{&SUCCEED_TO_ADD_CUSTOM_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) TemplateDataSourceType(com.webank.wedatasphere.qualitis.rule.entity.TemplateDataSourceType) AlarmConfig(com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)

Example 9 with RuleResponse

use of com.webank.wedatasphere.qualitis.rule.response.RuleResponse in project Qualitis by WeBankFinTech.

the class CustomRuleServiceImpl method modifyCustomRuleReal.

private GeneralResponse<RuleResponse> modifyCustomRuleReal(ModifyCustomRuleRequest request, String loginUser) throws UnExpectedRequestException, MetaDataAcquireFailedException, PermissionDeniedRequestException {
    ModifyCustomRuleRequest.checkRequest(request);
    Rule ruleInDb = ruleDao.findById(request.getRuleId());
    if (ruleInDb == null) {
        throw new UnExpectedRequestException("rule_id [" + request.getRuleId() + "] {&DOES_NOT_EXIST}");
    }
    Project projectInDb = projectService.checkProjectExistence(ruleInDb.getProject().getId(), loginUser);
    if (!ruleInDb.getRuleType().equals(RuleTypeEnum.CUSTOM_RULE.getCode())) {
        throw new UnExpectedRequestException("rule_id: [" + request.getRuleId() + "]) {&IS_NOT_A_CUSTOM_RULE}");
    }
    // Check permissions of project
    List<Integer> permissions = new ArrayList<>();
    permissions.add(ProjectUserPermissionEnum.DEVELOPER.getCode());
    projectService.checkProjectPermission(projectInDb, loginUser, permissions);
    LOGGER.info("Succeed to find custom rule. rule_id: {}", ruleInDb.getId());
    // Check existence of project name
    ruleService.checkRuleName(request.getRuleName(), ruleInDb.getProject(), ruleInDb.getId());
    // Check if cluster name supported
    ruleDataSourceService.checkDataSourceClusterSupport(request.getClusterName());
    String nowDate = ExecutionManagerImpl.PRINT_TIME_FORMAT.format(new Date());
    // Delete alarm config by custom rule
    alarmConfigService.deleteByRule(ruleInDb);
    LOGGER.info("Succeed to delete all alarm_config. rule_id: {}", ruleInDb.getId());
    // Delete template of custom rule
    ruleTemplateService.deleteCustomTemplate(ruleInDb.getTemplate());
    LOGGER.info("Succeed to delete custom rule template. rule_id: {}", request.getRuleId());
    // Delete rule datasource of custom rule
    ruleDataSourceService.deleteByRule(ruleInDb);
    LOGGER.info("Succeed to delete all rule_dataSources. rule_id: {}", ruleInDb.getId());
    // Update rule count of datasource
    ruleDataSourceService.updateRuleDataSourceCount(ruleInDb, -1);
    // Save template, alarm config, rule datasource of custom rule
    AddCustomRuleRequest addCustomRuleRequest = new AddCustomRuleRequest();
    BeanUtils.copyProperties(request, addCustomRuleRequest);
    Template template = ruleTemplateService.addCustomTemplate(addCustomRuleRequest);
    TemplateDataSourceType templateDataSourceType = new TemplateDataSourceType();
    if (request.getLinkisDataSourceType() == null) {
        templateDataSourceType.setDataSourceTypeId(TemplateDataSourceTypeEnum.HIVE.getCode());
    } else {
        templateDataSourceType.setDataSourceTypeId(TemplateDataSourceTypeEnum.MYSQL.getCode());
    }
    templateDataSourceType.setTemplate(template);
    templateDataSourceTypeDao.save(templateDataSourceType);
    // Modify custom rule and save
    setBasicInfo(ruleInDb, template, loginUser, nowDate, request);
    String csId = request.getCsId();
    ruleInDb.setCsId(csId);
    boolean cs = false;
    if (StringUtils.isNotBlank(csId)) {
        cs = true;
    }
    String fileId = request.getFileId();
    boolean fps = false;
    if (StringUtils.isNotBlank(fileId)) {
        fps = true;
    }
    String sqlCheckArea = request.getSqlCheckArea();
    boolean sqlCheck = false;
    if (StringUtils.isNotBlank(sqlCheckArea)) {
        sqlCheck = true;
    }
    Rule savedRule = ruleDao.saveRule(ruleInDb);
    // Save alarm config and rule datasource
    List<AlarmConfig> savedAlarmConfigs = new ArrayList<>();
    if (request.getAlarm()) {
        savedAlarmConfigs = alarmConfigService.checkAndSaveCustomAlarmVariable(request.getAlarmVariable(), savedRule);
        LOGGER.info("Succeed to save alarm_configs, alarm_configs: {}", savedAlarmConfigs);
    }
    List<RuleDataSource> ruleDataSources = ruleDataSourceService.checkAndSaveCustomRuleDataSource(request.getClusterName(), request.getProxyUser(), loginUser, savedRule, cs, sqlCheck, request.getLinkisDataSourceId(), request.getLinkisDataSourceVersionId(), request.getLinkisDataSourceName(), request.getLinkisDataSourceType());
    savedRule.setAlarmConfigs(new HashSet<>(savedAlarmConfigs));
    if (CollectionUtils.isNotEmpty(ruleDataSources)) {
        savedRule.setRuleDataSources(new HashSet<>(ruleDataSources));
    }
    // Update rule count of datasource
    ruleDataSourceService.updateRuleDataSourceCount(ruleInDb, 1);
    RuleResponse response = new RuleResponse(savedRule);
    LOGGER.info("Succeed to modify custom rule, rule_id: {}", savedRule.getId());
    // projectEventService.record(savedRule.getProject().getId(), loginUser, "modify", "custom rule[name= " + savedRule.getName() + "].", EventTypeEnum.MODIFY_PROJECT.getCode());
    return new GeneralResponse<>("200", "{&SUCCEED_TO_MODIFY_CUSTOM_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) Template(com.webank.wedatasphere.qualitis.rule.entity.Template) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) Project(com.webank.wedatasphere.qualitis.project.entity.Project) AddCustomRuleRequest(com.webank.wedatasphere.qualitis.rule.request.AddCustomRuleRequest) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) TemplateDataSourceType(com.webank.wedatasphere.qualitis.rule.entity.TemplateDataSourceType) AlarmConfig(com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)

Example 10 with RuleResponse

use of com.webank.wedatasphere.qualitis.rule.response.RuleResponse in project Qualitis by WeBankFinTech.

the class FileRuleServiceImpl method modifyRuleDetailReal.

private GeneralResponse<RuleResponse> modifyRuleDetailReal(ModifyFileRuleRequest request, String loginUser) throws UnExpectedRequestException, PermissionDeniedRequestException {
    // Check Arguments
    ModifyFileRuleRequest.checkRequest(request);
    // Check existence of rule
    Rule ruleInDb = ruleDao.findById(request.getRuleId());
    if (ruleInDb == null) {
        throw new UnExpectedRequestException("rule_id [" + request.getRuleId() + "] {&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.FILE_TEMPLATE_RULE.getCode())) {
        throw new UnExpectedRequestException("rule(id: [" + request.getRuleId() + "]) {&IS_NOT_A_FILE_RULE}");
    }
    LOGGER.info("Succeed to find rule. rule_id: {}", ruleInDb.getId());
    String nowDate = ExecutionManagerImpl.PRINT_TIME_FORMAT.format(new Date());
    String csId = request.getCsId();
    boolean cs = false;
    if (StringUtils.isNotBlank(csId)) {
        cs = true;
        ruleInDb.setCsId(csId);
    } else {
        LOGGER.info("Delete context service ID. rule_id: {}, cs_id: {}", ruleInDb.getId(), ruleInDb.getCsId());
        ruleInDb.setCsId(csId);
        LOGGER.info("After delete context service ID. rule_id: {}, cs_id: {}", ruleInDb.getId(), ruleInDb.getCsId());
    }
    // Check cluster support
    ruleDataSourceService.checkDataSourceClusterSupport(request.getDatasource().getClusterName());
    // Delete alarm config by file rule
    alarmConfigService.deleteByRule(ruleInDb);
    LOGGER.info("Succeed to delete all alarm_config. rule_id: {}", ruleInDb.getId());
    // Delete template of file rule
    ruleTemplateService.deleteFileRuleTemplate(ruleInDb.getTemplate().getId());
    LOGGER.info("Succeed to delete file rule template. rule_id: {}", request.getRuleId());
    // Delete rule datasource of file rule
    ruleDataSourceService.deleteByRule(ruleInDb);
    LOGGER.info("Succeed to delete all rule_dataSources. rule_id: {}", ruleInDb.getId());
    // Update rule count of datasource
    ruleDataSourceService.updateRuleDataSourceCount(ruleInDb, -1);
    // Check existence of rule
    AddFileRuleRequest addFileRuleRequest = new AddFileRuleRequest();
    BeanUtils.copyProperties(request, addFileRuleRequest);
    Template template = ruleTemplateService.addFileTemplate(addFileRuleRequest);
    // Save rule
    ruleInDb.setRuleType(RuleTypeEnum.FILE_TEMPLATE_RULE.getCode());
    ruleInDb.setTemplate(template);
    ruleInDb.setName(request.getRuleName());
    ruleInDb.setCnName(request.getRuleCnName());
    ruleInDb.setDetail(request.getRuleDetail());
    ruleInDb.setAlarm(request.getAlarm());
    ruleInDb.setRuleTemplateName(template.getName());
    ruleInDb.setAbortOnFailure(request.getAbortOnFailure());
    ruleInDb.setModifyUser(loginUser);
    ruleInDb.setModifyTime(nowDate);
    Rule savedRule = ruleDao.saveRule(ruleInDb);
    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(ruleInDb, 1);
    RuleResponse response = new RuleResponse(savedRule);
    LOGGER.info("Succeed to modify file rule, rule_id: {}", savedRule.getId());
    // projectEventService.record(savedRule.getProject().getId(), loginUser, "modify", "file rule[name= " + savedRule.getName() + "].", EventTypeEnum.MODIFY_PROJECT.getCode());
    return new GeneralResponse<>("200", "{&SUCCEED_TO_MODIFY_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) Template(com.webank.wedatasphere.qualitis.rule.entity.Template) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) Project(com.webank.wedatasphere.qualitis.project.entity.Project) AddFileRuleRequest(com.webank.wedatasphere.qualitis.rule.request.AddFileRuleRequest) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) AlarmConfig(com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)

Aggregations

GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)11 RuleResponse (com.webank.wedatasphere.qualitis.rule.response.RuleResponse)11 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)10 Project (com.webank.wedatasphere.qualitis.project.entity.Project)9 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)6 RuleGroup (com.webank.wedatasphere.qualitis.rule.entity.RuleGroup)5 AlarmConfig (com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)4 RuleDataSource (com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource)4 Template (com.webank.wedatasphere.qualitis.rule.entity.Template)4 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 TemplateDataSourceType (com.webank.wedatasphere.qualitis.rule.entity.TemplateDataSourceType)2 AddCustomRuleRequest (com.webank.wedatasphere.qualitis.rule.request.AddCustomRuleRequest)2 AddFileRuleRequest (com.webank.wedatasphere.qualitis.rule.request.AddFileRuleRequest)2 ClusterInfo (com.webank.wedatasphere.qualitis.entity.ClusterInfo)1 User (com.webank.wedatasphere.qualitis.entity.User)1 ExcelMultiTemplateRuleByProject (com.webank.wedatasphere.qualitis.project.excel.ExcelMultiTemplateRuleByProject)1 ExcelTemplateFileRuleByProject (com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateFileRuleByProject)1 RuleDao (com.webank.wedatasphere.qualitis.rule.dao.RuleDao)1 RuleGroupDao (com.webank.wedatasphere.qualitis.rule.dao.RuleGroupDao)1