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