From 8b7c57c7731c915f9745a41a14cf11992b185575 Mon Sep 17 00:00:00 2001 From: Shans Kaluhin <88006020+Shans-Kaluhin@users.noreply.github.com> Date: Mon, 6 Mar 2023 11:53:12 +0200 Subject: [PATCH] MODELINKS-65 Set not specified source file name (#51) * Set not specified source file name (cherry picked from commit 85c2cccc3138520730fce86d2d2bcff956ed932a) --- .../InstanceAuthorityStatServiceDelegate.java | 35 ++++++++++--------- .../InstanceAuthorityLinkStatisticsIT.java | 3 +- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/folio/entlinks/controller/delegate/InstanceAuthorityStatServiceDelegate.java b/src/main/java/org/folio/entlinks/controller/delegate/InstanceAuthorityStatServiceDelegate.java index 40a7c2af..0fc1dff1 100644 --- a/src/main/java/org/folio/entlinks/controller/delegate/InstanceAuthorityStatServiceDelegate.java +++ b/src/main/java/org/folio/entlinks/controller/delegate/InstanceAuthorityStatServiceDelegate.java @@ -1,16 +1,16 @@ package org.folio.entlinks.controller.delegate; +import static org.apache.commons.lang3.StringUtils.isNotBlank; + import java.time.OffsetDateTime; import java.util.Collections; import java.util.List; -import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.UUID; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import lombok.extern.log4j.Log4j2; -import org.folio.entlinks.client.AuthoritySourceFileClient; import org.folio.entlinks.controller.converter.AuthorityDataStatMapper; import org.folio.entlinks.domain.dto.AuthorityChangeStatDtoCollection; import org.folio.entlinks.domain.dto.AuthorityDataStatActionDto; @@ -28,9 +28,9 @@ @RequiredArgsConstructor public class InstanceAuthorityStatServiceDelegate { + private static final String NOT_SPECIFIED_SOURCE_FILE = "Not specified"; private final AuthorityDataStatService dataStatService; private final AuthoritySourceFilesService sourceFilesService; - private final AuthorityDataStatMapper dataStatMapper; private final UsersClient usersClient; @@ -44,9 +44,6 @@ public AuthorityChangeStatDtoCollection fetchAuthorityLinksStats(OffsetDateTime last.ifPresent(dataStatList::remove); } - Map sourceFilesMap = - sourceFilesService.fetchAuthoritySources(); - String query = getUsersQueryString(dataStatList); ResultList userResultList = query.isEmpty() ? ResultList.of(0, Collections.emptyList()) : usersClient.query(query); @@ -55,17 +52,13 @@ public AuthorityChangeStatDtoCollection fetchAuthorityLinksStats(OffsetDateTime Metadata metadata = getMetadata(userResultList, source); var authorityDataStatDto = dataStatMapper.convertToDto(source); - if (authorityDataStatDto != null && authorityDataStatDto.getSourceFileNew() != null) { - var sourceFile = sourceFilesMap.get(UUID.fromString(authorityDataStatDto.getSourceFileNew())); - if (sourceFile != null) { - authorityDataStatDto.setSourceFileNew(sourceFile.name()); - } else { - // keep original value authSourceFileId - log.warn("AuthoritySourceFile not found by [sourceFileId={}]", authorityDataStatDto.getSourceFileNew()); - } + if (authorityDataStatDto != null) { + var sourceFileIdOld = authorityDataStatDto.getSourceFileOld(); + var sourceFileIdNew = authorityDataStatDto.getSourceFileNew(); + authorityDataStatDto.setSourceFileOld(getSourceFileName(sourceFileIdOld)); + authorityDataStatDto.setSourceFileNew(getSourceFileName(sourceFileIdNew)); + authorityDataStatDto.setMetadata(metadata); } - - authorityDataStatDto.setMetadata(metadata); return authorityDataStatDto; }) .toList(); @@ -108,4 +101,14 @@ private String getUsersQueryString(List dataStatList) { .collect(Collectors.joining(" or ")); return userIds.isEmpty() ? "" : "id=(" + userIds + ")"; } + + private String getSourceFileName(String uuid) { + if (isNotBlank(uuid)) { + var sourceFile = sourceFilesService.fetchAuthoritySources().get(UUID.fromString(uuid)); + if (sourceFile != null) { + return sourceFile.name(); + } + } + return NOT_SPECIFIED_SOURCE_FILE; + } } diff --git a/src/test/java/org/folio/entlinks/controller/InstanceAuthorityLinkStatisticsIT.java b/src/test/java/org/folio/entlinks/controller/InstanceAuthorityLinkStatisticsIT.java index e85f9b51..c5d1c68a 100644 --- a/src/test/java/org/folio/entlinks/controller/InstanceAuthorityLinkStatisticsIT.java +++ b/src/test/java/org/folio/entlinks/controller/InstanceAuthorityLinkStatisticsIT.java @@ -79,7 +79,8 @@ void getAuthDataStat_positive() { .andExpect(jsonPath("$.stats[0].lbTotal", is(1))) .andExpect(jsonPath("$.stats[0].naturalIdOld", is("naturalId"))) .andExpect(jsonPath("$.stats[0].naturalIdNew", is("naturalId"))) - .andExpect(jsonPath("$.stats[0].sourceFileNew", is(SOURCE_FILE_ID.toString()))) + .andExpect(jsonPath("$.stats[0].sourceFileOld", is("Not specified"))) + .andExpect(jsonPath("$.stats[0].sourceFileNew", is("Not specified"))) .andExpect(jsonPath("$.stats[0].headingOld", is("personal name"))) .andExpect(jsonPath("$.stats[0].headingNew", is("new personal name"))) .andExpect(jsonPath("$.stats[0].headingTypeOld", is("100")))