Search in sources :

Example 6 with ExcelMultiTemplateRuleByProject

use of com.webank.wedatasphere.qualitis.project.excel.ExcelMultiTemplateRuleByProject 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 7 with ExcelMultiTemplateRuleByProject

use of com.webank.wedatasphere.qualitis.project.excel.ExcelMultiTemplateRuleByProject in project Qualitis by WeBankFinTech.

the class RuleBatchServiceImpl method constructAddMultiSourceRuleRequest.

private List<AddMultiSourceRuleRequest> constructAddMultiSourceRuleRequest(Map<String, List<ExcelMultiTemplateRuleByProject>> multiRulePartitionedByRuleName, Project project, String localeStr) throws UnExpectedRequestException {
    List<AddMultiSourceRuleRequest> addMultiSourceRuleRequests = new ArrayList<>();
    for (String ruleName : multiRulePartitionedByRuleName.keySet()) {
        List<ExcelMultiTemplateRuleByProject> ruleInfos = multiRulePartitionedByRuleName.get(ruleName);
        ExcelMultiTemplateRuleByProject firstCommonInfo = ruleInfos.get(0);
        AddMultiSourceRuleRequest addMultiSourceRuleRequest = new AddMultiSourceRuleRequest();
        String ruleTemplateName = firstCommonInfo.getTemplateName();
        String ruleGroupName = firstCommonInfo.getRuleGroupName();
        addMultiSourceRuleRequest.setSpecifyStaticStartupParam(firstCommonInfo.getSpecifyStaticStartupParam());
        addMultiSourceRuleRequest.setDeleteFailCheckResult(firstCommonInfo.getDeleteFailCheckResult());
        addMultiSourceRuleRequest.setStaticStartupParam(firstCommonInfo.getStaticStartupParam());
        addMultiSourceRuleRequest.setAbortOnFailure(firstCommonInfo.getAbortOnFailure());
        if (StringUtils.isBlank(ruleGroupName)) {
            throw new UnExpectedRequestException("RuleGroupName {&CAN_NOT_BE_NULL_OR_EMPTY}");
        }
        Template template = findTemplateByName(ruleTemplateName);
        if (template == null) {
            throw new UnExpectedRequestException("{&TEMPLATE_NAME}: [" + ruleTemplateName + "] {&DOES_NOT_EXIST}");
        }
        String filter = null;
        boolean alarm = false;
        String clusterName = firstCommonInfo.getClusterName();
        MultiDataSourceConfigRequest sourceConfigRequest = new MultiDataSourceConfigRequest();
        MultiDataSourceConfigRequest targetConfigRequest = new MultiDataSourceConfigRequest();
        List<MultiDataSourceJoinConfigRequest> mappings = new ArrayList<>();
        List<AlarmConfigRequest> alarmConfigRequests = new ArrayList<>();
        for (ExcelMultiTemplateRuleByProject excelMultiTemplateRule : ruleInfos) {
            if (StringUtils.isNotBlank(excelMultiTemplateRule.getWhereFilter())) {
                filter = excelMultiTemplateRule.getWhereFilter();
            }
            getAlarmConfig(alarmConfigRequests, excelMultiTemplateRule, template, localeStr);
            getMultiDataSourceRequest(sourceConfigRequest, excelMultiTemplateRule, 0);
            getMultiDataSourceRequest(targetConfigRequest, excelMultiTemplateRule, 1);
            getMultiDataSourceJoinRequest(mappings, excelMultiTemplateRule);
        }
        if (alarmConfigRequests.size() != 0) {
            alarm = true;
        }
        RuleGroup ruleGroupInDb = ruleGroupDao.findByRuleGroupNameAndProjectId(ruleGroupName, project.getId());
        if (ruleGroupInDb != null) {
            addMultiSourceRuleRequest.setRuleGroupId(ruleGroupInDb.getId());
        } else {
            RuleGroup ruleGroup = ruleGroupDao.saveRuleGroup(new RuleGroup(ruleGroupName, project.getId()));
            addMultiSourceRuleRequest.setRuleGroupId(ruleGroup.getId());
        }
        addMultiSourceRuleRequest.setRuleName(ruleName);
        addMultiSourceRuleRequest.setClusterName(clusterName);
        addMultiSourceRuleRequest.setProjectId(project.getId());
        addMultiSourceRuleRequest.setRuleDetail(firstCommonInfo.getRuleDetail());
        addMultiSourceRuleRequest.setMultiSourceRuleTemplateId(template.getId());
        addMultiSourceRuleRequest.setAlarmVariable(alarmConfigRequests);
        addMultiSourceRuleRequests.add(addMultiSourceRuleRequest);
        addMultiSourceRuleRequest.setSource(sourceConfigRequest);
        addMultiSourceRuleRequest.setTarget(targetConfigRequest);
        addMultiSourceRuleRequest.setMappings(mappings);
        addMultiSourceRuleRequest.setFilter(filter);
        addMultiSourceRuleRequest.setAlarm(alarm);
    }
    return addMultiSourceRuleRequests;
}
Also used : UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) ExcelMultiTemplateRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelMultiTemplateRuleByProject) ArrayList(java.util.ArrayList) RuleGroup(com.webank.wedatasphere.qualitis.rule.entity.RuleGroup) Template(com.webank.wedatasphere.qualitis.rule.entity.Template) MultiDataSourceJoinConfigRequest(com.webank.wedatasphere.qualitis.rule.request.multi.MultiDataSourceJoinConfigRequest) FileAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest) CustomAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest) AlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.AlarmConfigRequest) MultiDataSourceConfigRequest(com.webank.wedatasphere.qualitis.rule.request.multi.MultiDataSourceConfigRequest) AddMultiSourceRuleRequest(com.webank.wedatasphere.qualitis.rule.request.multi.AddMultiSourceRuleRequest)

