use of com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta in project Qualitis by WeBankFinTech.
the class RuleTemplateServiceImpl method getRuleMultiTemplateMeta.
/**
* Get meta data information by template_id
* @param ruleTemplateId
* @return
* @throws UnExpectedRequestException
*/
@Override
public GeneralResponse<TemplateMetaResponse> getRuleMultiTemplateMeta(Long ruleTemplateId) throws UnExpectedRequestException {
// Find rule template by rule template id
Template templateInDb = ruleTemplateDao.findById(ruleTemplateId);
if (null == templateInDb) {
throw new UnExpectedRequestException("rule_template_id {&CAN_NOT_BE_NULL_OR_EMPTY}");
}
// Find meta data of template
List<TemplateOutputMeta> templateOutputMetas = templateOutputMetaDao.findByRuleTemplate(templateInDb);
// Add child template
if (templateInDb.getChildTemplate() != null) {
templateOutputMetas.addAll(templateOutputMetaDao.findByRuleTemplate(templateInDb.getChildTemplate()));
}
List<Integer> types = templateDataSourceTypeDao.findByTemplate(templateInDb).stream().map(TemplateDataSourceType::getDataSourceTypeId).collect(Collectors.toList());
TemplateMetaResponse response = new TemplateMetaResponse(templateInDb, templateOutputMetas, types);
LOGGER.info("Succeed to get rule_template, rule template id: {}", ruleTemplateId);
return new GeneralResponse<>("200", "{&GET_RULE_TEMPLATE_META_SUCCESSFULLY}", response);
}
use of com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta in project Qualitis by WeBankFinTech.
the class RuleBatchServiceImpl method getAlarmConfig.
private void getAlarmConfig(List<AlarmConfigRequest> alarmConfigRequests, ExcelMultiTemplateRuleByProject excelMultiTemplateRule, Template template, String localeStr) throws UnExpectedRequestException {
String templateOutputName = excelMultiTemplateRule.getAlarmCheckName();
if (!StringUtils.isBlank(templateOutputName)) {
String checkTemplateName = excelMultiTemplateRule.getCheckTemplateName();
String compareTypeName = excelMultiTemplateRule.getCompareType();
String threshold = excelMultiTemplateRule.getThreshold();
TemplateOutputMeta templateOutputMeta = findTemplateOutputMetaByTemplateAndOutputName(template, templateOutputName);
if (template.getChildTemplate() != null && templateOutputMeta == null) {
templateOutputMeta = findTemplateOutputMetaByTemplateAndOutputName(template.getChildTemplate(), templateOutputName);
}
if (templateOutputMeta == null) {
throw new UnExpectedRequestException("{&TEMPLATE_OUTPUT_NAME} {&DOES_NOT_EXIST}");
}
AlarmConfigRequest alarmConfigRequest = new AlarmConfigRequest();
alarmConfigRequest.setCheckTemplate(CheckTemplateEnum.getCheckTemplateCode(checkTemplateName, localeStr));
alarmConfigRequest.setCompareType(CompareTypeEnum.getCompareTypeCode(compareTypeName));
alarmConfigRequest.setThreshold(Double.valueOf(threshold));
alarmConfigRequest.setOutputMetaId(templateOutputMeta.getId());
// Rule Metric.
String ruleMetricEnCode = excelMultiTemplateRule.getRuleMetricEnCode();
if (StringUtils.isNotBlank(ruleMetricEnCode)) {
// xx_xx_xx_encode, index is 3.
RuleMetric ruleMetricInDb = ruleMetricDao.findByEnCode(ruleMetricEnCode);
if (ruleMetricInDb == null) {
throw new UnExpectedRequestException("Rule metric[Code=" + ruleMetricEnCode + "] " + "{&DOES_NOT_EXIST}");
}
String code = ruleMetricInDb.getEnCode();
alarmConfigRequest.setRuleMetricEnCode(code);
}
alarmConfigRequest.setUploadRuleMetricValue(excelMultiTemplateRule.getUploadRuleMetricValue());
alarmConfigRequest.setUploadAbnormalValue(excelMultiTemplateRule.getUploadAbnormalValue());
alarmConfigRequests.add(alarmConfigRequest);
}
}
use of com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta in project Qualitis by WeBankFinTech.
the class RuleNodeServiceImpl method importRuleReal.
private void importRuleReal(RuleNodeRequest ruleNodeRequest, Rule ruleInDb, Rule rule, Project projectInDb, Template template, RuleGroup ruleGroup, Set<AlarmConfig> alarmConfigs, Set<RuleVariable> ruleVariables, Set<RuleDataSource> ruleDataSources, Set<RuleDataSourceMapping> ruleDataSourceMappings) throws IOException, UnExpectedRequestException {
if (ruleInDb == null) {
LOGGER.info("Import in first time. That means adding.");
rule.setProject(projectInDb);
ruleGroup.setProjectId(projectInDb.getId());
if (RuleTypeEnum.CUSTOM_RULE.getCode().equals(rule.getRuleType())) {
Template saveTemplate = ruleTemplateDao.saveTemplate(template);
Set<Integer> templateDateTypes = ruleDataSources.stream().filter(currRuleDataSource -> currRuleDataSource.getDatasourceType() != null).map(RuleDataSource::getDatasourceType).collect(Collectors.toSet());
for (Integer templateDataType : templateDateTypes) {
TemplateDataSourceType templateDataSourceType = new TemplateDataSourceType(templateDataType, saveTemplate);
templateDataSourceTypeDao.save(templateDataSourceType);
}
Set<TemplateStatisticsInputMeta> templateStatisticsInputMetas = new HashSet<>();
Set<TemplateOutputMeta> templateOutputMetaSet = new HashSet<>();
if (rule.getOutputName() != null && rule.getFunctionType() != null && rule.getFunctionContent() != null) {
templateStatisticsInputMetas = templateStatisticsInputMetaService.getAndSaveTemplateStatisticsInputMeta(rule.getOutputName(), rule.getFunctionType(), rule.getFunctionContent(), saveTemplate.getSaveMidTable(), saveTemplate);
templateOutputMetaSet = templateOutputMetaService.getAndSaveTemplateOutputMeta(rule.getOutputName(), rule.getFunctionType(), saveTemplate.getSaveMidTable(), saveTemplate);
} else {
List<RuleMetric> ruleMetrics = alarmConfigs.stream().map(AlarmConfig::getRuleMetric).collect(Collectors.toList());
for (RuleMetric ruleMetric : ruleMetrics) {
templateStatisticsInputMetas.addAll(templateStatisticsInputMetaService.getAndSaveTemplateStatisticsInputMeta(ruleMetric.getName(), FunctionTypeEnum.MAX_FUNCTION.getCode(), ruleMetric.getName(), saveTemplate.getSaveMidTable(), saveTemplate));
templateOutputMetaSet.addAll(templateOutputMetaService.getAndSaveTemplateOutputMeta(ruleMetric.getName(), FunctionTypeEnum.MAX_FUNCTION.getCode(), saveTemplate.getSaveMidTable(), saveTemplate));
}
}
saveTemplate.setStatisticAction(templateStatisticsInputMetas);
saveTemplate.setTemplateOutputMetas(templateOutputMetaSet);
rule.setTemplate(saveTemplate);
} else if (RuleTypeEnum.FILE_TEMPLATE_RULE.getCode().equals(rule.getRuleType())) {
LOGGER.info("Start to import file rule. {}", rule.getName());
// Save file rule template.
rule.setTemplate(ruleTemplateDao.saveTemplate(template));
// Save file rule group
rule.setRuleGroup(ruleGroup);
Rule savedRule = ruleDao.saveRule(rule);
// Save file alarmconfig
List<AlarmConfig> alarmConfigList = new ArrayList<>();
for (AlarmConfig alarmConfig : alarmConfigs) {
ruleMetricSycn(alarmConfig);
alarmConfig.setRule(savedRule);
alarmConfigList.add(alarmConfig);
}
List<RuleDataSource> ruleDataSourceList = new ArrayList<>();
for (RuleDataSource ruleDataSource : ruleDataSources) {
ruleDataSource.setProjectId(projectInDb.getId());
ruleDataSource.setRule(savedRule);
ruleDataSourceList.add(ruleDataSource);
}
savedRule.setAlarmConfigs(new HashSet<>(alarmConfigDao.saveAllAlarmConfig(alarmConfigList)));
savedRule.setRuleDataSources(new HashSet<>(ruleDataSourceDao.saveAllRuleDataSource(ruleDataSourceList)));
LOGGER.info("Finish to import file rule. {}", rule.getName());
return;
} else {
// When trying out the newly created rule template in the development center, the production center needs to synchronize the rule template.
synchroRuleTemplate(ruleNodeRequest, rule, template, ruleDataSources);
}
rule.setRuleGroup(ruleGroup);
Rule savedRule = ruleDao.saveRule(rule);
saveRuleInfo(savedRule, template, projectInDb, alarmConfigs, ruleVariables, ruleDataSources, ruleDataSourceMappings);
if (ruleNodeRequest.getChildRuleObject() != null) {
importChildRule(savedRule, ruleGroup, ruleNodeRequest, projectInDb);
}
} else {
LOGGER.info("Import multiple times. That is to update.");
if (RuleTypeEnum.FILE_TEMPLATE_RULE.getCode().equals(rule.getRuleType())) {
LOGGER.info("Start to update import file rule. {}", rule.getName());
Set<AlarmConfig> alarmConfigList = new HashSet<>();
for (AlarmConfig alarmConfig : alarmConfigs) {
ruleMetricSycn(alarmConfig);
alarmConfig.setRule(ruleInDb);
alarmConfigList.add(alarmConfig);
}
updateImportedFileRule(rule, ruleInDb, ruleGroup, alarmConfigList, ruleDataSources);
LOGGER.info("Finish to update import file rule. {}", rule.getName());
return;
}
updateImportedRule(rule, ruleInDb, ruleGroup, ruleNodeRequest, template, alarmConfigs, ruleVariables, ruleDataSources, ruleDataSourceMappings);
}
}
use of com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta in project Qualitis by WeBankFinTech.
the class RuleNodeServiceImpl method updateImportedRule.
public void updateImportedRule(Rule rule, Rule ruleInDb, RuleGroup ruleGroup, RuleNodeRequest ruleNodeRequest, Template template, Set<AlarmConfig> alarmConfigs, Set<RuleVariable> ruleVariables, Set<RuleDataSource> ruleDataSources, Set<RuleDataSourceMapping> ruleDataSourceMappings) throws UnExpectedRequestException, IOException {
ruleInDb.setRuleGroup(ruleGroup);
ruleInDb.setAlarm(rule.getAlarm());
ruleInDb.setAbortOnFailure(rule.getAbortOnFailure());
ruleInDb.setFromContent(rule.getFromContent());
ruleInDb.setWhereContent(rule.getWhereContent());
ruleInDb.setRuleType(rule.getRuleType());
ruleInDb.setRuleTemplateName(template.getName());
ruleInDb.setOutputName(rule.getOutputName());
ruleInDb.setFunctionType(rule.getFunctionType());
ruleInDb.setFunctionContent(rule.getFunctionContent());
ruleInDb.setDeleteFailCheckResult(rule.getDeleteFailCheckResult());
if (RuleTypeEnum.CUSTOM_RULE.getCode().equals(rule.getRuleType())) {
ruleTemplateService.deleteCustomTemplate(ruleInDb.getTemplate());
Template savedTemplate = ruleTemplateDao.saveTemplate(template);
Set<TemplateStatisticsInputMeta> templateStatisticsInputMetas = new HashSet<>();
Set<TemplateOutputMeta> templateOutputMetaSet = new HashSet<>();
if (rule.getOutputName() != null && rule.getFunctionType() != null && rule.getFunctionContent() != null) {
templateStatisticsInputMetas = templateStatisticsInputMetaService.getAndSaveTemplateStatisticsInputMeta(rule.getOutputName(), rule.getFunctionType(), rule.getFunctionContent(), savedTemplate.getSaveMidTable(), savedTemplate);
templateOutputMetaSet = templateOutputMetaService.getAndSaveTemplateOutputMeta(rule.getOutputName(), rule.getFunctionType(), savedTemplate.getSaveMidTable(), savedTemplate);
} else {
List<RuleMetric> ruleMetrics = alarmConfigs.stream().map(AlarmConfig::getRuleMetric).collect(Collectors.toList());
for (RuleMetric ruleMetric : ruleMetrics) {
templateStatisticsInputMetas.addAll(templateStatisticsInputMetaService.getAndSaveTemplateStatisticsInputMeta(ruleMetric.getName(), FunctionTypeEnum.MAX_FUNCTION.getCode(), ruleMetric.getName(), savedTemplate.getSaveMidTable(), savedTemplate));
templateOutputMetaSet.addAll(templateOutputMetaService.getAndSaveTemplateOutputMeta(ruleMetric.getName(), FunctionTypeEnum.MAX_FUNCTION.getCode(), savedTemplate.getSaveMidTable(), savedTemplate));
}
}
savedTemplate.setStatisticAction(templateStatisticsInputMetas);
savedTemplate.setTemplateOutputMetas(templateOutputMetaSet);
ruleInDb.setTemplate(savedTemplate);
} else {
synchroRuleTemplate(ruleNodeRequest, ruleInDb, template, ruleDataSources);
}
alarmConfigService.deleteByRule(ruleInDb);
LOGGER.info("Succeed to delete all alarm_config. rule_id: {}", ruleInDb.getId());
Integer ruleType = ruleInDb.getRuleType();
if (RuleTypeEnum.SINGLE_TEMPLATE_RULE.getCode().equals(ruleType) || RuleTypeEnum.MULTI_TEMPLATE_RULE.getCode().equals(ruleType)) {
ruleVariableService.deleteByRule(ruleInDb);
LOGGER.info("Succeed to delete all rule_variable. rule_id: {}", ruleInDb.getId());
if (RuleTypeEnum.MULTI_TEMPLATE_RULE.getCode().equals(ruleType)) {
ruleDataSourceMappingService.deleteByRule(ruleInDb);
LOGGER.info("Succeed to delete all rule_dataSource_mapping. rule_id: {}", ruleInDb.getId());
}
}
ruleDataSourceService.deleteByRule(ruleInDb);
LOGGER.info("Succeed to delete all rule_dataSources. rule_id: {}", ruleInDb.getId());
Rule updateRule = ruleDao.saveRule(ruleInDb);
saveRuleInfo(updateRule, template, updateRule.getProject(), alarmConfigs, ruleVariables, ruleDataSources, ruleDataSourceMappings);
updateImportedChildRule(updateRule, ruleNodeRequest);
}
use of com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta in project Qualitis by WeBankFinTech.
the class RuleNodeServiceImpl method synchroRuleTemplate.
public void synchroRuleTemplate(RuleNodeRequest ruleNodeRequest, Rule rule, Template template, Set<RuleDataSource> ruleDataSources) throws IOException {
Template templateInDb = ruleTemplateDao.findById(template.getId());
Template templateNameInDb = null;
if (StringUtils.isNotBlank(template.getImportExportName())) {
templateNameInDb = ruleTemplateDao.findByImportExportName(template.getImportExportName());
}
if (templateInDb == null && templateNameInDb == null) {
LOGGER.info("Start to synchronize the rule template. Template: {}", template);
ObjectMapper objectMapper = new ObjectMapper();
// Template meta info.
Set<TemplateOutputMeta> templateOutputMetaSet = objectMapper.readValue(ruleNodeRequest.getTemplateTemplateOutputMetaObject(), new TypeReference<Set<TemplateOutputMeta>>() {
});
Set<TemplateMidTableInputMeta> templateMidTableInputMetaSet = objectMapper.readValue(ruleNodeRequest.getTemplateTemplateMidTableInputMetaObject(), new TypeReference<Set<TemplateMidTableInputMeta>>() {
});
Set<TemplateStatisticsInputMeta> templateStatisticsInputMetaSet = objectMapper.readValue(ruleNodeRequest.getTemplateTemplateStatisticsInputMetaObject(), new TypeReference<Set<TemplateStatisticsInputMeta>>() {
});
Template savedTemplate = ruleTemplateDao.saveTemplate(template);
Set<TemplateOutputMeta> templateOutputMetas = new HashSet<>();
for (TemplateOutputMeta outputMeta : templateOutputMetaSet) {
outputMeta.setTemplate(savedTemplate);
templateOutputMetas.add(templateOutputMetaDao.saveTemplateOutputMeta(outputMeta));
}
savedTemplate.setTemplateOutputMetas(templateOutputMetas);
LOGGER.info("Success to save template output meta. TemplateOutputMetas: {}", savedTemplate.getTemplateOutputMetas());
List<TemplateMidTableInputMeta> templateMidTableInputMetas = new ArrayList<>();
for (TemplateMidTableInputMeta templateMidTableInputMeta : templateMidTableInputMetaSet) {
templateMidTableInputMeta.setTemplate(savedTemplate);
templateMidTableInputMetas.add(templateMidTableInputMeta);
}
templateMidTableInputMetas.sort(Comparator.comparing(TemplateMidTableInputMeta::getId));
savedTemplate.setTemplateMidTableInputMetas(templateMidTableInputMetaService.saveAll(templateMidTableInputMetas));
LOGGER.info("Success to save template mid_table input meta. TemplateMidTableInputMetas: {}", savedTemplate.getTemplateMidTableInputMetas());
List<TemplateStatisticsInputMeta> templateStatisticsInputMetas = new ArrayList<>();
for (TemplateStatisticsInputMeta templateStatisticsInputMeta : templateStatisticsInputMetaSet) {
templateStatisticsInputMeta.setTemplate(savedTemplate);
templateStatisticsInputMetas.add(templateStatisticsInputMeta);
}
savedTemplate.setStatisticAction(templateStatisticsInputMetaService.saveAll(templateStatisticsInputMetas));
LOGGER.info("Success to save template statistics input meta. templateStatisticsInputMetas: {}", savedTemplate.getStatisticAction());
Set<Integer> templateDateTypes = ruleDataSources.stream().filter(currRuleDataSource -> currRuleDataSource.getDatasourceType() != null).map(RuleDataSource::getDatasourceType).collect(Collectors.toSet());
for (Integer templateDataType : templateDateTypes) {
TemplateDataSourceType templateDataSourceType = new TemplateDataSourceType(templateDataType, savedTemplate);
templateDataSourceTypeDao.save(templateDataSourceType);
}
LOGGER.info("Success to save template data types. Template data types: {}", Arrays.toString(templateDateTypes.toArray()));
LOGGER.info("Finished to synchronize the rule template. Template: {}", savedTemplate);
rule.setTemplate(savedTemplate);
} else if (templateInDb != null) {
rule.setTemplate(templateInDb);
} else if (templateNameInDb != null) {
rule.setTemplate(templateNameInDb);
} else {
rule.setTemplate(template);
}
}
Aggregations