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;
}
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;
}
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;
}
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);
}
}
}
Aggregations