use of com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest in project Qualitis by WeBankFinTech.
the class RuleBatchServiceImpl method getCustomAlarmConfig.
private void getCustomAlarmConfig(List<CustomAlarmConfigRequest> customAlarmConfigRequests, ExcelCustomRuleByProject excelCustomRule, String localeStr) throws UnExpectedRequestException {
String templateOutputName = excelCustomRule.getAlarmCheckName();
if (!StringUtils.isBlank(templateOutputName)) {
String checkTemplateName = excelCustomRule.getCheckTemplateName();
String compareTypeName = excelCustomRule.getCompareType();
String threshold = excelCustomRule.getThreshold();
CustomAlarmConfigRequest customAlarmConfigRequest = new CustomAlarmConfigRequest();
customAlarmConfigRequest.setCheckTemplate(CheckTemplateEnum.getCheckTemplateCode(checkTemplateName, localeStr));
customAlarmConfigRequest.setCompareType(CompareTypeEnum.getCompareTypeCode(compareTypeName));
customAlarmConfigRequest.setThreshold(Double.valueOf(threshold));
// Rule Metric.
String ruleMetricEnCode = excelCustomRule.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();
customAlarmConfigRequest.setRuleMetricEnCode(code);
}
customAlarmConfigRequest.setUploadRuleMetricValue(excelCustomRule.getUploadRuleMetricValue());
customAlarmConfigRequest.setUploadAbnormalValue(excelCustomRule.getUploadAbnormalValue());
customAlarmConfigRequests.add(customAlarmConfigRequest);
}
}
use of com.webank.wedatasphere.qualitis.rule.request.CustomAlarmConfigRequest 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);
}
Aggregations