Example 8 with ExcelMultiTemplateRuleByProject

use of com.webank.wedatasphere.qualitis.project.excel.ExcelMultiTemplateRuleByProject in project Qualitis by WeBankFinTech.

the class ExcelRuleListener method invoke.

@Override
public void invoke(Object object, AnalysisContext context) {
    if (context.getCurrentSheet().getSheetName().equals(ExcelSheetName.TEMPLATE_RULE_NAME)) {
        ExcelTemplateRuleByProject excelTemplateRuleByProject = (ExcelTemplateRuleByProject) object;
        String key = excelTemplateRuleByProject.getRuleName();
        if (templateExcelContent.containsKey(key)) {
            templateExcelContent.get(key).add(excelTemplateRuleByProject);
        } else {
            List<ExcelTemplateRuleByProject> tmp = new ArrayList<>();
            tmp.add(excelTemplateRuleByProject);
            templateExcelContent.put(key, tmp);
        }
    } else if (context.getCurrentSheet().getSheetName().equals(ExcelSheetName.CUSTOM_RULE_NAME)) {
        ExcelCustomRuleByProject excelCustomRule = (ExcelCustomRuleByProject) object;
        String key = excelCustomRule.getRuleName();
        if (customExcelContent.containsKey(key)) {
            customExcelContent.get(key).add(excelCustomRule);
        } else {
            List<ExcelCustomRuleByProject> tmp = new ArrayList<>();
            tmp.add(excelCustomRule);
            customExcelContent.put(key, tmp);
        }
    } else if (context.getCurrentSheet().getSheetName().equals(ExcelSheetName.MULTI_TEMPLATE_RULE_NAME)) {
        ExcelMultiTemplateRuleByProject excelMultiTemplateRule = (ExcelMultiTemplateRuleByProject) object;
        String key = excelMultiTemplateRule.getRuleName();
        if (multiTemplateExcelContent.containsKey(key)) {
            multiTemplateExcelContent.get(key).add(excelMultiTemplateRule);
        } else {
            List<ExcelMultiTemplateRuleByProject> tmp = new ArrayList<>();
            tmp.add(excelMultiTemplateRule);
            multiTemplateExcelContent.put(key, tmp);
        }
    } else if (context.getCurrentSheet().getSheetName().equals(ExcelSheetName.TEMPLATE_FILE_RULE_NAME)) {
        ExcelTemplateFileRuleByProject excelTemplateFileRule = (ExcelTemplateFileRuleByProject) object;
        String key = excelTemplateFileRule.getRuleName();
        if (templateFileExcelContent.containsKey(key)) {
            templateFileExcelContent.get(key).add(excelTemplateFileRule);
        } else {
            List<ExcelTemplateFileRuleByProject> tmp = new ArrayList<>();
            tmp.add(excelTemplateFileRule);
            templateFileExcelContent.put(key, tmp);
        }
    }
}
Also used : ExcelMultiTemplateRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelMultiTemplateRuleByProject) ExcelCustomRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelCustomRuleByProject) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ExcelTemplateFileRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateFileRuleByProject) ExcelTemplateRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateRuleByProject)

Aggregations

ExcelMultiTemplateRuleByProject (com.webank.wedatasphere.qualitis.project.excel.ExcelMultiTemplateRuleByProject)8 ExcelCustomRuleByProject (com.webank.wedatasphere.qualitis.project.excel.ExcelCustomRuleByProject)6 ExcelTemplateRuleByProject (com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateRuleByProject)6 RuleMetric (com.webank.wedatasphere.qualitis.entity.RuleMetric)3 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)3 Project (com.webank.wedatasphere.qualitis.project.entity.Project)3 ExcelTemplateFileRuleByProject (com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateFileRuleByProject)3 OutputStream (java.io.OutputStream)3 ArrayList (java.util.ArrayList)3 User (com.webank.wedatasphere.qualitis.entity.User)2 PermissionDeniedRequestException (com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException)2 AddProjectRequest (com.webank.wedatasphere.qualitis.project.request.AddProjectRequest)2 AlarmConfig (com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)2 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)2 RuleDataSourceMapping (com.webank.wedatasphere.qualitis.rule.entity.RuleDataSourceMapping)2 RuleGroup (com.webank.wedatasphere.qualitis.rule.entity.RuleGroup)2 Template (com.webank.wedatasphere.qualitis.rule.entity.Template)2 AlarmConfigRequest (com.webank.wedatasphere.qualitis.rule.request.AlarmConfigRequest)2 CustomAlarmConfigRequest (com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest)2 FileAlarmConfigRequest (com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest)2