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, ExcelTemplateRuleByProject excelTemplateRule, Template template, String localeStr) throws UnExpectedRequestException {
String templateOutputName = excelTemplateRule.getAlarmCheckName();
if (!StringUtils.isBlank(templateOutputName)) {
String checkTemplateName = excelTemplateRule.getCheckTemplateName();
String compareTypeName = excelTemplateRule.getCompareType();
String threshold = excelTemplateRule.getThreshold();
TemplateOutputMeta templateOutputMeta = findTemplateOutputMetaByTemplateAndOutputName(template, 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 = excelTemplateRule.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(excelTemplateRule.getUploadRuleMetricValue());
alarmConfigRequest.setUploadAbnormalValue(excelTemplateRule.getUploadAbnormalValue());
alarmConfigRequests.add(alarmConfigRequest);
}
}
use of com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta in project Qualitis by WeBankFinTech.
the class RuleNodeServiceImpl method saveRuleInfo.
public void saveRuleInfo(Rule savedRule, Template template, Project projectInDb, Set<AlarmConfig> alarmConfigs, Set<RuleVariable> ruleVariables, Set<RuleDataSource> ruleDataSources, Set<RuleDataSourceMapping> ruleDataSourceMappings) {
LOGGER.info("Start to save rule Info.");
List<AlarmConfig> alarmConfigList = new ArrayList<>();
for (AlarmConfig alarmConfig : alarmConfigs) {
alarmConfig.setRule(savedRule);
ruleMetricSycn(alarmConfig);
alarmConfig.setTemplateOutputMeta(savedRule.getTemplate().getTemplateOutputMetas().iterator().next());
alarmConfigList.add(alarmConfig);
}
List<RuleVariable> ruleVariablesList = new ArrayList<>();
TemplateStatisticsInputMeta templateStatisticsInputMeta = savedRule.getTemplate().getStatisticAction().iterator().next();
for (RuleVariable ruleVariable : ruleVariables) {
ruleVariable.setRule(savedRule);
ruleVariable.setTemplateStatisticsInputMeta(templateStatisticsInputMeta);
ruleVariablesList.add(ruleVariable);
}
if (template.getId().intValue() != savedRule.getTemplate().getId().intValue()) {
ruleVariablesList.sort(Comparator.comparing(RuleVariable::getId));
List<TemplateMidTableInputMeta> templateMidTableInputMetaList = new ArrayList<>();
if (savedRule.getTemplate().getTemplateMidTableInputMetas() != null) {
templateMidTableInputMetaList.addAll(savedRule.getTemplate().getTemplateMidTableInputMetas());
templateMidTableInputMetaList.sort(Comparator.comparing(TemplateMidTableInputMeta::getId));
Iterator iterator = templateMidTableInputMetaList.iterator();
for (RuleVariable ruleVariable : ruleVariablesList) {
ruleVariable.setTemplateMidTableInputMeta((TemplateMidTableInputMeta) iterator.next());
}
}
}
List<RuleDataSource> ruleDataSourceList = new ArrayList<>();
for (RuleDataSource ruleDataSource : ruleDataSources) {
ruleDataSource.setProjectId(projectInDb.getId());
ruleDataSource.setRule(savedRule);
ruleDataSourceList.add(ruleDataSource);
}
if (RuleTypeEnum.CUSTOM_RULE.getCode().equals(savedRule.getRuleType())) {
List<AlarmConfig> customAlarmConfigs = new ArrayList<>();
for (AlarmConfig alarmConfig : alarmConfigList) {
TemplateOutputMeta templateOutputMetaInDb = savedRule.getTemplate().getTemplateOutputMetas().iterator().next();
AlarmConfig customAlarmConfig = new AlarmConfig();
customAlarmConfig.setRule(savedRule);
customAlarmConfig.setRuleMetric(alarmConfig.getRuleMetric());
customAlarmConfig.setThreshold(alarmConfig.getThreshold());
customAlarmConfig.setTemplateOutputMeta(templateOutputMetaInDb);
customAlarmConfig.setCheckTemplate(alarmConfig.getCheckTemplate());
Integer checkTemplateCode = alarmConfig.getCheckTemplate();
if (alarmConfig.getCheckTemplate().equals(CheckTemplateEnum.FIXED_VALUE.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.FULL_YEAR_RING_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.HALF_YEAR_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.SEASON_RING_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.MONTH_RING_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.WEEK_RING_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.DAY_RING_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.HOUR_RING_GROWTH.getCode()) || checkTemplateCode.equals(CheckTemplateEnum.YEAR_ON_YEAR.getCode())) {
customAlarmConfig.setCompareType(alarmConfig.getCompareType());
}
customAlarmConfigs.add(customAlarmConfig);
}
savedRule.setAlarmConfigs(new HashSet<>(alarmConfigDao.saveAllAlarmConfig(customAlarmConfigs)));
savedRule.setRuleDataSources(new HashSet<>(ruleDataSourceDao.saveAllRuleDataSource(ruleDataSourceList)));
} else {
savedRule.setAlarmConfigs(new HashSet<>(alarmConfigDao.saveAllAlarmConfig(alarmConfigList)));
savedRule.setRuleVariables(new HashSet<>(ruleVariableDao.saveAllRuleVariable(ruleVariablesList)));
savedRule.setRuleDataSources(new HashSet<>(ruleDataSourceDao.saveAllRuleDataSource(ruleDataSourceList)));
for (RuleDataSourceMapping ruleDataSourceMapping : ruleDataSourceMappings) {
ruleDataSourceMapping.setRule(savedRule);
ruleDataSourceMappingDao.saveRuleDataSourceMapping(ruleDataSourceMapping);
}
}
}
use of com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta in project Qualitis by WeBankFinTech.
the class RuleTemplateServiceImpl method addCustomTemplate.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public Template addCustomTemplate(AddCustomRuleRequest request) {
Template newTemplate = new Template();
newTemplate.setName(request.getProjectId() + "_" + request.getRuleName() + "_template");
newTemplate.setSaveMidTable(request.getSaveMidTable());
String sqlCheckArea = request.getSqlCheckArea();
if (StringUtils.isNotBlank(sqlCheckArea)) {
newTemplate.setMidTableAction(sqlCheckArea);
newTemplate.setTemplateType(RuleTemplateTypeEnum.CUSTOM.getCode());
newTemplate.setActionType(TemplateActionTypeEnum.SQL.getCode());
Template savedTemplate = ruleTemplateDao.saveTemplate(newTemplate);
LOGGER.info("Succeed to save custom template, template_id: {}", savedTemplate.getId());
// Generate statistics input meta by rule metric
Set<String> ruleMetricCodeSet = request.getAlarmVariable().stream().map(CustomAlarmConfigRequest::getRuleMetricEnCode).collect(Collectors.toSet());
Set<TemplateStatisticsInputMeta> templateStatisticsInputMetas = new HashSet<>(ruleMetricCodeSet.size());
Set<TemplateOutputMeta> templateOutputMetas = new HashSet<>(ruleMetricCodeSet.size());
for (String enCode : ruleMetricCodeSet) {
// xx_xx_xx_encode, index is 3.
RuleMetric ruleMetricInDb = ruleMetricDao.findByEnCode(enCode);
templateStatisticsInputMetas.addAll(templateStatisticsInputMetaService.getAndSaveTemplateStatisticsInputMeta(ruleMetricInDb.getName(), FunctionTypeEnum.MAX_FUNCTION.getCode(), ruleMetricInDb.getName(), true, savedTemplate));
templateOutputMetas.addAll(templateOutputMetaService.getAndSaveTemplateOutputMeta(ruleMetricInDb.getName(), FunctionTypeEnum.MAX_FUNCTION.getCode(), true, savedTemplate));
}
savedTemplate.setStatisticAction(templateStatisticsInputMetas);
savedTemplate.setTemplateOutputMetas(templateOutputMetas);
savedTemplate.setTemplateOutputMetas(templateOutputMetas);
return savedTemplate;
} else {
newTemplate.setMidTableAction(getMidTableAction(request));
newTemplate.setTemplateType(RuleTemplateTypeEnum.CUSTOM.getCode());
newTemplate.setActionType(TemplateActionTypeEnum.SQL.getCode());
Template savedTemplate = ruleTemplateDao.saveTemplate(newTemplate);
LOGGER.info("Succeed to save custom template, template_id: {}", savedTemplate.getId());
Set<TemplateStatisticsInputMeta> templateStatisticsInputMetas = templateStatisticsInputMetaService.getAndSaveTemplateStatisticsInputMeta(request.getOutputName(), request.getFunctionType(), request.getFunctionContent(), request.getSaveMidTable(), savedTemplate);
savedTemplate.setStatisticAction(templateStatisticsInputMetas);
Set<TemplateOutputMeta> templateOutputMetas = templateOutputMetaService.getAndSaveTemplateOutputMeta(request.getOutputName(), request.getFunctionType(), request.getSaveMidTable(), savedTemplate);
savedTemplate.setTemplateOutputMetas(templateOutputMetas);
return savedTemplate;
}
}
use of com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta in project Qualitis by WeBankFinTech.
the class RuleTemplateServiceImpl method getModifyRuleTemplateDetail.
@Override
public RuleTemplateResponse getModifyRuleTemplateDetail(Long templateId) throws UnExpectedRequestException {
// Check template existence
Template templateInDb = checkRuleTemplate(templateId);
RuleTemplateResponse response = new RuleTemplateResponse(templateInDb);
response.setClusterNum(templateInDb.getClusterNum());
response.setDbNum(templateInDb.getDbNum());
response.setTableNum(templateInDb.getTableNum());
response.setFieldNum(templateInDb.getFieldNum());
List<TemplateDataSourceType> templateDataSourceTypes = templateDataSourceTypeDao.findByTemplate(templateInDb);
response.setDatasourceType(templateDataSourceTypes.stream().map(TemplateDataSourceType::getDataSourceTypeId).collect(Collectors.toList()));
response.setActionType(templateInDb.getActionType());
response.setMidTableAction(templateInDb.getMidTableAction());
response.setSaveMidTable(templateInDb.getSaveMidTable());
List<TemplateOutputMetaResponse> outputMetaResponses = new ArrayList<>(1);
List<TemplateMidTableInputMetaResponse> midTableInputMetaResponses = new ArrayList<>(2);
List<TemplateStatisticsInputMetaResponse> statisticsInputMetaResponses = new ArrayList<>(1);
for (TemplateOutputMeta templateOutputMeta : templateInDb.getTemplateOutputMetas()) {
TemplateOutputMetaResponse templateOutputMetaResponse = new TemplateOutputMetaResponse();
templateOutputMetaResponse.setOutputName(templateOutputMeta.getOutputName());
outputMetaResponses.add(templateOutputMetaResponse);
}
response.setTemplateOutputMetaResponses(outputMetaResponses);
for (TemplateMidTableInputMeta templateMidTableInputMeta : templateInDb.getTemplateMidTableInputMetas()) {
TemplateMidTableInputMetaResponse templateMidTableInputMetaResponse = new TemplateMidTableInputMetaResponse();
templateMidTableInputMetaResponse.setName(templateMidTableInputMeta.getName());
templateMidTableInputMetaResponse.setPlaceholder(templateMidTableInputMeta.getPlaceholder());
templateMidTableInputMetaResponse.setPlaceholderDescription(templateMidTableInputMeta.getPlaceholderDescription());
templateMidTableInputMetaResponse.setInputType(templateMidTableInputMeta.getInputType());
midTableInputMetaResponses.add(templateMidTableInputMetaResponse);
}
response.setTemplateMidTableInputMetaResponses(midTableInputMetaResponses);
for (TemplateStatisticsInputMeta templateStatisticsInputMeta : templateInDb.getStatisticAction()) {
TemplateStatisticsInputMetaResponse templateStatisticsInputMetaResponse = new TemplateStatisticsInputMetaResponse();
templateStatisticsInputMetaResponse.setName(templateStatisticsInputMeta.getName());
templateStatisticsInputMetaResponse.setFuncName(templateStatisticsInputMeta.getFuncName());
templateStatisticsInputMetaResponse.setValue(templateStatisticsInputMeta.getValue());
templateStatisticsInputMetaResponse.setValueType(templateStatisticsInputMeta.getValueType());
statisticsInputMetaResponses.add(templateStatisticsInputMetaResponse);
}
response.setTemplateStatisticsInputMetaResponses(statisticsInputMetaResponses);
return response;
}
use of com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta in project Qualitis by WeBankFinTech.
the class RuleTemplateServiceImpl method createAndSaveTemplateInfo.
private void createAndSaveTemplateInfo(Template savedTemplate, AddRuleTemplateRequest request) {
// Save template output meta.
Set<TemplateOutputMeta> templateOutputMetas = new HashSet<>();
for (TemplateOutputMetaRequest templateOutputMetaRequest : request.getTemplateOutputMetaRequests()) {
templateOutputMetas.addAll(templateOutputMetaService.getAndSaveTemplateOutputMeta(templateOutputMetaRequest.getOutputName(), FunctionTypeEnum.getFunctionTypeByName(templateOutputMetaRequest.getFieldName()), request.getSaveMidTable(), savedTemplate));
}
savedTemplate.setTemplateOutputMetas(templateOutputMetas);
LOGGER.info("Success to save template output meta. TemplateOutputMetas: {}", savedTemplate.getTemplateOutputMetas());
// Save template mid_table input meta
List<TemplateMidTableInputMeta> templateMidTableInputMetas = new ArrayList<>();
for (TemplateMidTableInputMetaRequest templateMidTableInputMetaRequest : request.getTemplateMidTableInputMetaRequests()) {
TemplateMidTableInputMeta templateMidTableInputMeta = new TemplateMidTableInputMeta();
templateMidTableInputMeta.setName(templateMidTableInputMetaRequest.getName());
templateMidTableInputMeta.setFieldType(templateMidTableInputMetaRequest.getFieldType());
templateMidTableInputMeta.setInputType(templateMidTableInputMetaRequest.getInputType());
templateMidTableInputMeta.setPlaceholder(templateMidTableInputMetaRequest.getPlaceholder());
templateMidTableInputMeta.setPlaceholderDescription(templateMidTableInputMetaRequest.getPlaceholderDescription());
templateMidTableInputMeta.setRegexpType(templateMidTableInputMetaRequest.getRegexpType());
templateMidTableInputMeta.setReplaceByRequest(templateMidTableInputMetaRequest.getReplaceByRequest());
templateMidTableInputMeta.setTemplate(savedTemplate);
templateMidTableInputMetas.add(templateMidTableInputMeta);
}
savedTemplate.setTemplateMidTableInputMetas(templateMidTableInputMetaService.saveAll(templateMidTableInputMetas));
LOGGER.info("Success to save template mid_table input meta. TemplateMidTableInputMetas: {}", savedTemplate.getTemplateMidTableInputMetas());
// Save template statistics input meta
List<TemplateStatisticsInputMeta> templateStatisticsInputMetas = new ArrayList<>();
for (TemplateStatisticsInputMetaRequest templateStatisticsInputMetaRequest : request.getTemplateStatisticsInputMetaRequests()) {
TemplateStatisticsInputMeta templateStatisticsInputMeta = new TemplateStatisticsInputMeta();
templateStatisticsInputMeta.setName(templateStatisticsInputMetaRequest.getName());
templateStatisticsInputMeta.setFuncName(templateStatisticsInputMetaRequest.getFuncName());
templateStatisticsInputMeta.setResultType(templateStatisticsInputMetaRequest.getResultType());
templateStatisticsInputMeta.setValue(templateStatisticsInputMetaRequest.getValue());
templateStatisticsInputMeta.setValueType(templateStatisticsInputMetaRequest.getValueType());
templateStatisticsInputMeta.setTemplate(savedTemplate);
templateStatisticsInputMetas.add(templateStatisticsInputMeta);
}
savedTemplate.setStatisticAction(templateStatisticsInputMetaService.saveAll(templateStatisticsInputMetas));
LOGGER.info("Success to save template statistics input meta. templateStatisticsInputMetas: {}", savedTemplate.getStatisticAction());
}
Aggregations