Skip to content

Commit

Permalink
Reduce Cognitive Complexity for ConsistencyCheckJobAPI.getJobItemInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
sandynz committed Sep 19, 2023
1 parent 07a8d2c commit 9f05d33
Showing 1 changed file with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -313,16 +313,10 @@ private ConsistencyCheckJobItemInfo getJobItemInfo(final String parentJobId) {
}
fillInJobItemInfoWithTimes(result, jobItemProgress, jobConfigPOJO);
result.setTableNames(Optional.ofNullable(jobItemProgress.getTableNames()).orElse(""));
fillInJobItemInfoWithAlgorithm(result, checkJobId);
fillInJobItemInfoWithCheckAlgorithm(result, checkJobId);
result.setErrorMessage(getJobItemErrorMessage(checkJobId, 0));
Map<String, TableDataConsistencyCheckResult> checkJobResult = governanceRepositoryAPI.getCheckJobResult(parentJobId, checkJobId);
if (checkJobResult.isEmpty()) {
result.setCheckSuccess(null);
} else {
InventoryIncrementalJobAPI inventoryIncrementalJobAPI = (InventoryIncrementalJobAPI) TypedSPILoader.getService(
PipelineJobAPI.class, PipelineJobIdUtils.parseJobType(parentJobId).getType());
result.setCheckSuccess(inventoryIncrementalJobAPI.aggregateDataConsistencyCheckResults(parentJobId, checkJobResult));
}
fillInJobItemInfoWithCheckResult(result, checkJobResult, parentJobId);
result.setCheckFailedTableNames(checkJobResult.entrySet().stream().filter(each -> !each.getValue().isIgnored() && !each.getValue().isMatched())
.map(Entry::getKey).collect(Collectors.joining(",")));
return result;
Expand Down Expand Up @@ -353,14 +347,24 @@ private void fillInJobItemInfoWithTimes(final ConsistencyCheckJobItemInfo result
}
}

private void fillInJobItemInfoWithAlgorithm(final ConsistencyCheckJobItemInfo result, final String checkJobId) {
private void fillInJobItemInfoWithCheckAlgorithm(final ConsistencyCheckJobItemInfo result, final String checkJobId) {
ConsistencyCheckJobConfiguration jobConfig = getJobConfiguration(checkJobId);
result.setAlgorithmType(jobConfig.getAlgorithmTypeName());
if (null != jobConfig.getAlgorithmProps()) {
result.setAlgorithmProps(jobConfig.getAlgorithmProps().entrySet().stream().map(entry -> String.format("'%s'='%s'", entry.getKey(), entry.getValue())).collect(Collectors.joining(",")));
}
}

private void fillInJobItemInfoWithCheckResult(final ConsistencyCheckJobItemInfo result, final Map<String, TableDataConsistencyCheckResult> checkJobResult, final String parentJobId) {
if (checkJobResult.isEmpty()) {
result.setCheckSuccess(null);
} else {
InventoryIncrementalJobAPI inventoryIncrementalJobAPI = (InventoryIncrementalJobAPI) TypedSPILoader.getService(
PipelineJobAPI.class, PipelineJobIdUtils.parseJobType(parentJobId).getType());
result.setCheckSuccess(inventoryIncrementalJobAPI.aggregateDataConsistencyCheckResults(parentJobId, checkJobResult));
}
}

@Override
public ConsistencyCheckJobConfiguration getJobConfiguration(final String jobId) {
return getJobConfiguration(getElasticJobConfigPOJO(jobId));
Expand Down

0 comments on commit 9f05d33

Please sign in to comment.