Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.folio.dataexp.client.SourceStorageClient;
import org.folio.dataexp.domain.dto.FileDefinition;
Expand Down Expand Up @@ -74,9 +75,10 @@ public FileDefinition getFileDefinitionForMarcDeletedIds(Date from, Date to) {
new ArrayList<>(sourceStorageClient.getMarcRecordsIdentifiers(payload).getRecords());
log.info("Found deleted MARC IDs: {}", marcIds.size());

if (!consortiaService.isCurrentTenantCentralTenant(folioExecutionContext.getTenantId())) {
var centralTenantId =
consortiaService.getCentralTenantId(folioExecutionContext.getTenantId());
var currentTenantId = folioExecutionContext.getTenantId();
var centralTenantId = consortiaService.getCentralTenantId(currentTenantId);
if (StringUtils.isNotEmpty(centralTenantId)
&& !consortiaService.isCurrentTenantCentralTenant(currentTenantId)) {
try (var ignored =
new FolioExecutionContextSetter(
prepareContextForTenant(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.folio.dataexp.util.Constants.DATE_PATTERN;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -67,6 +68,7 @@ void shouldReturnOneRecord() {
.thenReturn(fileDefinition);
when(fileDefinitionsService.uploadFile(isA(UUID.class), isA(Resource.class)))
.thenReturn(fileDefinition);
when(consortiaService.getCentralTenantId(null)).thenReturn("central");
when(consortiaService.isCurrentTenantCentralTenant(null)).thenReturn(true);

var res = marcDeletedIdsService.getFileDefinitionForMarcDeletedIds(null, null);
Expand All @@ -86,6 +88,7 @@ void shouldHavePayloadWithDateRangeIfDateRangeIsUsed() {
.thenReturn(fileDefinition);
when(fileDefinitionsService.uploadFile(isA(UUID.class), isA(Resource.class)))
.thenReturn(fileDefinition);
when(consortiaService.getCentralTenantId(null)).thenReturn("central");
when(consortiaService.isCurrentTenantCentralTenant(null)).thenReturn(true);

var date = new SimpleDateFormat(DATE_PATTERN);
Expand All @@ -111,6 +114,7 @@ void shouldHavePayloadWithFromDateIfDateFromIsUsed() {
.thenReturn(fileDefinition);
when(fileDefinitionsService.uploadFile(isA(UUID.class), isA(Resource.class)))
.thenReturn(fileDefinition);
when(consortiaService.getCentralTenantId(null)).thenReturn("central");
when(consortiaService.isCurrentTenantCentralTenant(null)).thenReturn(true);

var date = new SimpleDateFormat(DATE_PATTERN);
Expand All @@ -135,6 +139,7 @@ void shouldHavePayloadWithToDateIfDateToIsUsed() {
.thenReturn(fileDefinition);
when(fileDefinitionsService.uploadFile(isA(UUID.class), isA(Resource.class)))
.thenReturn(fileDefinition);
when(consortiaService.getCentralTenantId(null)).thenReturn("central");
when(consortiaService.isCurrentTenantCentralTenant(null)).thenReturn(true);

var date = new SimpleDateFormat(DATE_PATTERN);
Expand All @@ -158,6 +163,7 @@ void shouldHavePayloadWithPreviousDayIfDateIsNotUsed() {
.thenReturn(fileDefinition);
when(fileDefinitionsService.uploadFile(isA(UUID.class), isA(Resource.class)))
.thenReturn(fileDefinition);
when(consortiaService.getCentralTenantId(null)).thenReturn("central");
when(consortiaService.isCurrentTenantCentralTenant(null)).thenReturn(true);

marcDeletedIdsService.getFileDefinitionForMarcDeletedIds(null, null);
Expand Down Expand Up @@ -205,4 +211,26 @@ void shouldExcludeSharedNonDeletedIds() {
verify(fileDefinitionsService).uploadFile(isA(UUID.class), resourceArgumentCaptor.capture());
assertThat(id1).isEqualTo(resourceArgumentCaptor.getValue().getContentAsString(UTF_8));
}

@Test
@SneakyThrows
void shouldNotCheckCentralTenantWhenNonEcs() {
var id1 = UUID.randomUUID().toString();
var id2 = UUID.randomUUID().toString();
when(sourceStorageClient.getMarcRecordsIdentifiers(isA(MarcRecordIdentifiersPayload.class)))
.thenReturn(
new MarcRecordsIdentifiersResponse().withRecords(List.of(id1, id2)).withTotalCount(2));
when(folioExecutionContext.getTenantId()).thenReturn("member");
when(consortiaService.getCentralTenantId("member")).thenReturn("");
var fileDefinition = new FileDefinition().id(UUID.randomUUID());
when(fileDefinitionsService.postFileDefinition(isA(FileDefinition.class)))
.thenReturn(fileDefinition);

marcDeletedIdsService.getFileDefinitionForMarcDeletedIds(null, null);

verify(consortiaService, never()).isCurrentTenantCentralTenant("member");
verify(fileDefinitionsService).uploadFile(isA(UUID.class), resourceArgumentCaptor.capture());
assertThat(resourceArgumentCaptor.getValue().getContentAsString(UTF_8))
.isEqualTo(String.join(System.lineSeparator(), List.of(id1, id2)));
}
}
Loading