Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MODELINKS-115: Persist failure info of authority-instance link update in authority data stat #343

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* Return only ids in response when idOnly=true ([MODELINKS-237](https://issues.folio.org/browse/MODELINKS-227))
* Fix totalRecords count when idOnly=true ([MODELINKS-239](https://issues.folio.org/browse/MODELINKS-239))
* Add parsing errors handling on bulk api ([MODELINKS-249](https://issues.folio.org/browse/MODELINKS-249))
* Persist failure info of authority-instance link update in authority data stat ([MODELINKS-115](https://issues.folio.org/browse/MODELINKS-115))

### Tech Dept
* Fix issue that causes repeated update of same entity with latest Hibernate versions ([MODELINKS-237](https://issues.folio.org/browse/MODELINKS-227))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private void updateStatsData(AuthorityDataStat dataStat, List<LinkUpdateReport>
var jobCompleted = dataStat.getLbUpdated() + dataStat.getLbFailed() == dataStat.getLbTotal();
if (jobCompleted) {
dataStat.setCompletedAt(currentTs());
updateStatStatus(dataStat);
updateStatStatus(dataStat, reports);
}

log.info("Saving stats data [statsId: {}, status: {}]", dataStat.getId(), dataStat.getStatus());
Expand All @@ -129,14 +129,22 @@ private int getReportCountForStatus(List<LinkUpdateReport> reports, LinkUpdateRe
.count();
}

private void updateStatStatus(AuthorityDataStat dataStat) {
private void updateStatStatus(AuthorityDataStat dataStat, List<LinkUpdateReport> reports) {
if (dataStat.getLbFailed() == 0) {
dataStat.setStatus(AuthorityDataStatStatus.COMPLETED_SUCCESS);
} else if (dataStat.getLbFailed() == dataStat.getLbTotal()) {
return;
}

if (dataStat.getLbFailed() == dataStat.getLbTotal()) {
dataStat.setStatus(AuthorityDataStatStatus.FAILED);
} else {
dataStat.setStatus(AuthorityDataStatStatus.COMPLETED_WITH_ERRORS);
}
reports.stream()
.map(LinkUpdateReport::getFailCause)
.filter(StringUtils::isNotBlank)
.findFirst()
.ifPresent(dataStat::setFailCause);
}

private InstanceAuthorityLinkStatus mapReportStatus(LinkUpdateReport report) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void updateForReports_positive_updateStatsData_inProgress() {
var dataStat = dataStatCaptor.getValue();

assertDataStat(dataStat,
successReports.size(), failReports.size(), AuthorityDataStatStatus.IN_PROGRESS);
successReports.size(), failReports.size(), AuthorityDataStatStatus.IN_PROGRESS, null);
}

@Test
Expand All @@ -134,7 +134,7 @@ void updateForReports_positive_updateStatsData_completeSuccess() {
verify(statRepository).save(dataStatCaptor.capture());
var dataStat = dataStatCaptor.getValue();

assertDataStat(dataStat, reports.size(), 0, AuthorityDataStatStatus.COMPLETED_SUCCESS);
assertDataStat(dataStat, reports.size(), 0, AuthorityDataStatStatus.COMPLETED_SUCCESS, null);
}

@Test
Expand All @@ -153,7 +153,7 @@ void updateForReports_positive_updateStatsData_completeWithErrors() {
var dataStat = dataStatCaptor.getValue();

assertDataStat(dataStat,
successReports.size(), failReports.size(), AuthorityDataStatStatus.COMPLETED_WITH_ERRORS);
successReports.size(), failReports.size(), AuthorityDataStatStatus.COMPLETED_WITH_ERRORS, REPORT_ERROR);
}

@Test
Expand All @@ -168,7 +168,7 @@ void updateForReports_positive_updateStatsData_completeFail() {
verify(statRepository).save(dataStatCaptor.capture());
var dataStat = dataStatCaptor.getValue();

assertDataStat(dataStat, 0, reports.size(), AuthorityDataStatStatus.FAILED);
assertDataStat(dataStat, 0, reports.size(), AuthorityDataStatStatus.FAILED, REPORT_ERROR);
}

private Consumer<InstanceAuthorityLink> linkAsserter(InstanceAuthorityLinkStatus status, String errorCause) {
Expand All @@ -178,15 +178,15 @@ private Consumer<InstanceAuthorityLink> linkAsserter(InstanceAuthorityLinkStatus
};
}

private void assertDataStat(AuthorityDataStat dataStat, int updated, int failed, AuthorityDataStatStatus status) {
private void assertDataStat(AuthorityDataStat dataStat, int updated, int failed, AuthorityDataStatStatus status,
String failCause) {
var softAssertions = new SoftAssertions();

softAssertions.assertThat(dataStat.getLbUpdated())
.isEqualTo(updated);
softAssertions.assertThat(dataStat.getLbFailed())
.isEqualTo(failed);
softAssertions.assertThat(dataStat.getFailCause())
.isBlank();
softAssertions.assertThat(dataStat.getFailCause()).isEqualTo(failCause);
softAssertions.assertThat(dataStat.getStatus())
.isEqualTo(status);
if (status.equals(AuthorityDataStatStatus.IN_PROGRESS)) {
Expand Down