use of com.webank.wedatasphere.qualitis.project.response.HiveRuleDetail in project Qualitis by WeBankFinTech.
the class RuleMetricServiceImpl method getRulesByRuleMetric.
@Override
public DataInfo<HiveRuleDetail> getRulesByRuleMetric(long id, int page, int size) throws UnExpectedRequestException {
DataInfo<HiveRuleDetail> dataInfo = new DataInfo<>();
if (id <= 0) {
throw new UnExpectedRequestException("{&REQUEST_CAN_NOT_BE_NULL}");
}
// Check rule metric existence.
RuleMetric ruleMetricInDb = ruleMetricDao.findById(id);
if (ruleMetricInDb == null) {
throw new UnExpectedRequestException("Rule Metric ID [" + id + "] {&DOES_NOT_EXIST}");
}
List<Long> ruleIds = taskResultDao.findRuleByRuleMetric(ruleMetricInDb.getId(), page, size).stream().distinct().collect(Collectors.toList());
int total = taskResultDao.countRuleByRuleMetric(ruleMetricInDb.getId());
List<HiveRuleDetail> result = new ArrayList<>(ruleIds.size());
for (Long ruleId : ruleIds) {
Rule ruleInDb = ruleDao.findById(ruleId);
if (ruleInDb == null) {
total--;
continue;
}
List<Long> ruleMetricIds = ruleInDb.getAlarmConfigs().stream().map(AlarmConfig::getRuleMetric).filter(ruleMetric -> ruleMetric != null).map(RuleMetric::getId).collect(Collectors.toList());
if (ruleInDb != null && ruleMetricIds.contains(id)) {
HiveRuleDetail hiveRuleDetail = new HiveRuleDetail(ruleInDb);
result.add(hiveRuleDetail);
}
}
dataInfo.setContent(result);
dataInfo.setTotalCount(total);
return dataInfo;
}
use of com.webank.wedatasphere.qualitis.project.response.HiveRuleDetail in project Qualitis by WeBankFinTech.
the class RuleQueryServiceImpl method getRulesByColumn.
@Override
public DataInfo<HiveRuleDetail> getRulesByColumn(String cluster, String db, String table, String column, String userName, int page, int size) {
LOGGER.info("Start to get rules with column. cluster: {}, db: {}, table: {}, column: {}", cluster, db, table, column);
DataInfo<HiveRuleDetail> dataInfo = new DataInfo<>();
List<Rule> rules = ruleDataSourceDao.findRuleByDataSource(cluster, db, table, column, userName, page, size);
int total = ruleDataSourceDao.countRuleByDataSource(cluster, db, table, column, userName);
if (rules == null || rules.isEmpty()) {
return null;
}
List<HiveRuleDetail> result = new ArrayList<>(rules.size());
LOGGER.info("Success to get rules with column. Rules: {}", rules);
for (Rule rule : rules) {
HiveRuleDetail hiveRuleDetail = new HiveRuleDetail(rule);
hiveRuleDetail.setTemplateName(rule.getRuleTemplateName());
result.add(hiveRuleDetail);
}
dataInfo.setContent(result);
dataInfo.setTotalCount(total);
return dataInfo;
}
Aggregations