Search in sources :

Example 26 with RuleMetric

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

the class RuleBatchServiceImpl method getAlarmConfig.

private void getAlarmConfig(List<AlarmConfigRequest> alarmConfigRequests, ExcelMultiTemplateRuleByProject excelMultiTemplateRule, Template template, String localeStr) throws UnExpectedRequestException {
    String templateOutputName = excelMultiTemplateRule.getAlarmCheckName();
    if (!StringUtils.isBlank(templateOutputName)) {
        String checkTemplateName = excelMultiTemplateRule.getCheckTemplateName();
        String compareTypeName = excelMultiTemplateRule.getCompareType();
        String threshold = excelMultiTemplateRule.getThreshold();
        TemplateOutputMeta templateOutputMeta = findTemplateOutputMetaByTemplateAndOutputName(template, templateOutputName);
        if (template.getChildTemplate() != null && templateOutputMeta == null) {
            templateOutputMeta = findTemplateOutputMetaByTemplateAndOutputName(template.getChildTemplate(), templateOutputName);
        }
        if (templateOutputMeta == null) {
            throw new UnExpectedRequestException("{&TEMPLATE_OUTPUT_NAME} {&DOES_NOT_EXIST}");
        }
        AlarmConfigRequest alarmConfigRequest = new AlarmConfigRequest();
        alarmConfigRequest.setCheckTemplate(CheckTemplateEnum.getCheckTemplateCode(checkTemplateName, localeStr));
        alarmConfigRequest.setCompareType(CompareTypeEnum.getCompareTypeCode(compareTypeName));
        alarmConfigRequest.setThreshold(Double.valueOf(threshold));
        alarmConfigRequest.setOutputMetaId(templateOutputMeta.getId());
        // Rule Metric.
        String ruleMetricEnCode = excelMultiTemplateRule.getRuleMetricEnCode();
        if (StringUtils.isNotBlank(ruleMetricEnCode)) {
            // xx_xx_xx_encode, index is 3.
            RuleMetric ruleMetricInDb = ruleMetricDao.findByEnCode(ruleMetricEnCode);
            if (ruleMetricInDb == null) {
                throw new UnExpectedRequestException("Rule metric[Code=" + ruleMetricEnCode + "] " + "{&DOES_NOT_EXIST}");
            }
            String code = ruleMetricInDb.getEnCode();
            alarmConfigRequest.setRuleMetricEnCode(code);
        }
        alarmConfigRequest.setUploadRuleMetricValue(excelMultiTemplateRule.getUploadRuleMetricValue());
        alarmConfigRequest.setUploadAbnormalValue(excelMultiTemplateRule.getUploadAbnormalValue());
        alarmConfigRequests.add(alarmConfigRequest);
    }
}
Also used : RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) FileAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest) CustomAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest) AlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.AlarmConfigRequest) TemplateOutputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta)

Example 27 with RuleMetric

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

the class RuleBatchServiceImpl method getMappingInfoAndAlarm.

private void getMappingInfoAndAlarm(Set<RuleDataSourceMapping> ruleDataSourceMappings, Set<AlarmConfig> alarmConfigs, List<ExcelMultiTemplateRuleByProject> lines, ExcelMultiTemplateRuleByProject ruleLinePrefix, String localeStr) {
    for (RuleDataSourceMapping mapping : ruleDataSourceMappings) {
        ExcelMultiTemplateRuleByProject tmp = new ExcelMultiTemplateRuleByProject(ruleLinePrefix.getRuleName());
        tmp.setLeftMappingStatement(mapping.getLeftStatement());
        tmp.setLeftMappingNames(mapping.getLeftColumnNames());
        tmp.setLeftMappingTypes(mapping.getLeftColumnTypes());
        tmp.setMappingOperation(MappingOperationEnum.getByCode(mapping.getOperation()).getSymbol());
        tmp.setRightMappingStatement(mapping.getRightStatement());
        tmp.setRightMappingNames(mapping.getRightColumnNames());
        tmp.setRightMappingTypes(mapping.getRightColumnTypes());
        LOGGER.info("Collect excel line: {}", tmp);
        lines.add(tmp);
    }
    for (AlarmConfig alarmConfig : alarmConfigs) {
        Double threshold = alarmConfig.getThreshold();
        String alarmOutputName = alarmConfig.getTemplateOutputMeta().getOutputName();
        String alarmCompareType = CompareTypeEnum.getCompareTypeName(alarmConfig.getCompareType());
        String checkTemplateName = CheckTemplateEnum.getCheckTemplateName(alarmConfig.getCheckTemplate(), localeStr);
        ExcelMultiTemplateRuleByProject tmp = new ExcelMultiTemplateRuleByProject(ruleLinePrefix.getRuleName());
        tmp.setCompareType(alarmCompareType);
        tmp.setAlarmCheckName(alarmOutputName);
        tmp.setCheckTemplateName(checkTemplateName);
        tmp.setThreshold(String.valueOf(threshold));
        RuleMetric ruleMetric = alarmConfig.getRuleMetric();
        // Recod rule metric info (unique code).
        if (ruleMetric != null) {
            String enCode = ruleMetric.getEnCode();
            tmp.setRuleMetricEnCode(enCode);
            tmp.setRuleMetricName(ruleMetric.getName());
        }
        tmp.setUploadRuleMetricValue(alarmConfig.getUploadRuleMetricValue());
        tmp.setUploadAbnormalValue(alarmConfig.getUploadAbnormalValue());
        LOGGER.info("Collect excel line: {}", tmp);
        lines.add(tmp);
    }
}
Also used : RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) RuleDataSourceMapping(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSourceMapping) ExcelMultiTemplateRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelMultiTemplateRuleByProject) AlarmConfig(com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)

