From 991e2e67f0163a0b107cb13ab4f3845b53632fc7 Mon Sep 17 00:00:00 2001 From: Mark Chance <mark.chance@hitachivantara.com> Date: Thu, 26 Sep 2024 14:18:07 -0400 Subject: [PATCH] set feature flag to control mapping WIP --- .../src/main/resources/application.properties | 1 + .../IndexerConfigurationProperties.java | 1 + .../SchemaConverterPropertiesConfig.java | 21 ++++++++++++++----- .../converter/PropertiesProcessorTest.java | 13 ++++++++++-- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/indexer-core-plus/src/main/resources/application.properties b/indexer-core-plus/src/main/resources/application.properties index 2f1c6c98b..5d827e4f1 100644 --- a/indexer-core-plus/src/main/resources/application.properties +++ b/indexer-core-plus/src/main/resources/application.properties @@ -63,6 +63,7 @@ rabbitmq-retry-limit=5 # Feature flag settings featureFlag.strategy=dataPartition +featureFlag.mapBooleanToString.enabled=true featureFlag.asIngestedCoordinates.enabled=false featureFlag.keywordLower.enabled=false featureFlag.bagOfWords.enabled=false diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/config/IndexerConfigurationProperties.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/config/IndexerConfigurationProperties.java index 0b7efbc6e..a8afb4a13 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/config/IndexerConfigurationProperties.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/config/IndexerConfigurationProperties.java @@ -13,6 +13,7 @@ import org.springframework.context.annotation.Configuration; @Getter @Setter public class IndexerConfigurationProperties { + public static final String MAP_BOOL2STRING_FEATURE_NAME = "featureFlag.mapBooleanToString.enabled"; public static final String KEYWORD_LOWER_FEATURE_NAME = "featureFlag.keywordLower.enabled"; public static final String BAG_OF_WORDS_FEATURE_NAME = "featureFlag.bagOfWords.enabled"; public static final String COLLABORATIONS_FEATURE_NAME = "collaborations-enabled"; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/config/SchemaConverterPropertiesConfig.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/config/SchemaConverterPropertiesConfig.java index c09339260..5058a08fd 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/config/SchemaConverterPropertiesConfig.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/config/SchemaConverterPropertiesConfig.java @@ -7,9 +7,13 @@ import java.util.Map; import java.util.Set; import lombok.Getter; import lombok.Setter; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Configuration; +import org.opengroup.osdu.core.common.feature.IFeatureFlag; +import static org.opengroup.osdu.indexer.config.IndexerConfigurationProperties.MAP_BOOL2STRING_FEATURE_NAME; + @Configuration @ConfigurationProperties(prefix = "schema.converter") @Getter @@ -23,6 +27,8 @@ public class SchemaConverterPropertiesConfig implements SchemaConverterConfig { private Set<String> processedArraysTypes = getDefaultArraysTypesForProcessing(); private String defaultObjectArraysType = getObjectArraysDefaultType(); + @Autowired + private IFeatureFlag featureFlagChecker; private Set<String> getDefaultSkippedDefinitions() { return new HashSet<>(Arrays.asList("AbstractAnyCrsFeatureCollection", @@ -46,11 +52,16 @@ public class SchemaConverterPropertiesConfig implements SchemaConverterConfig { private Map<String, String> getDefaultPrimitiveTypesMap() { Map<String, String> defaultPrimitiveTypesMap = new HashMap<>(); - // in the earlier versions boolean was translated to bool and - // this caused mapping boolean values like text as entry in StorageType entry in map is boolean - // in some places boolean is still presented as bool so here both are normalized to boolean - defaultPrimitiveTypesMap.put("boolean", "boolean"); - defaultPrimitiveTypesMap.put("bool", "boolean"); + if (this.featureFlagChecker.isFeatureEnabled(MAP_BOOL2STRING_FEATURE_NAME)) { + // in the earlier versions boolean was translated to bool and + // this caused mapping boolean values like text as entry in StorageType entry in map is boolean + // in some places boolean is still presented as bool so here both are normalized to boolean + defaultPrimitiveTypesMap.put("boolean", "boolean"); + defaultPrimitiveTypesMap.put("bool", "boolean"); + } else { + defaultPrimitiveTypesMap.put("boolean", "bool"); + } + defaultPrimitiveTypesMap.put("number", "double"); defaultPrimitiveTypesMap.put("date-time", "datetime"); defaultPrimitiveTypesMap.put("date", "datetime"); diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/schema/converter/PropertiesProcessorTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/schema/converter/PropertiesProcessorTest.java index 478448df0..88ae2eb82 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/schema/converter/PropertiesProcessorTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/schema/converter/PropertiesProcessorTest.java @@ -30,12 +30,20 @@ import java.util.Map; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.opengroup.osdu.indexer.config.IndexerConfigurationProperties.MAP_BOOL2STRING_FEATURE_NAME; +import org.opengroup.osdu.core.common.feature.IFeatureFlag; +import org.springframework.beans.factory.annotation.Autowired; + +import static org.opengroup.osdu.indexer.config.IndexerConfigurationProperties.MAP_BOOL2STRING_FEATURE_NAME; public class PropertiesProcessorTest { private static final String PATH = "given_path"; private static final String DEFINITIONS_PREFIX = "#/definitions/"; + @Autowired + private IFeatureFlag featureFlagChecker; + @Test public void should_fail_on_bad_reference_definition() { PropertiesProcessor propertiesProcessor = new PropertiesProcessor(Mockito.mock(Definitions.class), new SchemaConverterPropertiesConfig()); @@ -121,7 +129,8 @@ public class PropertiesProcessorTest { String res = new PropertiesProcessor(Mockito.mock(Definitions.class), new SchemaConverterPropertiesConfig()) .processItem(allOfItem).map(Object::toString).reduce("", String::concat); - assertEquals("{path=" + PATH + ", kind=boolean}", res); + String preferredType = (this.featureFlagChecker.isFeatureEnabled(MAP_BOOL2STRING_FEATURE_NAME))?"string":"boolean"; + assertEquals("{{path=${PATH}, kind=${preferredType}}}", res); } @Test @@ -246,4 +255,4 @@ public class PropertiesProcessorTest { .processItem(allOfItem).map(Object::toString).reduce("", String::concat); assertEquals("{path="+ PATH + ", kind=[]int}",res); } -} \ No newline at end of file +} -- GitLab