diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/config/SchemaEventsListenerConfiguration.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/config/SchemaEventsListenerConfiguration.java new file mode 100644 index 0000000000000000000000000000000000000000..7f4bddefe2cbd10706e9ba82acb1f5815c1e45ba --- /dev/null +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/config/SchemaEventsListenerConfiguration.java @@ -0,0 +1,16 @@ +package org.opengroup.osdu.indexer.config; + +import lombok.Getter; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; + +@Configuration +@Getter +public class SchemaEventsListenerConfiguration { + + @Value("${listner.schema.event.create:true}") + private boolean listenCreateEvent; + + @Value("${listner.schema.event.update:true}") + private boolean listenUpdateEvent; +} diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/SchemaProviderImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/SchemaProviderImpl.java index 8253615489a1b946b9f7334795c3173a8dd2f304..c82d538a234ae20cbc41f166ec36e08749891da0 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/SchemaProviderImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/SchemaProviderImpl.java @@ -28,6 +28,7 @@ import org.opengroup.osdu.core.common.model.indexer.SchemaInfo; import org.opengroup.osdu.core.common.model.indexer.SchemaOperationType; import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; +import org.opengroup.osdu.indexer.config.SchemaEventsListenerConfiguration; import org.opengroup.osdu.indexer.logging.AuditLogger; import org.opengroup.osdu.indexer.schema.converter.interfaces.SchemaToStorageFormat; import org.opengroup.osdu.indexer.util.ElasticClientHandler; @@ -76,6 +77,10 @@ public class SchemaProviderImpl implements SchemaService { @Inject private AuditLogger auditLogger; + @Inject + private SchemaEventsListenerConfiguration schemaEventsListenerConfiguration; + + @Override public String getSchema(String kind) throws URISyntaxException, UnsupportedEncodingException { String schemaServiceSchema = getFromSchemaService(kind); @@ -85,16 +90,23 @@ public class SchemaProviderImpl implements SchemaService { @Override public void processSchemaMessages(List<SchemaInfo> schemaInfos) throws IOException { Map<String, SchemaOperationType> messages = new HashMap<>(); - Map<String, SchemaOperationType> createSchemaMessages = SchemaInfo.getCreateSchemaEvents(schemaInfos); - if (createSchemaMessages != null && !createSchemaMessages.isEmpty()) { - messages.putAll(createSchemaMessages); + + if (schemaEventsListenerConfiguration.isListenCreateEvent()) { + Map<String, SchemaOperationType> createSchemaMessages = SchemaInfo.getCreateSchemaEvents(schemaInfos); + if (createSchemaMessages != null && !createSchemaMessages.isEmpty()) { + messages.putAll(createSchemaMessages); + } } - Map<String, SchemaOperationType> updateSchemaMessages = SchemaInfo.getUpdateSchemaEvents(schemaInfos); - if (updateSchemaMessages != null && !updateSchemaMessages.isEmpty()) { - messages.putAll(updateSchemaMessages); + if (schemaEventsListenerConfiguration.isListenUpdateEvent()) { + Map<String, SchemaOperationType> updateSchemaMessages = SchemaInfo.getUpdateSchemaEvents(schemaInfos); + if (updateSchemaMessages != null && !updateSchemaMessages.isEmpty()) { + messages.putAll(updateSchemaMessages); + } } + if (messages.isEmpty()) return; + try (RestHighLevelClient restClient = this.elasticClientHandler.createRestClient()) { messages.entrySet().forEach(msg -> { try { diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/SchemaProviderImplTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/SchemaProviderImplTest.java index 2d1ab4aea5beebe682cbc2b98fc7fd356ccb49af..3c40aa24ca8ffc38ed84c51275d67975092364ac 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/SchemaProviderImplTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/SchemaProviderImplTest.java @@ -21,6 +21,7 @@ import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.rest.RestStatus; import org.junit.Assert; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.*; @@ -31,6 +32,7 @@ import org.opengroup.osdu.core.common.model.http.HttpResponse; import org.opengroup.osdu.core.common.model.indexer.SchemaInfo; import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; +import org.opengroup.osdu.indexer.config.SchemaEventsListenerConfiguration; import org.opengroup.osdu.indexer.logging.AuditLogger; import org.opengroup.osdu.indexer.schema.converter.SchemaToStorageFormatImpl; import org.opengroup.osdu.indexer.util.ElasticClientHandler; @@ -77,12 +79,19 @@ public class SchemaProviderImplTest { private AuditLogger auditLogger; @Mock private IndexSchemaService indexSchemaService; - + @Mock + private SchemaEventsListenerConfiguration schemaEventsListenerConfiguration; @InjectMocks private SchemaProviderImpl sut; private RestHighLevelClient restClient; + @Before + public void setup() { + when(this.schemaEventsListenerConfiguration.isListenCreateEvent()).thenReturn(true); + when(this.schemaEventsListenerConfiguration.isListenUpdateEvent()).thenReturn(true); + } + @Test public void test_empty_schema() throws UnsupportedEncodingException, URISyntaxException { org.opengroup.osdu.core.common.model.http.HttpResponse httpResponse =