Example 28 with RuleMetric

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

the class RuleBatchServiceImpl method getCustomAlarmConfig.

private void getCustomAlarmConfig(List<CustomAlarmConfigRequest> customAlarmConfigRequests, ExcelCustomRuleByProject excelCustomRule, String localeStr) throws UnExpectedRequestException {
    String templateOutputName = excelCustomRule.getAlarmCheckName();
    if (!StringUtils.isBlank(templateOutputName)) {
        String checkTemplateName = excelCustomRule.getCheckTemplateName();
        String compareTypeName = excelCustomRule.getCompareType();
        String threshold = excelCustomRule.getThreshold();
        CustomAlarmConfigRequest customAlarmConfigRequest = new CustomAlarmConfigRequest();
        customAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.getCheckTemplateCode(checkTemplateName, localeStr));
        customAlarmConfigRequest.setCompareType(CompareTypeEnum.getCompareTypeCode(compareTypeName));
        customAlarmConfigRequest.setThreshold(Double.valueOf(threshold));
        // Rule Metric.
        String ruleMetricEnCode = excelCustomRule.getRuleMetricEnCode();
        if (StringUtils.isNotBlank(ruleMetricEnCode)) {
            // xx_xx_xx_encode, index is 3.
            RuleMetric ruleMetricInDb = ruleMetricDao.findByEnCode(ruleMetricEnCode);
            if (ruleMetricInDb == null) {
                throw new UnExpectedRequestException("Rule metric[Code=" + ruleMetricEnCode + "] " + "{&DOES_NOT_EXIST}");
            }
            String code = ruleMetricInDb.getEnCode();
            customAlarmConfigRequest.setRuleMetricEnCode(code);
        }
        customAlarmConfigRequest.setUploadRuleMetricValue(excelCustomRule.getUploadRuleMetricValue());
        customAlarmConfigRequest.setUploadAbnormalValue(excelCustomRule.getUploadAbnormalValue());
        customAlarmConfigRequests.add(customAlarmConfigRequest);
    }
}
Also used : RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) CustomAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest)

Example 29 with RuleMetric

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

the class RuleBatchServiceImpl method getCustomRule.

