Skip to content

Commit

Permalink
MODELINKS-65 Set not specified source file name (#51)
Browse files Browse the repository at this point in the history
* Set not specified source file name

(cherry picked from commit 85c2ccc)
  • Loading branch information
Shans-Kaluhin authored and psmagin committed Mar 7, 2023
1 parent ecca024 commit 8b7c57c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand All @@ -44,9 +44,6 @@ public AuthorityChangeStatDtoCollection fetchAuthorityLinksStats(OffsetDateTime
last.ifPresent(dataStatList::remove);
}

Map<UUID, AuthoritySourceFileClient.AuthoritySourceFile> sourceFilesMap =
sourceFilesService.fetchAuthoritySources();

String query = getUsersQueryString(dataStatList);
ResultList<UsersClient.User> userResultList =
query.isEmpty() ? ResultList.of(0, Collections.emptyList()) : usersClient.query(query);
Expand All @@ -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();
Expand Down Expand Up @@ -108,4 +101,14 @@ private String getUsersQueryString(List<AuthorityDataStat> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
Expand Down

0 comments on commit 8b7c57c

Please sign in to comment.