use of com.webank.wedatasphere.qualitis.response.TaskCheckResultResponse in project Qualitis by WeBankFinTech.
the class TaskServiceImpl method getTaskDetail.
@Override
public GeneralResponse<?> getTaskDetail(Long taskId) throws UnExpectedRequestException {
Task taskInDb = taskDao.findById(taskId);
if (taskInDb == null) {
throw new UnExpectedRequestException("Job id [" + taskId + "] {&DOES_NOT_EXIST}");
}
// FIXME:
List<TaskRuleAlarmConfig> distinct;
Set<TaskRuleSimple> taskRuleSimples = new HashSet<>(taskInDb.getTaskRuleSimples().size());
for (TaskRuleSimple taskRuleSimple : taskInDb.getTaskRuleSimples()) {
distinct = taskRuleSimple.getTaskRuleAlarmConfigList().stream().distinct().collect(Collectors.toList());
taskRuleSimple.setTaskRuleAlarmConfigList(distinct);
taskRuleSimples.add(taskRuleSimple);
}
taskInDb.setTaskRuleSimples(taskRuleSimples);
// Find single table verification rules
List<TaskRuleSimple> singleRuleIds = taskInDb.getTaskRuleSimples().stream().filter(taskRuleSimple -> taskRuleSimple.getRuleType().equals(RuleTypeEnum.SINGLE_TEMPLATE_RULE.getCode())).collect(Collectors.toList());
// Find all datasources of single table verification rules, and save it in the map
Map<TaskRuleSimple, List<TaskDataSource>> singleRuleDataSourceMap = new HashMap<>(singleRuleIds.size());
for (TaskRuleSimple taskRuleSimple : singleRuleIds) {
singleRuleDataSourceMap.put(taskRuleSimple, taskDataSourceDao.findByTaskAndRuleId(taskInDb, taskRuleSimple.getRuleId()));
}
// Find custom table verification rules
List<TaskRuleSimple> customRuleIds = taskInDb.getTaskRuleSimples().stream().filter(taskRuleSimple -> taskRuleSimple.getRuleType().equals(RuleTypeEnum.CUSTOM_RULE.getCode())).collect(Collectors.toList());
// Find all datasources of custom table verification rules, and save it in the map
Map<TaskRuleSimple, List<TaskDataSource>> customRuleDataSourceMap = new HashMap<>(customRuleIds.size());
for (TaskRuleSimple taskRuleSimple : customRuleIds) {
customRuleDataSourceMap.put(taskRuleSimple, taskDataSourceDao.findByTaskAndRuleId(taskInDb, taskRuleSimple.getRuleId()));
}
// Find multi-table verification rules
List<TaskRuleSimple> multiRuleIds = taskInDb.getTaskRuleSimples().stream().filter(taskRuleSimple -> taskRuleSimple.getRuleType().equals(RuleTypeEnum.MULTI_TEMPLATE_RULE.getCode())).collect(Collectors.toList());
// Find all datasources of multi-table verification rules, and save it in the map
Map<TaskRuleSimple, List<TaskDataSource>> multiRuleDataSourceMap = new HashMap<>(multiRuleIds.size());
for (TaskRuleSimple taskRuleSimple : multiRuleIds) {
multiRuleDataSourceMap.put(taskRuleSimple, taskDataSourceDao.findByTaskAndRuleId(taskInDb, taskRuleSimple.getRuleId()));
}
// Find file table verification rules
List<TaskRuleSimple> fileRuleIds = taskInDb.getTaskRuleSimples().stream().filter(taskRuleSimple -> taskRuleSimple.getRuleType().equals(RuleTypeEnum.FILE_TEMPLATE_RULE.getCode())).collect(Collectors.toList());
// Find all datasources of file table verification rules, and save it in the map
Map<TaskRuleSimple, List<TaskDataSource>> fileRuleDataSourceMap = new HashMap<>(fileRuleIds.size());
for (TaskRuleSimple taskRuleSimple : fileRuleIds) {
fileRuleDataSourceMap.put(taskRuleSimple, taskDataSourceDao.findByTaskAndRuleId(taskInDb, taskRuleSimple.getRuleId()));
}
List<Long> allRuleIds = new ArrayList<>();
for (TaskRuleSimple taskRuleSimple : taskInDb.getTaskRuleSimples()) {
allRuleIds.add(taskRuleSimple.getRuleId());
if (taskRuleSimple.getChildRuleSimple() != null) {
allRuleIds.add(taskRuleSimple.getChildRuleSimple().getRuleId());
}
}
List<TaskResult> allTaskResult = taskResultDao.findByApplicationIdAndRuleIn(taskInDb.getApplication().getId(), allRuleIds);
Map<Long, List<TaskResult>> allResultMap = new HashMap<>(allTaskResult.size());
for (TaskResult taskResult : allTaskResult) {
if (allResultMap.get(taskResult.getRuleId()) != null) {
allResultMap.get(taskResult.getRuleId()).add(taskResult);
} else {
List<TaskResult> taskResults = new ArrayList<>(1);
taskResults.add(taskResult);
allResultMap.put(taskResult.getRuleId(), taskResults);
}
}
TaskCheckResultResponse taskCheckResultResponse = new TaskCheckResultResponse(taskInDb, singleRuleDataSourceMap, customRuleDataSourceMap, multiRuleDataSourceMap, fileRuleDataSourceMap, allResultMap);
return new GeneralResponse<>("200", "{&SUCCEED_TO_GET_TASK_DETAIL}", taskCheckResultResponse);
}
Aggregations