Search in sources :

Example 6 with ExcelTemplateRuleByProject

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

the class RuleBatchServiceImpl method constructAddRuleRequest.

private List<AddRuleRequest> constructAddRuleRequest(Map<String, List<ExcelTemplateRuleByProject>> partitionedByRuleName, Project project, String localeStr) throws UnExpectedRequestException {
    List<AddRuleRequest> addRuleRequests = new ArrayList<>();
    for (String ruleName : partitionedByRuleName.keySet()) {
        List<ExcelTemplateRuleByProject> ruleInfos = partitionedByRuleName.get(ruleName);
        ExcelTemplateRuleByProject firstCommonInfo = ruleInfos.get(0);
        AddRuleRequest addRuleRequest = new AddRuleRequest();
        String ruleDetail = firstCommonInfo.getRuleDetail();
        String ruleCnName = firstCommonInfo.getRuleCnName();
        String ruleGroupName = firstCommonInfo.getRuleGroupName();
        String ruleTemplateName = firstCommonInfo.getTemplateName();
        addRuleRequest.setRuleCnName(ruleCnName);
        addRuleRequest.setAbortOnFailure(firstCommonInfo.getAbortOnFailure());
        addRuleRequest.setStaticStartupParam(firstCommonInfo.getStaticStartupParam());
        addRuleRequest.setDeleteFailCheckResult(firstCommonInfo.getDeleteFailCheckResult());
        addRuleRequest.setSpecifyStaticStartupParam(firstCommonInfo.getSpecifyStaticStartupParam());
        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}");
        }
        boolean alarm = false;
        Long projectId = project.getId();
        List<DataSourceRequest> dataSourceRequests = new ArrayList<>();
        List<AlarmConfigRequest> alarmConfigRequests = new ArrayList<>();
        List<TemplateArgumentRequest> templateArgumentRequests = new ArrayList<>();
        for (ExcelTemplateRuleByProject excelTemplateRuleByProject : ruleInfos) {
            getDataSourceRequest(dataSourceRequests, excelTemplateRuleByProject);
            getTemplateArgument(templateArgumentRequests, excelTemplateRuleByProject, template);
            getAlarmConfig(alarmConfigRequests, excelTemplateRuleByProject, template, localeStr);
        }
        RuleGroup ruleGroupInDb = ruleGroupDao.findByRuleGroupNameAndProjectId(ruleGroupName, projectId);
        if (ruleGroupInDb != null) {
            addRuleRequest.setRuleGroupId(ruleGroupInDb.getId());
        } else {
            RuleGroup ruleGroup = ruleGroupDao.saveRuleGroup(new RuleGroup(ruleGroupName, project.getId()));
            addRuleRequest.setRuleGroupId(ruleGroup.getId());
        }
        // Construct addRuleRequest
        addRuleRequest.setRuleName(ruleName);
        addRuleRequest.setRuleDetail(ruleDetail);
        addRuleRequest.setRuleTemplateId(template.getId());
        if (!alarmConfigRequests.isEmpty()) {
            alarm = true;
        }
        addRuleRequest.setAlarmVariable(alarmConfigRequests);
        addRuleRequest.setDatasource(dataSourceRequests);
        addRuleRequest.setProjectId(projectId);
        addRuleRequest.setAlarm(alarm);
        addRuleRequest.setTemplateArgumentRequests(templateArgumentRequests);
        addRuleRequests.add(addRuleRequest);
    }
    return addRuleRequests;
}
Also used : AddRuleRequest(com.webank.wedatasphere.qualitis.rule.request.AddRuleRequest) DataSourceRequest(com.webank.wedatasphere.qualitis.rule.request.DataSourceRequest) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) ArrayList(java.util.ArrayList) RuleGroup(com.webank.wedatasphere.qualitis.rule.entity.RuleGroup) Template(com.webank.wedatasphere.qualitis.rule.entity.Template) TemplateArgumentRequest(com.webank.wedatasphere.qualitis.rule.request.TemplateArgumentRequest) FileAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest) CustomAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest) AlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.AlarmConfigRequest) ExcelTemplateRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateRuleByProject)

Example 7 with ExcelTemplateRuleByProject

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

the class RuleBatchServiceImpl method getTemplateRule.

