From a3ca7821f1b8e3ff43790fb146852b4fbca9c5fc Mon Sep 17 00:00:00 2001 From: viacheslav_kolesnyk Date: Thu, 28 Nov 2024 17:04:01 +0100 Subject: [PATCH] Merge call-number, classification listeners --- .../message/KafkaMessageListener.java | 49 +++++++------------ .../folio/search/utils/KafkaConstants.java | 3 +- .../utils/ShelvingOrderCalculationHelper.java | 2 +- src/main/resources/application.yml | 12 ++--- .../populate-call-number-browse-config.xml | 2 +- .../entity/shelvingOrderAlgorithmType.yaml | 1 - .../integration/KafkaMessageListenerTest.java | 40 +++++---------- .../ShelvingOrderCalculationHelperTest.java | 9 ++-- src/test/resources/application.yml | 10 ++-- 9 files changed, 45 insertions(+), 83 deletions(-) diff --git a/src/main/java/org/folio/search/integration/message/KafkaMessageListener.java b/src/main/java/org/folio/search/integration/message/KafkaMessageListener.java index f0c278be6..6190025b9 100644 --- a/src/main/java/org/folio/search/integration/message/KafkaMessageListener.java +++ b/src/main/java/org/folio/search/integration/message/KafkaMessageListener.java @@ -118,46 +118,35 @@ public void handleAuthorityEvents(List> co } @KafkaListener( - id = KafkaConstants.CLASSIFICATION_TYPE_LISTENER_ID, + id = KafkaConstants.BROWSE_CONFIG_DATA_LISTENER_ID, containerFactory = "resourceListenerContainerFactory", - groupId = "#{folioKafkaProperties.listener['classification-type'].groupId}", - concurrency = "#{folioKafkaProperties.listener['classification-type'].concurrency}", - topicPattern = "#{folioKafkaProperties.listener['classification-type'].topicPattern}") + groupId = "#{folioKafkaProperties.listener['browse-config-data'].groupId}", + concurrency = "#{folioKafkaProperties.listener['browse-config-data'].concurrency}", + topicPattern = "#{folioKafkaProperties.listener['browse-config-data'].topicPattern}") @CacheEvict(cacheNames = REFERENCE_DATA_CACHE, allEntries = true) - public void handleClassificationTypeEvents(List> consumerRecords) { + public void handleBrowseConfigDataEvents(List> consumerRecords) { log.info("Processing classification-type events from Kafka [number of events: {}]", consumerRecords.size()); var batch = consumerRecords.stream() .map(ConsumerRecord::value) - .filter(resourceEvent -> resourceEvent.getType() == DELETE).toList(); - - var batchByTenant = batch.stream().collect(Collectors.groupingBy(ResourceEvent::getTenant)); - - batchByTenant.forEach((tenant, resourceEvents) -> executionService.executeSystemUserScoped(tenant, () -> { - folioMessageBatchProcessor.consumeBatchWithFallback(batch, KAFKA_RETRY_TEMPLATE_NAME, - resourceEvent -> configSynchronizationService.sync(resourceEvent, ResourceType.CLASSIFICATION_TYPE), - KafkaMessageListener::logFailedEvent); - return null; - })); - } - - @KafkaListener( - id = KafkaConstants.CALL_NUMBER_TYPE_LISTENER_ID, - containerFactory = "resourceListenerContainerFactory", - groupId = "#{folioKafkaProperties.listener['call-number-type'].groupId}", - concurrency = "#{folioKafkaProperties.listener['call-number-type'].concurrency}", - topicPattern = "#{folioKafkaProperties.listener['call-number-type'].topicPattern}") - @CacheEvict(cacheNames = REFERENCE_DATA_CACHE, allEntries = true) - public void handleCallNumberTypeEvents(List> consumerRecords) { - log.info("Processing call-number-type events from Kafka [number of events: {}]", consumerRecords.size()); - var batch = consumerRecords.stream() - .map(ConsumerRecord::value) - .filter(resourceEvent -> resourceEvent.getType() == DELETE).toList(); + .filter(resourceEvent -> resourceEvent.getType() == DELETE) + .toList(); var batchByTenant = batch.stream().collect(Collectors.groupingBy(ResourceEvent::getTenant)); batchByTenant.forEach((tenant, resourceEvents) -> executionService.executeSystemUserScoped(tenant, () -> { folioMessageBatchProcessor.consumeBatchWithFallback(batch, KAFKA_RETRY_TEMPLATE_NAME, - resourceEvent -> configSynchronizationService.sync(resourceEvent, ResourceType.CALL_NUMBER_TYPE), + resourceEvent -> { + var eventsByResource = resourceEvent.stream().collect(Collectors.groupingBy(ResourceEvent::getResourceName)); + eventsByResource.forEach((resourceName, events) -> { + if (ResourceType.CLASSIFICATION_TYPE.getName().equals(resourceName)) { + configSynchronizationService.sync(resourceEvent, ResourceType.CLASSIFICATION_TYPE); + } else if (ResourceType.CALL_NUMBER_TYPE.getName().equals(resourceName)) { + configSynchronizationService.sync(resourceEvent, ResourceType.CALL_NUMBER_TYPE); + } else { + log.warn("handleBrowseConfigDataEvents:: unsupported resource type: [{}]", resourceName); + } + }); + }, KafkaMessageListener::logFailedEvent); return null; })); diff --git a/src/main/java/org/folio/search/utils/KafkaConstants.java b/src/main/java/org/folio/search/utils/KafkaConstants.java index 1eb1abc82..224b22cb3 100644 --- a/src/main/java/org/folio/search/utils/KafkaConstants.java +++ b/src/main/java/org/folio/search/utils/KafkaConstants.java @@ -7,8 +7,7 @@ public class KafkaConstants { public static final String AUTHORITY_LISTENER_ID = "mod-search-authorities-listener"; public static final String EVENT_LISTENER_ID = "mod-search-events-listener"; - public static final String CLASSIFICATION_TYPE_LISTENER_ID = "mod-search-classification-type-listener"; - public static final String CALL_NUMBER_TYPE_LISTENER_ID = "mod-search-call-number-type-listener"; + public static final String BROWSE_CONFIG_DATA_LISTENER_ID = "mod-search-browse-config-data-listener"; public static final String LOCATION_LISTENER_ID = "mod-search-location-listener"; public static final String LINKED_DATA_LISTENER_ID = "mod-search-linked-data-listener"; public static final String REINDEX_RANGE_INDEX_LISTENER_ID = "mod-search-reindex-index-listener"; diff --git a/src/main/java/org/folio/search/utils/ShelvingOrderCalculationHelper.java b/src/main/java/org/folio/search/utils/ShelvingOrderCalculationHelper.java index b84628ce2..1117d4f0e 100644 --- a/src/main/java/org/folio/search/utils/ShelvingOrderCalculationHelper.java +++ b/src/main/java/org/folio/search/utils/ShelvingOrderCalculationHelper.java @@ -18,7 +18,7 @@ public static String calculate(@NonNull String input, @NonNull ShelvingOrderAlgo case DEWEY -> new DeweyCallNumber(input).getShelfKey().trim(); case NLM -> new NlmCallNumber(input).getShelfKey().trim(); case SUDOC -> new SuDocCallNumber(input).getShelfKey().trim(); - case OTHER, DEFAULT -> normalize(input); + case DEFAULT -> normalize(input); }; } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 02768e7a6..0f7d2962a 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -126,14 +126,10 @@ folio: concurrency: ${KAFKA_AUTHORITIES_CONCURRENCY:1} topic-pattern: ${KAFKA_AUTHORITIES_CONSUMER_PATTERN:(${folio.environment}\.)(.*\.)authorities\.authority} group-id: ${folio.environment}-mod-search-authorities-group - classification-type: - concurrency: ${KAFKA_CLASSIFICATION_TYPE_CONCURRENCY:1} - topic-pattern: (${folio.environment}\.)(.*\.)inventory\.classification-type - group-id: ${folio.environment}-mod-search-classification-type-group - call-number-type: - concurrency: ${KAFKA_CALL_NUMBER_TYPE_CONCURRENCY:1} - topic-pattern: (${folio.environment}\.)(.*\.)inventory\.call-number-type - group-id: ${folio.environment}-mod-search-call-number-type-group + browse-config-data: + concurrency: ${KAFKA_BROWSE_CONFIG_DATA_CONCURRENCY:1} + topic-pattern: (${folio.environment}\.)(.*\.)inventory\.(classification-type|call-number-type) + group-id: ${folio.environment}-mod-search-browse-config-data-group location: concurrency: ${KAFKA_LOCATION_CONCURRENCY:1} topic-pattern: (${folio.environment}\.)(.*\.)inventory\.(location|campus|institution|library) diff --git a/src/main/resources/changelog/changes/v4.1/populate-call-number-browse-config.xml b/src/main/resources/changelog/changes/v4.1/populate-call-number-browse-config.xml index 7e57fc4da..c621c8b43 100644 --- a/src/main/resources/changelog/changes/v4.1/populate-call-number-browse-config.xml +++ b/src/main/resources/changelog/changes/v4.1/populate-call-number-browse-config.xml @@ -40,7 +40,7 @@ - + diff --git a/src/main/resources/swagger.api/schemas/entity/shelvingOrderAlgorithmType.yaml b/src/main/resources/swagger.api/schemas/entity/shelvingOrderAlgorithmType.yaml index b14433e4e..951db6e95 100644 --- a/src/main/resources/swagger.api/schemas/entity/shelvingOrderAlgorithmType.yaml +++ b/src/main/resources/swagger.api/schemas/entity/shelvingOrderAlgorithmType.yaml @@ -5,5 +5,4 @@ enum: - dewey - nlm - sudoc - - other - default diff --git a/src/test/java/org/folio/search/integration/KafkaMessageListenerTest.java b/src/test/java/org/folio/search/integration/KafkaMessageListenerTest.java index 712551230..3d8a41092 100644 --- a/src/test/java/org/folio/search/integration/KafkaMessageListenerTest.java +++ b/src/test/java/org/folio/search/integration/KafkaMessageListenerTest.java @@ -65,6 +65,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; import org.junit.jupiter.params.provider.ValueSource; import org.mockito.InjectMocks; import org.mockito.Mock; @@ -317,35 +318,20 @@ void handleLinkedDataHubEvent_negative_logFailedEvent() { verify(batchProcessor).consumeBatchWithFallback(eq(expectedEvents), eq(KAFKA_RETRY_TEMPLATE_NAME), any(), any()); } - @Test - void handleClassificationTypeEvent_positive_filterOnlyDeleteEvents() { - var deleteEvent = resourceEvent(RESOURCE_ID, ResourceType.CLASSIFICATION_TYPE, DELETE, null, emptyMap()); - var createEvent = resourceEvent(RESOURCE_ID, ResourceType.CLASSIFICATION_TYPE, CREATE, emptyMap(), null); - var updateEvent = resourceEvent(RESOURCE_ID, ResourceType.CLASSIFICATION_TYPE, UPDATE, null, null); - - messageListener.handleClassificationTypeEvents(List.of( - consumerRecordForType(ResourceType.CLASSIFICATION_TYPE, deleteEvent), - consumerRecordForType(ResourceType.CLASSIFICATION_TYPE, updateEvent), - consumerRecordForType(ResourceType.CLASSIFICATION_TYPE, createEvent)) - ); - - verify(configSynchronizationService).sync(List.of(deleteEvent), ResourceType.CLASSIFICATION_TYPE); - verify(batchProcessor).consumeBatchWithFallback(eq(List.of(deleteEvent)), any(), any(), any()); - } - - @Test - void handleCallNumberTypeEvent_positive_filterOnlyDeleteEvents() { - var deleteEvent = resourceEvent(RESOURCE_ID, ResourceType.CALL_NUMBER_TYPE, DELETE, null, emptyMap()); - var createEvent = resourceEvent(RESOURCE_ID, ResourceType.CALL_NUMBER_TYPE, CREATE, emptyMap(), null); - var updateEvent = resourceEvent(RESOURCE_ID, ResourceType.CALL_NUMBER_TYPE, UPDATE, null, null); - - messageListener.handleCallNumberTypeEvents(List.of( - consumerRecordForType(ResourceType.CALL_NUMBER_TYPE, deleteEvent), - consumerRecordForType(ResourceType.CALL_NUMBER_TYPE, updateEvent), - consumerRecordForType(ResourceType.CALL_NUMBER_TYPE, createEvent)) + @ParameterizedTest + @EnumSource(value = ResourceType.class, names = {"CLASSIFICATION_TYPE", "CALL_NUMBER_TYPE"}) + void handleBrowseConfigDataEvent_positive_filterOnlyDeleteEvents(ResourceType type) { + var deleteEvent = resourceEvent(RESOURCE_ID, type, DELETE, null, emptyMap()); + var createEvent = resourceEvent(RESOURCE_ID, type, CREATE, emptyMap(), null); + var updateEvent = resourceEvent(RESOURCE_ID, type, UPDATE, null, null); + + messageListener.handleBrowseConfigDataEvents(List.of( + consumerRecordForType(type, deleteEvent), + consumerRecordForType(type, updateEvent), + consumerRecordForType(type, createEvent)) ); - verify(configSynchronizationService).sync(List.of(deleteEvent), ResourceType.CALL_NUMBER_TYPE); + verify(configSynchronizationService).sync(List.of(deleteEvent), type); verify(batchProcessor).consumeBatchWithFallback(eq(List.of(deleteEvent)), any(), any(), any()); } diff --git a/src/test/java/org/folio/search/utils/ShelvingOrderCalculationHelperTest.java b/src/test/java/org/folio/search/utils/ShelvingOrderCalculationHelperTest.java index 32afa0fe3..049d25ee3 100644 --- a/src/test/java/org/folio/search/utils/ShelvingOrderCalculationHelperTest.java +++ b/src/test/java/org/folio/search/utils/ShelvingOrderCalculationHelperTest.java @@ -7,8 +7,6 @@ import org.folio.search.domain.dto.ShelvingOrderAlgorithmType; import org.folio.spring.testing.type.UnitTest; import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.EnumSource; @UnitTest class ShelvingOrderCalculationHelperTest { @@ -53,13 +51,12 @@ void shouldCalculateSudocNumber() { assertEquals(expectedShelfKey, result); } - @ParameterizedTest - @EnumSource(value = ShelvingOrderAlgorithmType.class, mode = EnumSource.Mode.INCLUDE, names = {"DEFAULT", "OTHER"}) - void shouldCalculateNormalizedNumber(ShelvingOrderAlgorithmType type) { + @Test + void shouldCalculateDefaultNumber() { var input = "hd1691 ^I5 1967"; var expectedShelfKey = "HD1691 ^I5 1967"; - var result = calculate(input, type); + var result = calculate(input, ShelvingOrderAlgorithmType.DEFAULT); assertEquals(expectedShelfKey, result); } diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index 39a3fe790..f793294aa 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -145,14 +145,10 @@ folio: concurrency: 1 topic-pattern: (${folio.environment}\.)(.*\.)authorities\.authority group-id: ${folio.environment}-mod-search-authorities-group - classification-type: + browse-config-data: concurrency: 1 - topic-pattern: (${folio.environment}\.)(.*\.)inventory\.classification-type - group-id: ${folio.environment}-mod-search-classification-type-group - call-number-type: - concurrency: 1 - topic-pattern: (${folio.environment}\.)(.*\.)inventory\.call-number-type - group-id: ${folio.environment}-mod-search-call-number-type-group + topic-pattern: (${folio.environment}\.)(.*\.)inventory\.(classification-type|call-number-type) + group-id: ${folio.environment}-mod-search-browse-config-data-group location: concurrency: 1 topic-pattern: (${folio.environment}\.)(.*\.)inventory\.(location|campus|institution|library)