@Override
public List<ExcelCustomRuleByProject> getCustomRule(Iterable<Rule> rules, String localeStr) {
    List<ExcelCustomRuleByProject> lines = new ArrayList<>();
    for (Rule rule : rules) {
        if (!rule.getRuleType().equals(RuleTypeEnum.CUSTOM_RULE.getCode())) {
            continue;
        }
        ExcelCustomRuleByProject ruleLinePrefix = new ExcelCustomRuleByProject();
        basicInfoToExcel(ruleLinePrefix, rule);
        lines.add(ruleLinePrefix);
        for (AlarmConfig alarmConfig : rule.getAlarmConfigs()) {
            Double threshold = alarmConfig.getThreshold();
            String alarmOutputName = alarmConfig.getTemplateOutputMeta().getOutputName();
            String alarmCompareType = CompareTypeEnum.getCompareTypeName(alarmConfig.getCompareType());
            String checkTemplateName = CheckTemplateEnum.getCheckTemplateName(alarmConfig.getCheckTemplate(), localeStr);
            ExcelCustomRuleByProject tmp = new ExcelCustomRuleByProject(rule.getName());
            tmp.setCompareType(alarmCompareType);
            tmp.setAlarmCheckName(alarmOutputName);
            tmp.setThreshold(String.valueOf(threshold));
            tmp.setCheckTemplateName(checkTemplateName);
            RuleMetric ruleMetric = alarmConfig.getRuleMetric();
            // Recod rule metric info (unique code).
            if (ruleMetric != null) {
                String enCode = ruleMetric.getEnCode();
                tmp.setRuleMetricEnCode(enCode);
                tmp.setRuleMetricName(ruleMetric.getName());
            }
            tmp.setUploadRuleMetricValue(alarmConfig.getUploadRuleMetricValue());
            tmp.setUploadAbnormalValue(alarmConfig.getUploadAbnormalValue());
            lines.add(tmp);
        }
    }
    return lines;
}
Also used : RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) ExcelCustomRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelCustomRuleByProject) ArrayList(java.util.ArrayList) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) AlarmConfig(com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)

Example 30 with RuleMetric

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

the class RuleNodeServiceImpl method importRuleReal.

