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

fix(consortium): ignore authority shadow copies while indexing #467

Merged
merged 3 commits into from
Nov 15, 2023
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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
### Bug fixes
* Fix secure setup of system users by default ([MSEARCH-608](https://issues.folio.org/browse/MSEARCH-608))
* Fix result filtering for items.effectiveLocationId ([MSEARCH-615](https://issues.folio.org/browse/MSEARCH-615))
* Ignore authority shadow copies while indexing ([MSEARCH-638](https://issues.folio.org/browse/MSEARCH-638))

### Tech Dept
* Description ([ISSUE_NUMBER](https://issues.folio.org/browse/ISSUE_NUMBER))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@
import static org.folio.search.domain.dto.ResourceEventType.REINDEX;
import static org.folio.search.utils.SearchConverterUtils.getEventPayload;
import static org.folio.search.utils.SearchConverterUtils.getResourceEventId;
import static org.folio.search.utils.SearchConverterUtils.getResourceSource;
import static org.folio.search.utils.SearchUtils.AUTHORITY_RESOURCE;
import static org.folio.search.utils.SearchUtils.CONTRIBUTOR_RESOURCE;
import static org.folio.search.utils.SearchUtils.ID_FIELD;
import static org.folio.search.utils.SearchUtils.INSTANCE_ID_FIELD;
import static org.folio.search.utils.SearchUtils.INSTANCE_RESOURCE;
import static org.folio.search.utils.SearchUtils.INSTANCE_SUBJECT_RESOURCE;
import static org.folio.search.utils.SearchUtils.SOURCE_CONSORTIUM_PREFIX;

import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.logging.log4j.message.FormattedMessage;
import org.folio.search.domain.dto.ResourceEvent;
Expand Down Expand Up @@ -80,6 +83,7 @@ public void handleAuthorityEvents(List<ConsumerRecord<String, ResourceEvent>> co
log.info("Processing authority events from Kafka [number of events: {}]", consumerRecords.size());
var batch = consumerRecords.stream()
.map(ConsumerRecord::value)
.filter(authority -> !StringUtils.startsWith(getResourceSource(authority), SOURCE_CONSORTIUM_PREFIX))
.map(authority -> authority.resourceName(AUTHORITY_RESOURCE).id(getResourceEventId(authority)))
.toList();

Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/folio/search/utils/SearchConverterUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,16 @@ public static String getResourceEventId(Map<String, Object> eventPayload) {
return getString(eventPayload, ID_FIELD);
}

/**
* Returns resource event source field value from {@link ResourceEvent} object.
*
* @param event - resource event body to analyze
* @return event source field value as {@link String} object
*/
public static String getResourceSource(ResourceEvent event) {
return getResourceSource(getEventPayload(event));
}

/**
* Returns resource event source field value from event payload {@link Map} object.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
import static org.folio.search.utils.TestUtils.resourceEvent;
import static org.folio.search.utils.TestUtils.toMap;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -180,6 +182,17 @@ void handleAuthorityEvent_positive() {
verify(batchProcessor).consumeBatchWithFallback(eq(expectedEvents), eq(KAFKA_RETRY_TEMPLATE_NAME), any(), any());
}

@Test
void handleAuthorityEvent_positive_shouldSkipAuthorityShadowCopies() {
var payload = toMap(new Authority().id(RESOURCE_ID).source("CONSORTIUM-MARC"));

messageListener.handleAuthorityEvents(List.of(new ConsumerRecord<>(
inventoryAuthorityTopic(), 0, 0, RESOURCE_ID, resourceEvent(null, null, REINDEX, payload, null))));

verify(resourceService, never()).indexResources(anyList());
verify(batchProcessor, never()).consumeBatchWithFallback(any(), any(), any(), any());
}

@Test
void handleAuthorityEvent_negative_logFailedEvent() {
var payload = toMap(new Authority().id(RESOURCE_ID).personalName("test"));
Expand Down