use of com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta in project Qualitis by WeBankFinTech.
the class AlarmConfigServiceImpl method checkAndSaveCustomAlarmVariable.
@Override
public List<AlarmConfig> checkAndSaveCustomAlarmVariable(List<CustomAlarmConfigRequest> requests, Rule rule) throws UnExpectedRequestException {
List<AlarmConfig> alarmConfigs = new ArrayList<>();
List<RuleMetric> ruleMetrics = new ArrayList<>();
for (CustomAlarmConfigRequest request : requests) {
AlarmConfig newAlarmConfig = new AlarmConfig();
RuleMetric ruleMetric = ruleMetricDao.findByEnCode(request.getRuleMetricEnCode());
newAlarmConfig.setRuleMetric(ruleMetric);
ruleMetrics.add(ruleMetric);
// Check existence of templateOutputMeta
TemplateOutputMeta templateOutputMetaInDb = rule.getTemplate().getTemplateOutputMetas().stream().filter(f -> f.getOutputName().equals(ruleMetric.getName())).iterator().next();
// Generate alarmConfig and save
newAlarmConfig.setRule(rule);
newAlarmConfig.setTemplateOutputMeta(templateOutputMetaInDb);
newAlarmConfig.setCheckTemplate(request.getCheckTemplate());
newAlarmConfig.setThreshold(request.getThreshold());
Integer checkTemplateCode = request.getCheckTemplate();
if (checkTemplateCode.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())) {
newAlarmConfig.setCompareType(request.getCompareType());
}
newAlarmConfig.setUploadAbnormalValue(request.getUploadAbnormalValue());
newAlarmConfig.setUploadRuleMetricValue(request.getUploadRuleMetricValue());
newAlarmConfig.setDeleteFailCheckResult(request.getDeleteFailCheckResult());
alarmConfigs.add(newAlarmConfig);
}
Set<String> deptNames = ruleMetrics.stream().map(RuleMetric::getDepartmentName).collect(Collectors.toSet());
if (deptNames.size() > 1) {
throw new UnExpectedRequestException("{&NOT_SAME_DEPT_SYS_METRIC}");
}
return alarmConfigDao.saveAllAlarmConfig(alarmConfigs);
}
use of com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta in project Qualitis by WeBankFinTech.
the class AlarmConfigServiceImpl method checkAndSaveAlarmVariable.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public List<AlarmConfig> checkAndSaveAlarmVariable(List<AlarmConfigRequest> requests, Rule rule) throws UnExpectedRequestException {
List<AlarmConfig> alarmConfigs = new ArrayList<>();
for (AlarmConfigRequest request : requests) {
// Check Arguments
AlarmConfigRequest.checkRequest(request);
// Check existence of templateOutputMeta
TemplateOutputMeta templateOutputMetaInDb = templateOutputMetaService.checkTemplateOutputMetaId(request.getOutputMetaId());
// return if is multi-table template
if (isChildOrParentOutput(rule.getTemplate(), templateOutputMetaInDb)) {
continue;
}
// Check template output meta
checkTemplateContain(rule.getTemplate(), templateOutputMetaInDb);
// Generate alarmConfig and save
AlarmConfig newAlarmConfig = new AlarmConfig();
newAlarmConfig.setRule(rule);
newAlarmConfig.setTemplateOutputMeta(templateOutputMetaInDb);
newAlarmConfig.setCheckTemplate(request.getCheckTemplate());
newAlarmConfig.setThreshold(request.getThreshold());
Integer checkTemplateCode = request.getCheckTemplate();
if (checkTemplateCode.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())) {
newAlarmConfig.setCompareType(request.getCompareType());
}
if (StringUtils.isNotBlank(request.getRuleMetricEnCode())) {
RuleMetric ruleMetric = ruleMetricDao.findByEnCode(request.getRuleMetricEnCode());
newAlarmConfig.setRuleMetric(ruleMetric);
newAlarmConfig.setUploadAbnormalValue(request.getUploadAbnormalValue());
newAlarmConfig.setUploadRuleMetricValue(request.getUploadRuleMetricValue());
}
alarmConfigs.add(newAlarmConfig);
}
return alarmConfigDao.saveAllAlarmConfig(alarmConfigs);
}
use of com.webank.wedatasphere.qualitis.rule.entity.TemplateOutputMeta in project Qualitis by WeBankFinTech.
the class RuleTemplateServiceImpl method getRuleTemplateMeta.
@Override
public GeneralResponse<TemplateMetaResponse> getRuleTemplateMeta(Long ruleTemplateId) throws UnExpectedRequestException {
// Find rule template by id
Template templateInDb = ruleTemplateDao.findById(ruleTemplateId);
if (null == templateInDb) {
throw new UnExpectedRequestException("rule_template_id {&CAN_NOT_BE_NULL_OR_EMPTY}");
}
// Find input meta data by template
List<TemplateMidTableInputMeta> templateMidTableInputMetas = templateMidTableInputMetaDao.findByRuleTemplate(templateInDb);
List<TemplateOutputMeta> templateOutputMetas = templateOutputMetaDao.findByRuleTemplate(templateInDb);
List<Integer> types = templateDataSourceTypeDao.findByTemplate(templateInDb).stream().map(TemplateDataSourceType::getDataSourceTypeId).collect(Collectors.toList());
TemplateMetaResponse response = new TemplateMetaResponse(templateInDb, templateMidTableInputMetas, 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 TemplateOutputMetaServiceImpl method getAndSaveTemplateOutputMeta.
@Override
@Transactional(rollbackFor = RuntimeException.class)
public Set<TemplateOutputMeta> getAndSaveTemplateOutputMeta(String outputName, Integer functionType, Boolean saveMidTable, Template template) {
Set<TemplateOutputMeta> templateOutputMetas = new HashSet<>();
TemplateOutputMeta templateOutputMeta = new TemplateOutputMeta();
templateOutputMeta.setTemplate(template);
templateOutputMeta.setOutputName(outputName);
if (saveMidTable) {
templateOutputMeta.setFieldName(FunctionTypeEnum.getByCode(functionType).getFunction());
} else {
templateOutputMeta.setFieldName(FunctionTypeEnum.MAX_FUNCTION.getFunction());
}
templateOutputMeta.setFieldType(FieldTypeEnum.NUMBER.getCode());
TemplateOutputMeta savedTemplateOutputMeta = templateOutputMetaDao.saveTemplateOutputMeta(templateOutputMeta);
LOGGER.info("Succeed to save template output_meta: {}", templateOutputMeta);
templateOutputMetas.add(savedTemplateOutputMeta);
return templateOutputMetas;
}
Aggregations