Search in sources :

Example 1 with ExcelTemplateFileRuleByProject

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

the class RuleBatchServiceImpl method downloadRulesReal.

private GeneralResponse<?> downloadRulesReal(List<Rule> rules, HttpServletResponse response, String loginUser) throws IOException, WriteExcelException {
    String fileName = "batch_rules_export_" + FILE_DATE_FORMATTER.format(new Date()) + SUPPORT_EXCEL_SUFFIX_NAME;
    fileName = URLEncoder.encode(fileName, "UTF-8");
    response.setContentType("application/octet-stream");
    response.addHeader("Content-Disposition", "attachment;filename*=UTF-8''" + fileName);
    response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
    String localeStr = httpServletRequest.getHeader("Content-Language");
    // Write to response.getOutputStream
    OutputStream outputStream = response.getOutputStream();
    List<ExcelCustomRuleByProject> customRules = getCustomRule(rules, localeStr);
    List<ExcelTemplateRuleByProject> templateRules = getTemplateRule(rules, localeStr);
    List<ExcelTemplateFileRuleByProject> templateFileRules = getFileRule(rules, localeStr);
    List<ExcelMultiTemplateRuleByProject> multiTemplateRules = getMultiTemplateRule(rules, localeStr);
    writeExcelToOutput(templateRules, customRules, multiTemplateRules, templateFileRules, outputStream);
    outputStream.flush();
    LOGGER.info("Succeed to download all rules in type of excel");
    // projectEventService.record(rules.iterator().next().getProject().getId(), loginUser, "download", "rules[" + Arrays.toString(rules.stream().map(Rule::getName).toArray()) + "].", EventTypeEnum.MODIFY_PROJECT.getCode());
    return null;
}
Also used : ExcelMultiTemplateRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelMultiTemplateRuleByProject) ExcelCustomRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelCustomRuleByProject) OutputStream(java.io.OutputStream) ExcelTemplateFileRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateFileRuleByProject) Date(java.util.Date) ExcelTemplateRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateRuleByProject)

Example 2 with ExcelTemplateFileRuleByProject

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

the class RuleBatchServiceImpl method getFileRule.

@Override
public List<ExcelTemplateFileRuleByProject> getFileRule(Iterable<Rule> rules, String localeStr) {
    List<ExcelTemplateFileRuleByProject> lines = new ArrayList<>();
    for (Rule rule : rules) {
        if (!rule.getRuleType().equals(RuleTypeEnum.FILE_TEMPLATE_RULE.getCode())) {
            continue;
        }
        String ruleName = rule.getName();
        String ruleCnName = rule.getCnName();
        String ruleDetail = rule.getDetail();
        String templateName = rule.getTemplate().getName();
        ExcelTemplateFileRuleByProject ruleLinePrefix = new ExcelTemplateFileRuleByProject();
        ruleLinePrefix.setRuleName(ruleName);
        ruleLinePrefix.setRuleCnName(ruleCnName);
        ruleLinePrefix.setRuleDetail(ruleDetail);
        ruleLinePrefix.setTemplateName(templateName);
        ruleLinePrefix.setProjectName(rule.getProject().getName());
        ruleLinePrefix.setAbortOnFailure(rule.getAbortOnFailure());
        ruleLinePrefix.setRuleGroupName(rule.getRuleGroup().getRuleGroupName());
        ruleLinePrefix.setCreateUser(rule.getCreateUser());
        ruleLinePrefix.setCreateTime(rule.getCreateTime());
        ruleLinePrefix.setModifyUser(rule.getModifyUser());
        ruleLinePrefix.setModifyTime(rule.getModifyTime());
        ruleLinePrefix.setDeleteFailCheckResult(rule.getDeleteFailCheckResult());
        lines.add(ruleLinePrefix);
        for (RuleDataSource ruleDataSource : rule.getRuleDataSources()) {
            String clusterName = ruleDataSource.getClusterName();
            String databaseName = ruleDataSource.getDbName();
            String tableName = ruleDataSource.getTableName();
            String filter = ruleDataSource.getFilter();
            ExcelTemplateFileRuleByProject tmp = new ExcelTemplateFileRuleByProject(rule.getName());
            tmp.setClusterName(clusterName);
            tmp.setDatabaseName(databaseName);
            tmp.setTableName(tableName);
            tmp.setFilter(filter);
            LOGGER.info("Collect excel line: {}", tmp);
            lines.add(tmp);
        }
        for (AlarmConfig alarmConfig : rule.getAlarmConfigs()) {
            Double threshold = alarmConfig.getThreshold();
            String alarmCompareType = CompareTypeEnum.getCompareTypeName(alarmConfig.getCompareType());
            String alarmOutputName = FileOutputNameEnum.getFileOutputName(alarmConfig.getFileOutputName(), localeStr);
            String checkTemplateName = CheckTemplateEnum.getCheckTemplateName(alarmConfig.getCheckTemplate(), localeStr);
            String unit = alarmConfig.getFileOutputUnit() == null ? "" : FileOutputUnitEnum.fileOutputUnit(alarmConfig.getFileOutputUnit());
            ExcelTemplateFileRuleByProject tmp = new ExcelTemplateFileRuleByProject(rule.getName());
            tmp.setUnit(unit);
            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());
            }
            LOGGER.info("Collect excel line: {}", tmp);
            lines.add(tmp);
        }
    }
    return lines;
}
Also used : RuleMetric(com.webank.wedatasphere.qualitis.entity.RuleMetric) RuleDataSource(com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource) ArrayList(java.util.ArrayList) ExcelTemplateFileRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateFileRuleByProject) Rule(com.webank.wedatasphere.qualitis.rule.entity.Rule) AlarmConfig(com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)