@Override
public List<ExcelTemplateRuleByProject> getTemplateRule(Iterable<Rule> rules, String localeStr) {
    List<ExcelTemplateRuleByProject> lines = new ArrayList<>();
    for (Rule rule : rules) {
        if (!rule.getRuleType().equals(RuleTypeEnum.SINGLE_TEMPLATE_RULE.getCode())) {
            continue;
        }
        // Rule basic info.
        ExcelTemplateRuleByProject ruleLinePrefix = new ExcelTemplateRuleByProject();
        basicInfoToExcel(ruleLinePrefix, rule);
        lines.add(ruleLinePrefix);
        for (RuleDataSource ruleDataSource : rule.getRuleDataSources()) {
            String clusterName = ruleDataSource.getClusterName();
            String databaseName = ruleDataSource.getDbName();
            String tableName = ruleDataSource.getTableName();
            String columnName = ruleDataSource.getColName();
            String filter = ruleDataSource.getFilter();
            ExcelTemplateRuleByProject tmp = new ExcelTemplateRuleByProject(rule.getName());
            tmp.setBlackColName(ruleDataSource.getBlackColName());
            tmp.setProxyUser(ruleDataSource.getProxyUser());
            tmp.setFilter(filter);
            tmp.setCluster(clusterName);
            tmp.setDbName(databaseName);
            tmp.setTableName(tableName);
            tmp.setColumnNames(columnName);
            if (ruleDataSource.getLinkisDataSourceId() != null) {
                tmp.setLinkisDataSourceName(ruleDataSource.getLinkisDataSourceName());
                tmp.setLinkisDataSourceId(String.valueOf(ruleDataSource.getLinkisDataSourceId()));
                tmp.setLinkisDataSourceType(TemplateDataSourceTypeEnum.getMessage(ruleDataSource.getDatasourceType()));
            }
            LOGGER.info("Collect excel line: {}", tmp);
            lines.add(tmp);
        }
        for (TemplateMidTableInputMeta templateMidTableInputMeta : rule.getTemplate().getTemplateMidTableInputMetas()) {
            if (TemplateMidTableUtil.shouldResponse(templateMidTableInputMeta)) {
                for (RuleVariable ruleVariable : rule.getRuleVariables()) {
                    if (ruleVariable.getTemplateMidTableInputMeta().equals(templateMidTableInputMeta)) {
                        ExcelTemplateRuleByProject tmp = new ExcelTemplateRuleByProject(rule.getName());
                        String key = templateMidTableInputMeta.getName();
                        String value = StringEscapeUtils.unescapeJava(ruleVariable.getValue());
                        if (templateMidTableInputMeta.getInputType().equals(TemplateInputTypeEnum.REGEXP.getCode())) {
                            if (templateMidTableInputMeta.getRegexpType() != null) {
                                value = ruleVariable.getOriginValue();
                            }
                        }
                        tmp.setArgumentKey(key);
                        tmp.setArgumentValue(value);
                        LOGGER.info("Collect excel line: {}", tmp);
                        lines.add(tmp);
                    }
                }
            }
        }
        alarmConfigsToExcel(rule, lines, localeStr);
    }
    return lines;
}
Also used : RuleDataSource(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource) ArrayList(java.util.ArrayList) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) TemplateMidTableInputMeta(com.webank.wedatasphere.qualitis.rule.entity.TemplateMidTableInputMeta) ExcelTemplateRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateRuleByProject) RuleVariable(com.webank.wedatasphere.qualitis.rule.entity.RuleVariable)

Example 8 with ExcelTemplateRuleByProject

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

ExcelTemplateRuleByProject (com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateRuleByProject)8 ExcelCustomRuleByProject (com.webank.wedatasphere.qualitis.project.excel.ExcelCustomRuleByProject)5 ExcelMultiTemplateRuleByProject (com.webank.wedatasphere.qualitis.project.excel.ExcelMultiTemplateRuleByProject)5 ArrayList (java.util.ArrayList)3 RuleMetric (com.webank.wedatasphere.qualitis.entity.RuleMetric)2 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)2 Project (com.webank.wedatasphere.qualitis.project.entity.Project)2 ExcelTemplateFileRuleByProject (com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateFileRuleByProject)2 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)2 OutputStream (java.io.OutputStream)2 RuleMetricDepartmentUser (com.webank.wedatasphere.qualitis.entity.RuleMetricDepartmentUser)1 User (com.webank.wedatasphere.qualitis.entity.User)1 PermissionDeniedRequestException (com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException)1 ExcelProjectListener (com.webank.wedatasphere.qualitis.project.excel.ExcelProjectListener)1 AddProjectRequest (com.webank.wedatasphere.qualitis.project.request.AddProjectRequest)1 ModifyProjectDetailRequest (com.webank.wedatasphere.qualitis.project.request.ModifyProjectDetailRequest)1 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)1 AlarmConfig (com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)1 RuleDataSource (com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource)1 RuleGroup (com.webank.wedatasphere.qualitis.rule.entity.RuleGroup)1