Skip to content

Commit

Permalink
Merge call-number, classification listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
viacheslavkol committed Nov 28, 2024
1 parent 129c116 commit a3ca782
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,46 +118,35 @@ public void handleAuthorityEvents(List<ConsumerRecord<String, ResourceEvent>> 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<ConsumerRecord<String, ResourceEvent>> consumerRecords) {
public void handleBrowseConfigDataEvents(List<ConsumerRecord<String, ResourceEvent>> 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<ConsumerRecord<String, ResourceEvent>> 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;
}));
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/folio/search/utils/KafkaConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}

Expand Down
12 changes: 4 additions & 8 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<insert tableName="browse_config">
<column name="browse_type" value="instance-call-number"/>
<column name="browse_option_type" value="other"/>
<column name="shelving_algorithm" value="other"/>
<column name="shelving_algorithm" value="default"/>
</insert>
</changeSet>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ enum:
- dewey
- nlm
- sudoc
- other
- default
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand Down
10 changes: 3 additions & 7 deletions src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a3ca782

Please sign in to comment.