Example 3 with ExcelTemplateFileRuleByProject

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

the class RuleBatchServiceImpl method constructAddFileRuleRequest.

private List<AddFileRuleRequest> constructAddFileRuleRequest(Map<String, List<ExcelTemplateFileRuleByProject>> fileRulePartitionedByRuleName, Project project, String localeStr) throws UnExpectedRequestException {
    List<AddFileRuleRequest> addFileRuleRequests = new ArrayList<>();
    for (String ruleName : fileRulePartitionedByRuleName.keySet()) {
        List<ExcelTemplateFileRuleByProject> ruleInfos = fileRulePartitionedByRuleName.get(ruleName);
        ExcelTemplateFileRuleByProject firstCommonInfo = ruleInfos.get(0);
        AddFileRuleRequest addFileRuleRequest = new AddFileRuleRequest();
        String ruleGroupName = firstCommonInfo.getRuleGroupName();
        if (StringUtils.isBlank(ruleGroupName)) {
            throw new UnExpectedRequestException("RuleGroupName {&CAN_NOT_BE_NULL_OR_EMPTY}");
        }
        boolean alarm = false;
        List<FileAlarmConfigRequest> alarmConfigRequests = new ArrayList<>();
        DataSourceRequest dataSourceRequest = new DataSourceRequest();
        Long projectId = project.getId();
        for (ExcelTemplateFileRuleByProject excelTemplateFileRule : ruleInfos) {
            getDataFileSourceRequest(dataSourceRequest, excelTemplateFileRule);
            getFileAlarmConfig(alarmConfigRequests, excelTemplateFileRule, localeStr);
        }
        RuleGroup ruleGroupInDb = ruleGroupDao.findByRuleGroupNameAndProjectId(ruleGroupName, projectId);
        if (ruleGroupInDb != null) {
            addFileRuleRequest.setRuleGroupId(ruleGroupInDb.getId());
        } else {
            RuleGroup ruleGroup = ruleGroupDao.saveRuleGroup(new RuleGroup(ruleGroupName, project.getId()));
            addFileRuleRequest.setRuleGroupId(ruleGroup.getId());
        }
        // Construct addRuleRequest
        addFileRuleRequest.setRuleName(ruleName);
        addFileRuleRequest.setRuleDetail(firstCommonInfo.getRuleDetail());
        addFileRuleRequest.setAbortOnFailure(firstCommonInfo.getAbortOnFailure());
        if (!alarmConfigRequests.isEmpty()) {
            alarm = true;
        }
        addFileRuleRequest.setAlarm(alarm);
        addFileRuleRequest.setAlarmVariable(alarmConfigRequests);
        addFileRuleRequest.setDatasource(dataSourceRequest);
        addFileRuleRequest.setProjectId(projectId);
        addFileRuleRequests.add(addFileRuleRequest);
    }
    return addFileRuleRequests;
}
Also used : DataSourceRequest(com.webank.wedatasphere.qualitis.rule.request.DataSourceRequest) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) ArrayList(java.util.ArrayList) FileAlarmConfigRequest(com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest) RuleGroup(com.webank.wedatasphere.qualitis.rule.entity.RuleGroup) AddFileRuleRequest(com.webank.wedatasphere.qualitis.rule.request.AddFileRuleRequest) ExcelTemplateFileRuleByProject(com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateFileRuleByProject)

Example 4 with ExcelTemplateFileRuleByProject

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

ExcelTemplateFileRuleByProject (com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateFileRuleByProject)4 ArrayList (java.util.ArrayList)3 ExcelCustomRuleByProject (com.webank.wedatasphere.qualitis.project.excel.ExcelCustomRuleByProject)2 ExcelMultiTemplateRuleByProject (com.webank.wedatasphere.qualitis.project.excel.ExcelMultiTemplateRuleByProject)2 ExcelTemplateRuleByProject (com.webank.wedatasphere.qualitis.project.excel.ExcelTemplateRuleByProject)2 RuleMetric (com.webank.wedatasphere.qualitis.entity.RuleMetric)1 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)1 AlarmConfig (com.webank.wedatasphere.qualitis.rule.entity.AlarmConfig)1 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)1 RuleDataSource (com.webank.wedatasphere.qualitis.rule.entity.RuleDataSource)1 RuleGroup (com.webank.wedatasphere.qualitis.rule.entity.RuleGroup)1 AddFileRuleRequest (com.webank.wedatasphere.qualitis.rule.request.AddFileRuleRequest)1 DataSourceRequest (com.webank.wedatasphere.qualitis.rule.request.DataSourceRequest)1 FileAlarmConfigRequest (com.webank.wedatasphere.qualitis.rule.request.FileAlarmConfigRequest)1 OutputStream (java.io.OutputStream)1 Date (java.util.Date)1 List (java.util.List)1