private void importRuleReal(RuleNodeRequest ruleNodeRequest, Rule ruleInDb, Rule rule, Project projectInDb, Template template, RuleGroup ruleGroup, Set<AlarmConfig> alarmConfigs, Set<RuleVariable> ruleVariables, Set<RuleDataSource> ruleDataSources, Set<RuleDataSourceMapping> ruleDataSourceMappings) throws IOException, UnExpectedRequestException {
    if (ruleInDb == null) {
        LOGGER.info("Import in first time. That means adding.");
        rule.setProject(projectInDb);
        ruleGroup.setProjectId(projectInDb.getId());
        if (RuleTypeEnum.CUSTOM_RULE.getCode().equals(rule.getRuleType())) {
            Template saveTemplate = ruleTemplateDao.saveTemplate(template);
            Set<Integer> templateDateTypes = ruleDataSources.stream().filter(currRuleDataSource -> currRuleDataSource.getDatasourceType() != null).map(RuleDataSource::getDatasourceType).collect(Collectors.toSet());
            for (Integer templateDataType : templateDateTypes) {
                TemplateDataSourceType templateDataSourceType = new TemplateDataSourceType(templateDataType, saveTemplate);
                templateDataSourceTypeDao.save(templateDataSourceType);
            }
            Set<TemplateStatisticsInputMeta> templateStatisticsInputMetas = new HashSet<>();
            Set<TemplateOutputMeta> templateOutputMetaSet = new HashSet<>();
            if (rule.getOutputName() != null && rule.getFunctionType() != null && rule.getFunctionContent() != null) {
                templateStatisticsInputMetas = templateStatisticsInputMetaService.getAndSaveTemplateStatisticsInputMeta(rule.getOutputName(), rule.getFunctionType(), rule.getFunctionContent(), saveTemplate.getSaveMidTable(), saveTemplate);
                templateOutputMetaSet = templateOutputMetaService.getAndSaveTemplateOutputMeta(rule.getOutputName(), rule.getFunctionType(), saveTemplate.getSaveMidTable(), saveTemplate);
            } else {
                List<RuleMetric> ruleMetrics = alarmConfigs.stream().map(AlarmConfig::getRuleMetric).collect(Collectors.toList());
                for (RuleMetric ruleMetric : ruleMetrics) {
                    templateStatisticsInputMetas.addAll(templateStatisticsInputMetaService.getAndSaveTemplateStatisticsInputMeta(ruleMetric.getName(), FunctionTypeEnum.MAX_FUNCTION.getCode(), ruleMetric.getName(), saveTemplate.getSaveMidTable(), saveTemplate));
                    templateOutputMetaSet.addAll(templateOutputMetaService.getAndSaveTemplateOutputMeta(ruleMetric.getName(), FunctionTypeEnum.MAX_FUNCTION.getCode(), saveTemplate.getSaveMidTable(), saveTemplate));
                }
            }
            saveTemplate.setStatisticAction(templateStatisticsInputMetas);
            saveTemplate.setTemplateOutputMetas(templateOutputMetaSet);
            rule.setTemplate(saveTemplate);
        } else if (RuleTypeEnum.FILE_TEMPLATE_RULE.getCode().equals(rule.getRuleType())) {
            LOGGER.info("Start to import file rule. {}", rule.getName());
            // Save file rule template.
            rule.setTemplate(ruleTemplateDao.saveTemplate(template));
            // Save file rule group
            rule.setRuleGroup(ruleGroup);
            Rule savedRule = ruleDao.saveRule(rule);
            // Save file alarmconfig
            List<AlarmConfig> alarmConfigList = new ArrayList<>();
            for (AlarmConfig alarmConfig : alarmConfigs) {
                ruleMetricSycn(alarmConfig);
                alarmConfig.setRule(savedRule);
                alarmConfigList.add(alarmConfig);
            }
            List<RuleDataSource> ruleDataSourceList = new ArrayList<>();
            for (RuleDataSource ruleDataSource : ruleDataSources) {
                ruleDataSource.setProjectId(projectInDb.getId());
                ruleDataSource.setRule(savedRule);
                ruleDataSourceList.add(ruleDataSource);
            }
            savedRule.setAlarmConfigs(new HashSet<>(alarmConfigDao.saveAllAlarmConfig(alarmConfigList)));
            savedRule.setRuleDataSources(new HashSet<>(ruleDataSourceDao.saveAllRuleDataSource(ruleDataSourceList)));
            LOGGER.info("Finish to import file rule. {}", rule.getName());
            return;
        } else {
            // When trying out the newly created rule template in the development center, the production center needs to synchronize the rule template.
            synchroRuleTemplate(ruleNodeRequest, rule, template, ruleDataSources);
        }
        rule.setRuleGroup(ruleGroup);
        Rule savedRule = ruleDao.saveRule(rule);
        saveRuleInfo(savedRule, template, projectInDb, alarmConfigs, ruleVariables, ruleDataSources, ruleDataSourceMappings);
        if (ruleNodeRequest.getChildRuleObject() != null) {
            importChildRule(savedRule, ruleGroup, ruleNodeRequest, projectInDb);
        }
    } else {
        LOGGER.info("Import multiple times. That is to update.");
        if (RuleTypeEnum.FILE_TEMPLATE_RULE.getCode().equals(rule.getRuleType())) {
            LOGGER.info("Start to update import file rule. {}", rule.getName());
            Set<AlarmConfig> alarmConfigList = new HashSet<>();
            for (AlarmConfig alarmConfig : alarmConfigs) {
                ruleMetricSycn(alarmConfig);
                alarmConfig.setRule(ruleInDb);
                alarmConfigList.add(alarmConfig);
            }
            updateImportedFileRule(rule, ruleInDb, ruleGroup, alarmConfigList, ruleDataSources);
            LOGGER.info("Finish to update import file rule. {}", rule.getName());
            return;
        }
        updateImportedRule(rule, ruleInDb, ruleGroup, ruleNodeRequest, template, alarmConfigs, ruleVariables, ruleDataSources, ruleDataSourceMappings);
    }
}
Also used : RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) RuleDataSource(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource) TemplateOutputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta) Template(com.webank.wedatasphere.qualitis.rule.entity.Template) TemplateStatisticsInputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateStatisticsInputMeta) ArrayList(java.util.ArrayList) List(java.util.List) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) TemplateDataSourceType(com.webank.wedatasphere.qualitis.rule.entity.TemplateDataSourceType) HashSet(java.util.HashSet) AlarmConfig(com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)

Aggregations

RuleMetric (com.webank.wedatasphere.qualitis.entity.RuleMetric)36 ArrayList (java.util.ArrayList)23 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)19 AlarmConfig (com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)15 RuleMetricDepartmentUser (com.webank.wedatasphere.qualitis.entity.RuleMetricDepartmentUser)10 User (com.webank.wedatasphere.qualitis.entity.User)10 Department (com.webank.wedatasphere.qualitis.entity.Department)9 UserRole (com.webank.wedatasphere.qualitis.entity.UserRole)9 List (java.util.List)9 ExcelRuleMetric (com.webank.wedatasphere.qualitis.project.excel.ExcelRuleMetric)8 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)8 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)7 TemplateOutputMeta (com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta)7 CustomAlarmConfigRequest (com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest)7 FileAlarmConfigRequest (com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest)7 PermissionDeniedRequestException (com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException)6 RuleMetricResponse (com.webank.wedatasphere.qualitis.response.RuleMetricResponse)6 RuleDataSource (com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource)5 Date (java.util.Date)5 Template (com.webank.wedatasphere.qualitis.rule.entity.Template)4