diff --git a/redaction-service-v1/redaction-service-server-v1/build.gradle.kts b/redaction-service-v1/redaction-service-server-v1/build.gradle.kts index fb0ae389..dd1ec3e4 100644 --- a/redaction-service-v1/redaction-service-server-v1/build.gradle.kts +++ b/redaction-service-v1/redaction-service-server-v1/build.gradle.kts @@ -52,7 +52,7 @@ dependencies { implementation("com.iqser.red.commons:dictionary-merge-commons:1.5.0") implementation("com.iqser.red.commons:storage-commons:2.50.0") - implementation("com.knecon.fforesight:tenant-commons:0.30.0") + implementation("com.knecon.fforesight:tenant-commons:0.31.0") implementation("com.knecon.fforesight:keycloak-commons:0.30.0") { exclude(group = "com.knecon.fforesight", module = "tenant-commons") } diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/configuraton/PriorityTenantMessagingConfigurationImpl.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/configuraton/PriorityTenantMessagingConfigurationImpl.java deleted file mode 100644 index 2ec3a694..00000000 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/configuraton/PriorityTenantMessagingConfigurationImpl.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.iqser.red.service.redaction.v1.server.configuraton; - -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.context.annotation.Configuration; - -import com.knecon.fforesight.tenantcommons.queue.TenantMessagingConfiguration; - -@Configuration -@ConditionalOnProperty(prefix = "redaction-service", name = "priorityMode", havingValue = "true") -public class PriorityTenantMessagingConfigurationImpl extends TenantMessagingConfiguration { - -} diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/configuraton/TenantMessagingConfigurationImpl.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/configuraton/TenantMessagingConfigurationImpl.java deleted file mode 100644 index 9d54f3be..00000000 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/configuraton/TenantMessagingConfigurationImpl.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.iqser.red.service.redaction.v1.server.configuraton; - -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.context.annotation.Configuration; - -import com.knecon.fforesight.tenantcommons.queue.TenantMessagingConfiguration; - -@Configuration -@ConditionalOnProperty(prefix = "redaction-service", name = "priorityMode", havingValue = "false") -public class TenantMessagingConfigurationImpl extends TenantMessagingConfiguration { - -} diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/queue/PriorityTenantExchangeMessageReceiverImpl.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/queue/PriorityTenantExchangeMessageReceiverImpl.java deleted file mode 100644 index 9e14ec4c..00000000 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/queue/PriorityTenantExchangeMessageReceiverImpl.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.iqser.red.service.redaction.v1.server.queue; - -import static com.iqser.red.service.redaction.v1.model.QueueNames.*; -import java.util.Map; -import java.util.Set; - -import org.springframework.amqp.rabbit.annotation.RabbitHandler; -import org.springframework.amqp.rabbit.annotation.RabbitListener; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.event.ApplicationReadyEvent; -import org.springframework.context.event.EventListener; -import org.springframework.stereotype.Service; - -import com.knecon.fforesight.tenantcommons.TenantProvider; -import com.knecon.fforesight.tenantcommons.model.TenantCreatedEvent; -import com.knecon.fforesight.tenantcommons.model.TenantQueueConfiguration; -import com.knecon.fforesight.tenantcommons.model.TenantResponse; -import com.knecon.fforesight.tenantcommons.queue.RabbitQueueFromExchangeService; -import com.knecon.fforesight.tenantcommons.queue.TenantExchangeMessageReceiver; - -@Service -@ConditionalOnProperty(prefix = "redaction-service", name = "priorityMode", havingValue = "true") -public class PriorityTenantExchangeMessageReceiverImpl extends TenantExchangeMessageReceiver { - - public PriorityTenantExchangeMessageReceiverImpl(RabbitQueueFromExchangeService rabbitQueueService, TenantProvider tenantProvider) { - - super(rabbitQueueService, tenantProvider); - } - - - @Override - protected Set getTenantQueueConfigs() { - - return Set.of(TenantQueueConfiguration.builder() - .listenerId(PriorityMessageReceiver.REDACTION_PRIORITY_REQUEST_LISTENER_ID) - .exchangeName(REDACTION_PRIORITY_REQUEST_EXCHANGE) - .queuePrefix(REDACTION_PRIORITY_REQUEST_QUEUE_PREFIX) - .dlqName(REDACTION_DLQ) - .arguments(Map.of("x-max-priority", 2)) - .build()); - } - - - @EventListener(ApplicationReadyEvent.class) - public void onApplicationReady() { - - System.out.println("application ready invoked"); - super.initializeQueues(); - } - - - @RabbitHandler - @RabbitListener(queues = "#{priorityTenantMessagingConfigurationImpl.getTenantCreatedQueueName()}") - public void reactToTenantCreation(TenantCreatedEvent tenantCreatedEvent) { - - super.reactToTenantCreation(tenantCreatedEvent); - } - - - @RabbitHandler - @RabbitListener(queues = "#{priorityTenantMessagingConfigurationImpl.getTenantDeletedQueueName()}") - public void reactToTenantDeletion(TenantResponse tenantResponse) { - - super.reactToTenantDeletion(tenantResponse); - - } - -} diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/queue/TenantExchangeMessageReceiverImpl.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/queue/TenantExchangeMessageReceiverImpl.java deleted file mode 100644 index 4bae9d80..00000000 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/queue/TenantExchangeMessageReceiverImpl.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.iqser.red.service.redaction.v1.server.queue; - -import static com.iqser.red.service.redaction.v1.model.QueueNames.*; -import java.util.Map; -import java.util.Set; - -import org.springframework.amqp.rabbit.annotation.RabbitHandler; -import org.springframework.amqp.rabbit.annotation.RabbitListener; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.event.ApplicationReadyEvent; -import org.springframework.context.event.EventListener; -import org.springframework.stereotype.Service; - -import com.knecon.fforesight.tenantcommons.TenantProvider; -import com.knecon.fforesight.tenantcommons.model.TenantCreatedEvent; -import com.knecon.fforesight.tenantcommons.model.TenantQueueConfiguration; -import com.knecon.fforesight.tenantcommons.model.TenantResponse; -import com.knecon.fforesight.tenantcommons.queue.RabbitQueueFromExchangeService; -import com.knecon.fforesight.tenantcommons.queue.TenantExchangeMessageReceiver; - -@Service -@ConditionalOnProperty(prefix = "redaction-service", name = "priorityMode", havingValue = "false") -public class TenantExchangeMessageReceiverImpl extends TenantExchangeMessageReceiver { - - public TenantExchangeMessageReceiverImpl(RabbitQueueFromExchangeService rabbitQueueService, TenantProvider tenantProvider) { - - super(rabbitQueueService, tenantProvider); - } - - - @Override - protected Set getTenantQueueConfigs() { - - return Set.of(TenantQueueConfiguration.builder() - .listenerId(MessageReceiver.REDACTION_REQUEST_LISTENER_ID) - .exchangeName(REDACTION_REQUEST_EXCHANGE) - .queuePrefix(REDACTION_REQUEST_QUEUE_PREFIX) - .dlqName(REDACTION_DLQ) - .arguments(Map.of("x-max-priority", 2)) - .build()); - } - - - @EventListener(ApplicationReadyEvent.class) - public void onApplicationReady() { - - System.out.println("application ready invoked"); - super.initializeQueues(); - } - - - @RabbitHandler - @RabbitListener(queues = "#{tenantMessagingConfigurationImpl.getTenantCreatedQueueName()}") - public void reactToTenantCreation(TenantCreatedEvent tenantCreatedEvent) { - - super.reactToTenantCreation(tenantCreatedEvent); - } - - - @RabbitHandler - @RabbitListener(queues = "#{tenantMessagingConfigurationImpl.getTenantDeletedQueueName()}") - public void reactToTenantDeletion(TenantResponse tenantResponse) { - - super.reactToTenantDeletion(tenantResponse); - - } - -} diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/queue/TenantQueueProviderConfig.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/queue/TenantQueueProviderConfig.java new file mode 100644 index 00000000..6e18d320 --- /dev/null +++ b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/queue/TenantQueueProviderConfig.java @@ -0,0 +1,49 @@ +package com.iqser.red.service.redaction.v1.server.queue; + +import static com.iqser.red.service.redaction.v1.model.QueueNames.REDACTION_DLQ; +import static com.iqser.red.service.redaction.v1.model.QueueNames.REDACTION_PRIORITY_REQUEST_EXCHANGE; +import static com.iqser.red.service.redaction.v1.model.QueueNames.REDACTION_PRIORITY_REQUEST_QUEUE_PREFIX; +import static com.iqser.red.service.redaction.v1.model.QueueNames.REDACTION_REQUEST_EXCHANGE; +import static com.iqser.red.service.redaction.v1.model.QueueNames.REDACTION_REQUEST_QUEUE_PREFIX; + +import java.util.Map; +import java.util.Set; + +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import com.knecon.fforesight.tenantcommons.model.TenantQueueConfiguration; +import com.knecon.fforesight.tenantcommons.model.TenantQueueProvider; + +@Configuration +public class TenantQueueProviderConfig { + + @Bean + @ConditionalOnProperty(prefix = "redaction-service", name = "priorityMode", havingValue = "true") + protected TenantQueueProvider getTenantPriorityQueueConfigs() { + + return new TenantQueueProvider(Set.of(TenantQueueConfiguration.builder() + .listenerId(PriorityMessageReceiver.REDACTION_PRIORITY_REQUEST_LISTENER_ID) + .exchangeName(REDACTION_PRIORITY_REQUEST_EXCHANGE) + .queuePrefix(REDACTION_PRIORITY_REQUEST_QUEUE_PREFIX) + .dlqName(REDACTION_DLQ) + .arguments(Map.of("x-max-priority", 2)) + .build())); + } + + + @Bean + @ConditionalOnProperty(prefix = "redaction-service", name = "priorityMode", havingValue = "false", matchIfMissing = true) + protected Set getTenantQueueConfigs() { + + return Set.of(TenantQueueConfiguration.builder() + .listenerId(MessageReceiver.REDACTION_REQUEST_LISTENER_ID) + .exchangeName(REDACTION_REQUEST_EXCHANGE) + .queuePrefix(REDACTION_REQUEST_QUEUE_PREFIX) + .dlqName(REDACTION_DLQ) + .arguments(Map.of("x-max-priority", 2)) + .build()); + } + +} diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/service/DictionarySearchService.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/service/DictionarySearchService.java index e5a2ab17..c17b6ddd 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/service/DictionarySearchService.java +++ b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/service/DictionarySearchService.java @@ -7,7 +7,6 @@ import org.springframework.stereotype.Service; import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.Engine; import com.iqser.red.service.redaction.v1.server.model.dictionary.Dictionary; -import com.iqser.red.service.redaction.v1.server.model.dictionary.DictionaryModel; import com.iqser.red.service.redaction.v1.server.model.dictionary.SearchImplementation; import com.iqser.red.service.redaction.v1.server.model.document.entity.EntityType; import com.iqser.red.service.redaction.v1.server.model.document.nodes.SemanticNode; @@ -40,24 +39,16 @@ public class DictionarySearchService { public void addDictionaryEntities(Dictionary dictionary, SemanticNode node) { dictionary.getDictionaryModels() - .stream() - .parallel() .forEach(model -> { - synchronized (node) { - bySearchImplementationAsDictionary(model.getEntriesSearch(), - model.getType(), - model.isHint() ? EntityType.HINT : EntityType.ENTITY, - node, - model.isDossierDictionary()); - bySearchImplementationAsDictionary(model.getFalsePositiveSearch(), model.getType(), EntityType.FALSE_POSITIVE, node, model.isDossierDictionary()); - bySearchImplementationAsDictionary(model.getFalseRecommendationsSearch(), - model.getType(), - EntityType.FALSE_RECOMMENDATION, - node, - model.isDossierDictionary()); - if (model.isDossierDictionary()) { - bySearchImplementationAsDictionary(model.getDeletionEntriesSearch(), model.getType(), EntityType.DICTIONARY_REMOVAL, node, model.isDossierDictionary()); - } + bySearchImplementationAsDictionary(model.getEntriesSearch(), + model.getType(), + model.isHint() ? EntityType.HINT : EntityType.ENTITY, + node, + model.isDossierDictionary()); + bySearchImplementationAsDictionary(model.getFalsePositiveSearch(), model.getType(), EntityType.FALSE_POSITIVE, node, model.isDossierDictionary()); + bySearchImplementationAsDictionary(model.getFalseRecommendationsSearch(), model.getType(), EntityType.FALSE_RECOMMENDATION, node, model.isDossierDictionary()); + if (model.isDossierDictionary()) { + bySearchImplementationAsDictionary(model.getDeletionEntriesSearch(), model.getType(), EntityType.DICTIONARY_REMOVAL, node, model.isDossierDictionary()); } }); } diff --git a/redaction-service-v1/redaction-service-server-v1/src/test/java/com/iqser/red/service/redaction/v1/server/AbstractRedactionIntegrationTest.java b/redaction-service-v1/redaction-service-server-v1/src/test/java/com/iqser/red/service/redaction/v1/server/AbstractRedactionIntegrationTest.java index 9900f7ee..35fd53d8 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/test/java/com/iqser/red/service/redaction/v1/server/AbstractRedactionIntegrationTest.java +++ b/redaction-service-v1/redaction-service-server-v1/src/test/java/com/iqser/red/service/redaction/v1/server/AbstractRedactionIntegrationTest.java @@ -5,6 +5,7 @@ import static com.iqser.red.service.redaction.v1.server.testcontainers.MongoDBTe import static com.iqser.red.service.redaction.v1.server.testcontainers.MongoDBTestContainer.MONGO_USERNAME; import static com.knecon.fforesight.tenantcommons.model.TenantResponse.builder; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.io.File; @@ -30,12 +31,18 @@ import org.junit.jupiter.api.BeforeEach; import org.mockito.stubbing.Answer; import org.springframework.amqp.rabbit.core.RabbitAdmin; import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.amqp.rabbit.listener.MessageListenerContainer; import org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistry; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.util.TestPropertyValues; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; import org.springframework.core.io.ClassPathResource; import org.springframework.data.redis.listener.RedisMessageListenerContainer; import org.springframework.test.context.ContextConfiguration; @@ -85,6 +92,7 @@ import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; @ContextConfiguration(initializers = {AbstractRedactionIntegrationTest.Initializer.class}) +@Import(AbstractRedactionIntegrationTest.TestConfiguration.class) public abstract class AbstractRedactionIntegrationTest { protected static final String VERTEBRATE_INDICATOR = "vertebrate"; @@ -172,9 +180,6 @@ public abstract class AbstractRedactionIntegrationTest { @MockBean protected RabbitAdmin rabbitAdmin; - @MockBean - protected RabbitListenerEndpointRegistry rabbitListenerEndpointRegistry; - @MockBean protected LegalBasisClient legalBasisClient; @@ -739,4 +744,20 @@ public abstract class AbstractRedactionIntegrationTest { } } + + @Configuration + @EnableAutoConfiguration(exclude = {RabbitAutoConfiguration.class}) + public static class TestConfiguration { + + @Bean + public RabbitListenerEndpointRegistry rabbitListenerEndpointRegistry() { + + var mock = mock(RabbitListenerEndpointRegistry.class); + when(mock.getListenerContainer(any())).thenReturn(mock(MessageListenerContainer.class)); + + return mock; + } + + } + }