diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PropertyConfigurationsCacheVmImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/AugmenterConfigurationCacheVmImpl.java similarity index 71% rename from indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PropertyConfigurationsCacheVmImpl.java rename to indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/AugmenterConfigurationCacheVmImpl.java index 38e5f37a7ba1408711b9ccfbd55016e86e9c4c2d..ec990a98870ba0f9c812560fd97011b14a67f65c 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PropertyConfigurationsCacheVmImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/AugmenterConfigurationCacheVmImpl.java @@ -16,26 +16,26 @@ package org.opengroup.osdu.indexer.cache; import org.opengroup.osdu.core.common.cache.VmCache; -import org.opengroup.osdu.indexer.cache.interfaces.IPropertyConfigurationsCache; +import org.opengroup.osdu.indexer.cache.interfaces.IAugmenterConfigurationCache; import org.opengroup.osdu.indexer.model.Constants; -import org.opengroup.osdu.indexer.model.indexproperty.PropertyConfigurations; +import org.opengroup.osdu.indexer.model.indexproperty.AugmenterConfiguration; import org.springframework.stereotype.Component; @Component -public class PropertyConfigurationsCacheVmImpl implements IPropertyConfigurationsCache { - private VmCache<String, PropertyConfigurations> cache; +public class AugmenterConfigurationCacheVmImpl implements IAugmenterConfigurationCache { + private VmCache<String, AugmenterConfiguration> cache; - public PropertyConfigurationsCacheVmImpl() { + public AugmenterConfigurationCacheVmImpl() { cache = new VmCache<>(Constants.SPEC_CACHE_EXPIRATION, Constants.SPEC_MAX_CACHE_SIZE); } @Override - public void put(String s, PropertyConfigurations o) { + public void put(String s, AugmenterConfiguration o) { this.cache.put(s, o); } @Override - public PropertyConfigurations get(String s) { + public AugmenterConfiguration get(String s) { return this.cache.get(s); } diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PropertyConfigurationsEnabledCacheVmImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/AugmenterConfigurationEnabledCacheVmImpl.java similarity index 84% rename from indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PropertyConfigurationsEnabledCacheVmImpl.java rename to indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/AugmenterConfigurationEnabledCacheVmImpl.java index 1db22ec6f4f7ca3da748d8cfefad1ad751547254..5bfde74d8f53a44c2368a417cc37bea0d7721b44 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/PropertyConfigurationsEnabledCacheVmImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/AugmenterConfigurationEnabledCacheVmImpl.java @@ -16,15 +16,15 @@ package org.opengroup.osdu.indexer.cache; import org.opengroup.osdu.core.common.cache.VmCache; -import org.opengroup.osdu.indexer.cache.interfaces.IPropertyConfigurationsEnabledCache; +import org.opengroup.osdu.indexer.cache.interfaces.IAugmenterConfigurationEnabledCache; import org.opengroup.osdu.indexer.model.Constants; import org.springframework.stereotype.Component; @Component -public class PropertyConfigurationsEnabledCacheVmImpl implements IPropertyConfigurationsEnabledCache { +public class AugmenterConfigurationEnabledCacheVmImpl implements IAugmenterConfigurationEnabledCache { private VmCache<String, Boolean> cache; - public PropertyConfigurationsEnabledCacheVmImpl() { + public AugmenterConfigurationEnabledCacheVmImpl() { cache = new VmCache<>(Constants.SPEC_CACHE_EXPIRATION, Constants.SPEC_MAX_CACHE_SIZE); } diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/interfaces/IPropertyConfigurationsCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/interfaces/IAugmenterConfigurationCache.java similarity index 80% rename from indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/interfaces/IPropertyConfigurationsCache.java rename to indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/interfaces/IAugmenterConfigurationCache.java index 65ee4f96ad29808912c80dec1fb14d1a79651f27..75dbd6041a7dc6d8581802ebc8dc98b720410d09 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/interfaces/IPropertyConfigurationsCache.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/interfaces/IAugmenterConfigurationCache.java @@ -16,7 +16,7 @@ package org.opengroup.osdu.indexer.cache.interfaces; import org.opengroup.osdu.core.common.cache.ICache; -import org.opengroup.osdu.indexer.model.indexproperty.PropertyConfigurations; +import org.opengroup.osdu.indexer.model.indexproperty.AugmenterConfiguration; -public interface IPropertyConfigurationsCache extends ICache<String, PropertyConfigurations> { +public interface IAugmenterConfigurationCache extends ICache<String, AugmenterConfiguration> { } diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/interfaces/IPropertyConfigurationsEnabledCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/interfaces/IAugmenterConfigurationEnabledCache.java similarity index 91% rename from indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/interfaces/IPropertyConfigurationsEnabledCache.java rename to indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/interfaces/IAugmenterConfigurationEnabledCache.java index 98bdbcc5dedeef3f5e1b5bff006a18dccea9afb9..f02de3c599206005deb13230b5d8c238f11cc660 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/interfaces/IPropertyConfigurationsEnabledCache.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/interfaces/IAugmenterConfigurationEnabledCache.java @@ -17,5 +17,5 @@ package org.opengroup.osdu.indexer.cache.interfaces; import org.opengroup.osdu.core.common.cache.ICache; -public interface IPropertyConfigurationsEnabledCache extends ICache<String, Boolean> { +public interface IAugmenterConfigurationEnabledCache extends ICache<String, Boolean> { } diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/PropertyConfigurationsCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/AugmenterConfigurationCache.java similarity index 71% rename from indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/PropertyConfigurationsCache.java rename to indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/AugmenterConfigurationCache.java index 22752ecfb6a86b7bdd6b1fc85c94f02b32017529..c313e660cd6e6c020a22540f72a3eea78b4e0b0a 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/PropertyConfigurationsCache.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/AugmenterConfigurationCache.java @@ -15,24 +15,24 @@ package org.opengroup.osdu.indexer.cache.partitionsafe; -import org.opengroup.osdu.indexer.cache.interfaces.IPropertyConfigurationsCache; -import org.opengroup.osdu.indexer.model.indexproperty.PropertyConfigurations; +import org.opengroup.osdu.indexer.cache.interfaces.IAugmenterConfigurationCache; +import org.opengroup.osdu.indexer.model.indexproperty.AugmenterConfiguration; import org.springframework.stereotype.Component; import javax.inject.Inject; @Component -public class PropertyConfigurationsCache extends AbstractPartitionSafeCache<String,PropertyConfigurations> { +public class AugmenterConfigurationCache extends AbstractPartitionSafeCache<String, AugmenterConfiguration> { @Inject - private IPropertyConfigurationsCache cache; + private IAugmenterConfigurationCache cache; @Override - public void put(String s, PropertyConfigurations o) { + public void put(String s, AugmenterConfiguration o) { this.cache.put(cacheKey(s), o); } @Override - public PropertyConfigurations get(String s) { + public AugmenterConfiguration get(String s) { return this.cache.get(cacheKey(s)); } diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/ConfigurationsEnabledCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/AugmenterConfigurationEnabledCache.java similarity index 82% rename from indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/ConfigurationsEnabledCache.java rename to indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/AugmenterConfigurationEnabledCache.java index 086b4b3ceac97d307d25f17e67e07d23a68cb428..8e2e3c12e820719d287ef584a7cf417c887c49a9 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/ConfigurationsEnabledCache.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/cache/partitionsafe/AugmenterConfigurationEnabledCache.java @@ -15,15 +15,15 @@ package org.opengroup.osdu.indexer.cache.partitionsafe; -import org.opengroup.osdu.indexer.cache.interfaces.IPropertyConfigurationsEnabledCache; +import org.opengroup.osdu.indexer.cache.interfaces.IAugmenterConfigurationEnabledCache; import org.springframework.stereotype.Component; import javax.inject.Inject; @Component -public class ConfigurationsEnabledCache extends AbstractPartitionSafeCache<String,Boolean> { +public class AugmenterConfigurationEnabledCache extends AbstractPartitionSafeCache<String,Boolean> { @Inject - private IPropertyConfigurationsEnabledCache cache; + private IAugmenterConfigurationEnabledCache cache; @Override public void put(String s, Boolean o) { diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/model/indexproperty/PropertyConfigurations.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/model/indexproperty/AugmenterConfiguration.java similarity index 82% rename from indexer-core/src/main/java/org/opengroup/osdu/indexer/model/indexproperty/PropertyConfigurations.java rename to indexer-core/src/main/java/org/opengroup/osdu/indexer/model/indexproperty/AugmenterConfiguration.java index 3c0318dc99c530d2e1efae995e440864b7ec5480..cf97d561077fb0b80048b8da81c0ec575b61b688 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/model/indexproperty/PropertyConfigurations.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/model/indexproperty/AugmenterConfiguration.java @@ -26,12 +26,19 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; @Data @ToString @JsonInclude(JsonInclude.Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) -public class PropertyConfigurations { +public class AugmenterConfiguration { + // Version must be ended with dot and major version only + // e.g. "Code": "osdu:wks:master-data--Well:1." + private static final String KIND_WITH_MAJOR_VERSION_PATTERN = "[\\w\\-\\.]+:[\\w\\-\\.]+:[\\w\\-\\.]+:[0-9]+.$"; + @JsonProperty("Name") private String name; @@ -69,14 +76,14 @@ public class PropertyConfigurations { return false; } - String[] parts = this.code.split(":"); - if(parts.length != 4) { + try { + Pattern pattern = Pattern.compile(KIND_WITH_MAJOR_VERSION_PATTERN); + Matcher matcher = pattern.matcher(this.code); + return matcher.find(); + } + catch(PatternSyntaxException ex) { return false; } - // Version must be ended with dot and major version only - // e.g. "Code": "osdu:wks:master-data--Well:1." - String version = parts[3]; - return (version.length() > 1 && version.indexOf(".") == version.length() - 1); } public boolean hasValidConfigurations() { diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/model/indexproperty/jackson/PropertyPathDeserializer.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/model/indexproperty/jackson/PropertyPathDeserializer.java index 687776ed62597eab4365c3338607c03e5ff8a2ba..e63c97f007a9c7686a84f1b889f777d887e9e098 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/model/indexproperty/jackson/PropertyPathDeserializer.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/model/indexproperty/jackson/PropertyPathDeserializer.java @@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.JsonNode; import org.opengroup.osdu.indexer.model.indexproperty.PropertyPath; +import org.opengroup.osdu.indexer.model.indexproperty.RelatedCondition; import org.opengroup.osdu.indexer.model.indexproperty.RelatedObjectsSpec; import org.opengroup.osdu.indexer.model.indexproperty.ValueExtraction; @@ -26,7 +27,7 @@ public class PropertyPathDeserializer extends JsonDeserializer<PropertyPath> { private final String VALUE_EXTRACTION_RELATED_CONDITION_MATCHES = "ValueExtraction.RelatedConditionMatches"; @Override - public PropertyPath deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JacksonException { + public PropertyPath deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { PropertyPath propertyPath = new PropertyPath(); ObjectCodec codec = jsonParser.getCodec(); JsonNode node = codec.readTree(jsonParser); @@ -64,16 +65,7 @@ public class PropertyPathDeserializer extends JsonDeserializer<PropertyPath> { if(isNotNull(relatedObjectID)) { relatedObjectsSpec.setRelatedObjectID(relatedObjectID.asText()); } - if(isNotNull(relatedConditionProperty)) { - relatedObjectsSpec.setRelatedConditionProperty(relatedConditionProperty.asText()); - } - if(isNotNull(relatedConditionMatches) && relatedConditionMatches.isArray()) { - List<String> conditionMatches = new ArrayList<>(); - for (JsonNode subNode : relatedConditionMatches) { - conditionMatches.add(subNode.asText()); - } - relatedObjectsSpec.setRelatedConditionMatches(conditionMatches); - } + setRelatedCondition(relatedObjectsSpec, relatedConditionProperty, relatedConditionMatches); return relatedObjectsSpec; } @@ -92,22 +84,26 @@ public class PropertyPathDeserializer extends JsonDeserializer<PropertyPath> { if(isNotNull(valuePath)) { valueExtraction.setValuePath(valuePath.asText()); } - if(isNotNull(relatedConditionProperty)) { - valueExtraction.setRelatedConditionProperty(relatedConditionProperty.asText()); - } - if(isNotNull(relatedConditionMatches) && relatedConditionMatches.isArray()) { - List<String> conditionMatches = new ArrayList<>(); - for (JsonNode subNode : relatedConditionMatches) { - conditionMatches.add(subNode.asText()); - } - valueExtraction.setRelatedConditionMatches(conditionMatches); - } + setRelatedCondition(valueExtraction, relatedConditionProperty, relatedConditionMatches); return valueExtraction; } return null; } + private void setRelatedCondition(RelatedCondition relatedCondition, JsonNode relatedConditionProperty, JsonNode relatedConditionMatches) { + if(isNotNull(relatedConditionProperty)) { + relatedCondition.setRelatedConditionProperty(relatedConditionProperty.asText()); + } + if(isNotNull(relatedConditionMatches) && relatedConditionMatches.isArray()) { + List<String> conditionMatches = new ArrayList<>(); + for (JsonNode subNode : relatedConditionMatches) { + conditionMatches.add(subNode.asText()); + } + relatedCondition.setRelatedConditionMatches(conditionMatches); + } + } + private boolean isNotNull(JsonNode node) { return node != null && !node.isNull(); } diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/PropertyConfigurationsService.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/AugmenterConfigurationService.java similarity index 76% rename from indexer-core/src/main/java/org/opengroup/osdu/indexer/service/PropertyConfigurationsService.java rename to indexer-core/src/main/java/org/opengroup/osdu/indexer/service/AugmenterConfigurationService.java index 7aa33277a5b925f0a9c9191b16300059b87f7bbd..0c9df8877d8c72f7bfda58bd8391d4bd9bbb65aa 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/PropertyConfigurationsService.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/AugmenterConfigurationService.java @@ -18,19 +18,19 @@ package org.opengroup.osdu.indexer.service; import org.opengroup.osdu.core.common.model.search.RecordChangedMessages; import org.opengroup.osdu.core.common.model.storage.Schema; import org.opengroup.osdu.core.common.model.storage.SchemaItem; -import org.opengroup.osdu.indexer.model.indexproperty.PropertyConfigurations; +import org.opengroup.osdu.indexer.model.indexproperty.AugmenterConfiguration; import java.util.List; import java.util.Map; -public interface PropertyConfigurationsService { - boolean isPropertyConfigurationsEnabled(String kind); +public interface AugmenterConfigurationService { + boolean isConfigurationEnabled(String kind); - PropertyConfigurations getPropertyConfigurations(String kind); + AugmenterConfiguration getConfiguration(String kind); - Map<String, Object> getExtendedProperties(String objectId, Map<String, Object> originalDataMap, PropertyConfigurations propertyConfigurations); + Map<String, Object> getExtendedProperties(String objectId, Map<String, Object> originalDataMap, AugmenterConfiguration propertyConfigurations); - List<SchemaItem> getExtendedSchemaItems(Schema originalSchema, Map<String, Schema> relatedObjectKindSchemas, PropertyConfigurations propertyConfigurations); + List<SchemaItem> getExtendedSchemaItems(Schema originalSchema, Map<String, Schema> relatedObjectKindSchemas, AugmenterConfiguration propertyConfigurations); String resolveConcreteKind(String kind); diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/PropertyConfigurationsServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/AugmenterConfigurationServiceImpl.java similarity index 92% rename from indexer-core/src/main/java/org/opengroup/osdu/indexer/service/PropertyConfigurationsServiceImpl.java rename to indexer-core/src/main/java/org/opengroup/osdu/indexer/service/AugmenterConfigurationServiceImpl.java index 34d00278729a833ed1658e639421d994382f61d6..e3cc866dd3c4c83db879341990eb2b9d482031af 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/PropertyConfigurationsServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/AugmenterConfigurationServiceImpl.java @@ -45,7 +45,7 @@ import java.util.*; @Component -public class PropertyConfigurationsServiceImpl implements PropertyConfigurationsService { +public class AugmenterConfigurationServiceImpl implements AugmenterConfigurationService { private static final String ASSOCIATED_IDENTITIES_PROPERTY = "AssociatedIdentities"; private static final String VERSION_PROPERTY = "version"; private static final String ASSOCIATED_IDENTITIES_PROPERTY_STORAGE_FORMAT_TYPE = "[]string"; @@ -67,7 +67,7 @@ public class PropertyConfigurationsServiceImpl implements PropertyConfigurations private static final String STRING_ARRAY_KIND = "[]string"; - private static final PropertyConfigurations EMPTY_CONFIGURATIONS = new PropertyConfigurations(); + private static final AugmenterConfiguration EMPTY_AUGMENTER_CONFIGURATION = new AugmenterConfiguration(); private static final String SEARCH_GENERAL_ERROR = "Failed to call search service."; private final Gson gson = new Gson(); @@ -76,9 +76,9 @@ public class PropertyConfigurationsServiceImpl implements PropertyConfigurations @Inject private IndexerConfigurationProperties configurationProperties; @Inject - private PropertyConfigurationsCache propertyConfigurationCache; + private AugmenterConfigurationCache augmenterConfigurationCache; @Inject - private ConfigurationsEnabledCache propertyConfigurationsEnabledCache; + private AugmenterConfigurationEnabledCache augmenterConfigurationEnabledCache; @Inject private ChildRelationshipSpecsCache parentChildRelationshipSpecsCache; @Inject @@ -101,12 +101,12 @@ public class PropertyConfigurationsServiceImpl implements PropertyConfigurations private JaxRsDpsLog jaxRsDpsLog; @Override - public boolean isPropertyConfigurationsEnabled(String kind) { + public boolean isConfigurationEnabled(String kind) { kind = PropertyUtil.getKindWithMajor(kind); if (Strings.isNullOrEmpty(kind)) return false; - Boolean enabled = propertyConfigurationsEnabledCache.get(kind); + Boolean enabled = augmenterConfigurationEnabledCache.get(kind); if(enabled == null) { SearchRequest searchRequest = new SearchRequest(); searchRequest.setKind(INDEX_PROPERTY_PATH_CONFIGURATION_KIND); @@ -118,69 +118,69 @@ public class PropertyConfigurationsServiceImpl implements PropertyConfigurations else { enabled = false; } - propertyConfigurationsEnabledCache.put(kind, enabled); + augmenterConfigurationEnabledCache.put(kind, enabled); } return enabled; } @Override - public PropertyConfigurations getPropertyConfigurations(String kind) { + public AugmenterConfiguration getConfiguration(String kind) { kind = PropertyUtil.getKindWithMajor(kind); if (Strings.isNullOrEmpty(kind)) return null; - PropertyConfigurations configuration = propertyConfigurationCache.get(kind); - if (configuration == null) { - configuration = searchConfigurations(kind); - if (configuration != null) { - if(configuration.isValid()) { + AugmenterConfiguration augmenterConfiguration = augmenterConfigurationCache.get(kind); + if (augmenterConfiguration == null) { + augmenterConfiguration = searchConfiguration(kind); + if (augmenterConfiguration != null) { + if(augmenterConfiguration.isValid()) { // Log for debug - if(configuration.hasInvalidConfigurations()) { - String msg = String.format("PropertyConfigurations: it has invalid PropertyConfiguration for configurations with name '%s':", configuration.getName()); + if(augmenterConfiguration.hasInvalidConfigurations()) { + String msg = String.format("PropertyConfigurations: it has invalid PropertyConfiguration for configurations with name '%s':", augmenterConfiguration.getName()); this.jaxRsDpsLog.warning(msg); } } else { // Log for debug StringBuilder msgBuilder = new StringBuilder(); - msgBuilder.append(String.format("PropertyConfigurations: it is invalid for configurations with name '%s':", configuration.getName())); - if(!configuration.hasValidCode()) { + msgBuilder.append(String.format("PropertyConfigurations: it is invalid for configurations with name '%s':", augmenterConfiguration.getName())); + if(!augmenterConfiguration.hasValidCode()) { msgBuilder.append(System.lineSeparator()); - msgBuilder.append(String.format("The code '%s' is invalid. It should be a valid kind with major version ended with '.'", configuration.getCode())); + msgBuilder.append(String.format("The code '%s' is invalid. It should be a valid kind with major version ended with '.'", augmenterConfiguration.getCode())); } - if(!configuration.hasValidConfigurations()) { + if(!augmenterConfiguration.hasValidConfigurations()) { msgBuilder.append(System.lineSeparator()); msgBuilder.append("It does not have any valid PropertyConfiguration"); } this.jaxRsDpsLog.warning(msgBuilder.toString()); - configuration = EMPTY_CONFIGURATIONS; // reset + augmenterConfiguration = EMPTY_AUGMENTER_CONFIGURATION; // reset } - propertyConfigurationCache.put(kind, configuration); + augmenterConfigurationCache.put(kind, augmenterConfiguration); } else { - // It is common that a kind does not have extended property. So we need to cache an empty configuration + // It is common that a kind does not have extended property. So we need to cache an empty augmenterConfiguration // to avoid unnecessary search - propertyConfigurationCache.put(kind, EMPTY_CONFIGURATIONS); + augmenterConfigurationCache.put(kind, EMPTY_AUGMENTER_CONFIGURATION); } } - if (!isNullOrEmptyConfigurations(configuration)) { - return configuration; + if (!isEmptyConfiguration(augmenterConfiguration)) { + return augmenterConfiguration; } return null; } @Override - public Map<String, Object> getExtendedProperties(String objectId, Map<String, Object> originalDataMap, PropertyConfigurations propertyConfigurations) { + public Map<String, Object> getExtendedProperties(String objectId, Map<String, Object> originalDataMap, AugmenterConfiguration augmenterConfiguration) { // Get all data maps of the related objects in one query in order to improve the performance. - Map<String, Map<String, Object>> idObjectDataMap = getRelatedObjectsData(originalDataMap, propertyConfigurations); + Map<String, Map<String, Object>> idObjectDataMap = getRelatedObjectsData(originalDataMap, augmenterConfiguration); Set<String> associatedIdentities = new HashSet<>(); Map<String, Object> extendedDataMap = new HashMap<>(); - for (PropertyConfiguration configuration : propertyConfigurations.getConfigurations().stream().filter(c -> c.isValid()).toList()) { + for (PropertyConfiguration configuration : augmenterConfiguration.getConfigurations().stream().filter(c -> c.isValid()).toList()) { String extendedPropertyName = configuration.getExtendedPropertyName(); if (originalDataMap.containsKey(extendedPropertyName) && originalDataMap.get(extendedPropertyName) != null) { // If the original record already has the property, then we should not override. @@ -249,10 +249,10 @@ public class PropertyConfigurationsServiceImpl implements PropertyConfigurations } @Override - public List<SchemaItem> getExtendedSchemaItems(Schema originalSchema, Map<String, Schema> relatedObjectKindSchemas, PropertyConfigurations propertyConfigurations) { + public List<SchemaItem> getExtendedSchemaItems(Schema originalSchema, Map<String, Schema> relatedObjectKindSchemas, AugmenterConfiguration augmenterConfiguration) { List<SchemaItem> extendedSchemaItems = new ArrayList<>(); boolean hasChildToParentRelationship = false; - for (PropertyConfiguration configuration : propertyConfigurations.getConfigurations().stream().filter(c -> c.isValid()).toList()) { + for (PropertyConfiguration configuration : augmenterConfiguration.getConfigurations().stream().filter(c -> c.isValid()).toList()) { Schema schema = null; PropertyPath propertyPath = null; for (PropertyPath path : configuration.getPaths().stream().filter(p -> p.hasValidRelatedObjectsSpec()).toList()) { @@ -365,7 +365,7 @@ public class PropertyConfigurationsServiceImpl implements PropertyConfigurations } /******************************************************** Private methods **************************************************************/ - private boolean isNullOrEmptyConfigurations(PropertyConfigurations configuration) { + private boolean isEmptyConfiguration(AugmenterConfiguration configuration) { return configuration == null || Strings.isNullOrEmpty(configuration.getCode()); } @@ -427,10 +427,10 @@ public class PropertyConfigurationsServiceImpl implements PropertyConfigurations return data; } - private Map<String, Map<String, Object>> getRelatedObjectsData(Map<String, Object> originalDataMap, PropertyConfigurations propertyConfigurations) { + private Map<String, Map<String, Object>> getRelatedObjectsData(Map<String, Object> originalDataMap, AugmenterConfiguration augmenterConfiguration) { Map<String, Map<String, Object>> idData = new HashMap<>(); Map<String, Set<String>> kindIds = new HashMap<>(); - for (PropertyConfiguration configuration : propertyConfigurations.getConfigurations().stream().filter(c -> c.isValid()).toList()) { + for (PropertyConfiguration configuration : augmenterConfiguration.getConfigurations().stream().filter(c -> c.isValid()).toList()) { for (PropertyPath path : configuration.getPaths().stream().filter(p -> p.hasValidValueExtraction()).toList()) { if (path.hasValidRelatedObjectsSpec()) { RelatedObjectsSpec relatedObjectsSpec = path.getRelatedObjectsSpec(); @@ -706,7 +706,7 @@ public class PropertyConfigurationsServiceImpl implements PropertyConfigurations if(childrenKinds == null) { childrenKinds = new ChildrenKinds(); Set<String> kinds = new HashSet<>(); - for (PropertyConfigurations propertyConfigurations: searchChildrenKindConfigurations(parentKindWithMajor)) { + for (AugmenterConfiguration propertyConfigurations: searchChildrenKindConfigurations(parentKindWithMajor)) { kinds.add(propertyConfigurations.getCode()); } childrenKinds.setKinds(new ArrayList<>(kinds)); @@ -725,16 +725,16 @@ public class PropertyConfigurationsServiceImpl implements PropertyConfigurations specs = new ParentChildRelationshipSpecs(); specs.setSpecList(specsList); - List<PropertyConfigurations> configurationsList = searchParentKindConfigurations((childKindWithMajor)); - for (PropertyConfigurations configurations : configurationsList) { - for (PropertyConfiguration configuration : configurations.getConfigurations()) { - List<PropertyPath> matchedPropertyPaths = configuration.getPaths().stream().filter(p -> + List<AugmenterConfiguration> augmenterConfigurations = searchParentKindConfigurations((childKindWithMajor)); + for (AugmenterConfiguration augmenterConfiguration : augmenterConfigurations) { + for (PropertyConfiguration propertyConfiguration : augmenterConfiguration.getConfigurations()) { + List<PropertyPath> matchedPropertyPaths = propertyConfiguration.getPaths().stream().filter(p -> p.hasValidRelatedObjectsSpec() && p.getRelatedObjectsSpec().isParentToChildren() && p.getRelatedObjectsSpec().getRelatedObjectKind().contains(childKindWithMajor)) .toList(); for(PropertyPath propertyPath: matchedPropertyPaths) { - ParentChildRelationshipSpec spec = toParentChildRelationshipSpec(propertyPath, configurations.getCode(), childKindWithMajor); + ParentChildRelationshipSpec spec = toParentChildRelationshipSpec(propertyPath, augmenterConfiguration.getCode(), childKindWithMajor); boolean merged = false; for(ParentChildRelationshipSpec sp: specsList) { if(sp.equals(spec)) { @@ -840,9 +840,9 @@ public class PropertyConfigurationsServiceImpl implements PropertyConfigurations return true; } - PropertyConfigurations propertyConfigurations = this.getPropertyConfigurations(childKind); - if(propertyConfigurations != null) { - for (PropertyConfiguration propertyConfiguration : propertyConfigurations.getConfigurations()) { + AugmenterConfiguration augmenterConfiguration = this.getConfiguration(childKind); + if(augmenterConfiguration != null) { + for (PropertyConfiguration propertyConfiguration : augmenterConfiguration.getConfigurations()) { for (PropertyPath propertyPath : propertyConfiguration.getPaths().stream().filter( p -> p.hasValidValueExtraction() && p.hasValidRelatedObjectsSpec()).toList()) { String relatedObjectKind = propertyPath.getRelatedObjectsSpec().getRelatedObjectKind(); @@ -949,7 +949,7 @@ public class PropertyConfigurationsServiceImpl implements PropertyConfigurations return searchRequest; } - private PropertyConfigurations searchConfigurations(String kind) { + private AugmenterConfiguration searchConfiguration(String kind) { String query = String.format("data.Code: \"%s\"", kind); SearchRequest searchRequest = createSearchRequest(INDEX_PROPERTY_PATH_CONFIGURATION_KIND, query); // If there is more than PropertyConfigurations, pick the one that was last modified. @@ -959,42 +959,42 @@ public class PropertyConfigurationsServiceImpl implements PropertyConfigurations sort.setField(Arrays.asList(VERSION_PROPERTY)); sort.setOrder(Arrays.asList(SortOrder.DESC)); searchRequest.setSort(sort); - List<PropertyConfigurations> propertyConfigurationsList = searchConfigurations(searchRequest); - if(!propertyConfigurationsList.isEmpty()) { - if(propertyConfigurationsList.size() > 1) { + List<AugmenterConfiguration> augmenterConfigurations = searchConfigurations(searchRequest); + if(!augmenterConfigurations.isEmpty()) { + if(augmenterConfigurations.size() > 1) { jaxRsDpsLog.warning(String.format("There is more than one PropertyConfigurations for kind: %s", kind)); } - return propertyConfigurationsList.get(0); + return augmenterConfigurations.get(0); } return null; } - private List<PropertyConfigurations> searchParentKindConfigurations(String childKind) { + private List<AugmenterConfiguration> searchParentKindConfigurations(String childKind) { String query = String.format(PARENT_CHILDREN_CONFIGURATION_QUERY_FORMAT, childKind); SearchRequest searchRequest = createSearchRequest(INDEX_PROPERTY_PATH_CONFIGURATION_KIND, query); return searchConfigurations(searchRequest); } - private List<PropertyConfigurations> searchChildrenKindConfigurations(String parentKind) { + private List<AugmenterConfiguration> searchChildrenKindConfigurations(String parentKind) { String query = String.format(CHILDREN_PARENT_CONFIGURATION_QUERY_FORMAT, parentKind); SearchRequest searchRequest = createSearchRequest(INDEX_PROPERTY_PATH_CONFIGURATION_KIND, query); return searchConfigurations(searchRequest); } - private List<PropertyConfigurations> searchConfigurations(SearchRequest searchRequest) { - List<PropertyConfigurations> configurationsList = new ArrayList<>(); + private List<AugmenterConfiguration> searchConfigurations(SearchRequest searchRequest) { + List<AugmenterConfiguration> augmenterConfigurations = new ArrayList<>(); for (SearchRecord searchRecord : searchRecords(searchRequest)) { try { String data = objectMapper.writeValueAsString(searchRecord.getData()); - PropertyConfigurations configurations = objectMapper.readValue(data, PropertyConfigurations.class); + AugmenterConfiguration configurations = objectMapper.readValue(data, AugmenterConfiguration.class); String kind = PropertyUtil.getKindWithMajor(configurations.getCode()); - propertyConfigurationCache.put(kind, configurations); - configurationsList.add(configurations); + augmenterConfigurationCache.put(kind, configurations); + augmenterConfigurations.add(configurations); } catch (JsonProcessingException e) { jaxRsDpsLog.error("failed to deserialize PropertyConfigurations object", e); } } - return configurationsList; + return augmenterConfigurations; } private List<SearchRecord> searchRelatedRecords(List<String> relatedObjectKinds, List<String> relatedObjectIds) { diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaServiceImpl.java index 93faa0486ae50ecf63a7d9e5d6d7d547ca7413ea..467832a7e9f61f550ff336e1b1a2d4cb0dc26de4 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaServiceImpl.java @@ -33,7 +33,7 @@ import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver; import org.opengroup.osdu.indexer.cache.partitionsafe.FlattenedSchemaCache; import org.opengroup.osdu.indexer.cache.partitionsafe.SchemaCache; import org.opengroup.osdu.indexer.model.Kind; -import org.opengroup.osdu.indexer.model.indexproperty.PropertyConfigurations; +import org.opengroup.osdu.indexer.model.indexproperty.AugmenterConfiguration; import org.opengroup.osdu.indexer.schema.converter.exeption.SchemaProcessingException; import org.opengroup.osdu.indexer.schema.converter.interfaces.IVirtualPropertiesSchemaCache; import org.opengroup.osdu.indexer.util.AugmenterSetting; @@ -71,7 +71,7 @@ public class IndexSchemaServiceImpl implements IndexSchemaService { @Inject private IVirtualPropertiesSchemaCache virtualPropertiesSchemaCache; @Inject - private PropertyConfigurationsService propertyConfigurationsService; + private AugmenterConfigurationService augmenterConfigurationService; @Inject private AugmenterSetting augmenterSetting; @@ -178,9 +178,9 @@ public class IndexSchemaServiceImpl implements IndexSchemaService { if(augmenterSetting.isEnabled()) { try { // Merge schema of the extended properties if needed - PropertyConfigurations propertyConfigurations = propertyConfigurationsService.getPropertyConfigurations(kind); - if (propertyConfigurations != null) { - schema = mergeSchemaFromPropertyConfiguration(schema, propertyConfigurations); + AugmenterConfiguration augmenterConfiguration = augmenterConfigurationService.getConfiguration(kind); + if (augmenterConfiguration != null) { + schema = mergeSchemaFromPropertyConfiguration(schema, augmenterConfiguration); } } catch(Exception ex) { @@ -212,10 +212,10 @@ public class IndexSchemaServiceImpl implements IndexSchemaService { return flatSchemaObj; } - private String mergeSchemaFromPropertyConfiguration(String originalSchemaStr, PropertyConfigurations propertyConfigurations) throws UnsupportedEncodingException, URISyntaxException { - Map<String, Schema> relatedObjectKindSchemas = getSchemaOfRelatedObjectKinds(propertyConfigurations); + private String mergeSchemaFromPropertyConfiguration(String originalSchemaStr, AugmenterConfiguration augmenterConfiguration) throws UnsupportedEncodingException, URISyntaxException { + Map<String, Schema> relatedObjectKindSchemas = getSchemaOfRelatedObjectKinds(augmenterConfiguration); Schema originalSchema = gson.fromJson(originalSchemaStr, Schema.class); - List<SchemaItem> extendedSchemaItems = propertyConfigurationsService.getExtendedSchemaItems(originalSchema, relatedObjectKindSchemas, propertyConfigurations); + List<SchemaItem> extendedSchemaItems = augmenterConfigurationService.getExtendedSchemaItems(originalSchema, relatedObjectKindSchemas, augmenterConfiguration); if (!extendedSchemaItems.isEmpty()) { List<SchemaItem> originalSchemaItems = new ArrayList<>(Arrays.asList(originalSchema.getSchema())); originalSchemaItems.addAll(extendedSchemaItems); @@ -226,13 +226,13 @@ public class IndexSchemaServiceImpl implements IndexSchemaService { } } - private Map<String, Schema> getSchemaOfRelatedObjectKinds(PropertyConfigurations propertyConfigurations) throws UnsupportedEncodingException, URISyntaxException { - List<String> relatedObjectKinds = propertyConfigurations.getUniqueRelatedObjectKinds(); + private Map<String, Schema> getSchemaOfRelatedObjectKinds(AugmenterConfiguration augmenterConfiguration) throws UnsupportedEncodingException, URISyntaxException { + List<String> relatedObjectKinds = augmenterConfiguration.getUniqueRelatedObjectKinds(); Map<String, Schema> relatedObjectKindSchemas = new HashMap<>(); for (String relatedObjectKind : relatedObjectKinds) { // The relatedObjectKind defined in property configuration can be kind having major version only // e.g. "RelatedObjectKind": "osdu:wks:master-data--Wellbore:1." - String concreteRelatedObjectKind = propertyConfigurationsService.resolveConcreteKind(relatedObjectKind); + String concreteRelatedObjectKind = augmenterConfigurationService.resolveConcreteKind(relatedObjectKind); if (Strings.isNullOrEmpty(concreteRelatedObjectKind)) continue; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerServiceImpl.java index 06f58bb31d57fc204f2caf4c8a53f1b70257193c..4be79687afd2cebb785852f36165fede11599205 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerServiceImpl.java @@ -44,7 +44,7 @@ import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver; import org.opengroup.osdu.indexer.logging.AuditLogger; import org.opengroup.osdu.indexer.model.BulkRequestResult; -import org.opengroup.osdu.indexer.model.indexproperty.PropertyConfigurations; +import org.opengroup.osdu.indexer.model.indexproperty.AugmenterConfiguration; import org.opengroup.osdu.indexer.provider.interfaces.IPublisher; import org.opengroup.osdu.indexer.util.AugmenterSetting; import org.opengroup.osdu.indexer.util.ElasticClientHandler; @@ -106,7 +106,7 @@ public class IndexerServiceImpl implements IndexerService { @Inject private JobStatus jobStatus; @Inject - private PropertyConfigurationsService propertyConfigurationsService; + private AugmenterConfigurationService augmenterConfigurationService; @Inject private AugmenterSetting augmenterSetting; @@ -162,7 +162,7 @@ public class IndexerServiceImpl implements IndexerService { Map<String, List<String>> upsertKindIds = getUpsertRecordIdsForConfigurationsEnabledKinds(upsertRecordMap, retryRecordIds); Map<String, List<String>> deleteKindIds = getDeleteRecordIdsForConfigurationsEnabledKinds(deleteRecordMap, retryRecordIds); if (!upsertKindIds.isEmpty() || !deleteKindIds.isEmpty()) { - propertyConfigurationsService.updateAssociatedRecords(message, upsertKindIds, deleteKindIds); + augmenterConfigurationService.updateAssociatedRecords(message, upsertKindIds, deleteKindIds); } } catch(Exception ex) { @@ -207,7 +207,7 @@ public class IndexerServiceImpl implements IndexerService { Map<String, List<String>> upsertKindIds = new HashMap<>(); for (Map.Entry<String, Map<String, OperationType>> entry : upsertRecordMap.entrySet()) { String kind = entry.getKey(); - if(propertyConfigurationsService.isPropertyConfigurationsEnabled(kind)) { + if(augmenterConfigurationService.isConfigurationEnabled(kind)) { List<String> processedIds = entry.getValue().keySet().stream().filter(id -> !retryRecordIds.contains(id)).collect(Collectors.toList()); if (!processedIds.isEmpty()) { upsertKindIds.put(kind, processedIds); @@ -221,7 +221,7 @@ public class IndexerServiceImpl implements IndexerService { Map<String, List<String>> deletedRecordKindIdsMap = new HashMap<>(); for (Map.Entry<String, List<String>> entry : deleteRecordMap.entrySet()) { String kind = entry.getKey(); - if(propertyConfigurationsService.isPropertyConfigurationsEnabled(kind)) { + if(augmenterConfigurationService.isConfigurationEnabled(kind)) { List<String> processedIds = entry.getValue().stream().filter(id -> !retryRecordIds.contains(id)).collect(Collectors.toList()); if (!processedIds.isEmpty()) { deletedRecordKindIdsMap.put(kind, processedIds); @@ -352,14 +352,14 @@ public class IndexerServiceImpl implements IndexerService { if(this.augmenterSetting.isEnabled()) { try { - if (propertyConfigurationsService.isPropertyConfigurationsEnabled(storageRecord.getKind())) { - PropertyConfigurations propertyConfigurations = propertyConfigurationsService.getPropertyConfigurations(storageRecord.getKind()); - if (propertyConfigurations != null) { + if (augmenterConfigurationService.isConfigurationEnabled(storageRecord.getKind())) { + AugmenterConfiguration augmenterConfiguration = augmenterConfigurationService.getConfiguration(storageRecord.getKind()); + if (augmenterConfiguration != null) { // Merge extended properties - dataMap = mergeDataFromPropertyConfiguration(storageRecord.getId(), dataMap, propertyConfigurations); + dataMap = mergeDataFromPropertyConfiguration(storageRecord.getId(), dataMap, augmenterConfiguration); } // We cache the dataMap in case the update of this object will trigger update of the related objects. - propertyConfigurationsService.cacheDataRecord(storageRecord.getId(), storageRecord.getKind(), dataMap); + augmenterConfigurationService.cacheDataRecord(storageRecord.getId(), storageRecord.getKind(), dataMap); } } catch(Exception ex) { @@ -420,8 +420,8 @@ public class IndexerServiceImpl implements IndexerService { return document; } - private Map<String, Object> mergeDataFromPropertyConfiguration(String objectId, Map<String, Object> originalDataMap, PropertyConfigurations propertyConfigurations) { - Map<String, Object> extendedDataMap = propertyConfigurationsService.getExtendedProperties(objectId, originalDataMap, propertyConfigurations); + private Map<String, Object> mergeDataFromPropertyConfiguration(String objectId, Map<String, Object> originalDataMap, AugmenterConfiguration augmenterConfiguration) { + Map<String, Object> extendedDataMap = augmenterConfigurationService.getExtendedProperties(objectId, originalDataMap, augmenterConfiguration); if (!extendedDataMap.isEmpty()) { originalDataMap.putAll(extendedDataMap); } diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/model/indexproperty/AugmenterConfigurationTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/model/indexproperty/AugmenterConfigurationTest.java new file mode 100644 index 0000000000000000000000000000000000000000..5e1782334313cb4b0ef199e0bd57eacdf4b319b0 --- /dev/null +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/model/indexproperty/AugmenterConfigurationTest.java @@ -0,0 +1,117 @@ +/* + * Copyright © Schlumberger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.opengroup.osdu.indexer.model.indexproperty; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.SneakyThrows; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.junit4.SpringRunner; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; + +@RunWith(SpringRunner.class) +public class AugmenterConfigurationTest { + private AugmenterConfiguration augmenterConfiguration; + + @Before + public void setup() throws JsonProcessingException { + String jsonText = getJsonFromFile("well_configuration_record.json"); + ObjectMapper objectMapper = new ObjectMapper(); + augmenterConfiguration = objectMapper.readValue(jsonText, AugmenterConfiguration.class); + } + + @Test + public void isValid() { + Assert.assertTrue(augmenterConfiguration.hasValidCode()); + Assert.assertTrue(augmenterConfiguration.hasValidConfigurations()); + Assert.assertFalse(augmenterConfiguration.hasInvalidConfigurations()); + Assert.assertTrue(augmenterConfiguration.isValid()); + } + + @Test + public void hasInvalidCode() { + String code = augmenterConfiguration.getCode(); + + augmenterConfiguration.setCode(code + "0.0"); + Assert.assertFalse(augmenterConfiguration.hasValidCode()); + Assert.assertFalse(augmenterConfiguration.isValid()); + + augmenterConfiguration.setCode("a:b:1."); + Assert.assertFalse(augmenterConfiguration.hasValidCode()); + Assert.assertFalse(augmenterConfiguration.isValid()); + + augmenterConfiguration.setCode(""); + Assert.assertFalse(augmenterConfiguration.hasValidCode()); + Assert.assertFalse(augmenterConfiguration.isValid()); + + augmenterConfiguration.setCode(null); + Assert.assertFalse(augmenterConfiguration.hasValidCode()); + Assert.assertFalse(augmenterConfiguration.isValid()); + } + + @Test + public void hasNoValidConfigurations() { + List<PropertyConfiguration> propertyConfigurations = augmenterConfiguration.getConfigurations(); + + augmenterConfiguration.setConfigurations(new ArrayList<>()); + Assert.assertFalse(augmenterConfiguration.hasValidConfigurations()); + Assert.assertFalse(augmenterConfiguration.hasInvalidConfigurations()); + Assert.assertFalse(augmenterConfiguration.isValid()); + + augmenterConfiguration.setConfigurations(null); + Assert.assertFalse(augmenterConfiguration.hasValidConfigurations()); + Assert.assertFalse(augmenterConfiguration.hasInvalidConfigurations()); + Assert.assertFalse(augmenterConfiguration.isValid()); + + propertyConfigurations.forEach(p -> p.setPolicy("")); + augmenterConfiguration.setConfigurations(propertyConfigurations); + Assert.assertFalse(augmenterConfiguration.hasValidConfigurations()); + Assert.assertTrue(augmenterConfiguration.hasInvalidConfigurations()); + Assert.assertFalse(augmenterConfiguration.isValid()); + } + + @Test + public void hasPartialValidConfigurations() { + List<PropertyConfiguration> propertyConfigurations = augmenterConfiguration.getConfigurations(); + Assert.assertEquals(2, propertyConfigurations.size()); + + propertyConfigurations.get(0).setPolicy(""); + Assert.assertTrue(augmenterConfiguration.hasValidConfigurations()); + Assert.assertTrue(augmenterConfiguration.hasInvalidConfigurations()); + Assert.assertTrue(augmenterConfiguration.isValid()); + } + + @SneakyThrows + private String getJsonFromFile(String file) { + InputStream inStream = this.getClass().getResourceAsStream("/indexproperty/" + file); + BufferedReader br = new BufferedReader(new InputStreamReader(inStream)); + StringBuilder stringBuilder = new StringBuilder(); + String sCurrentLine; + while ((sCurrentLine = br.readLine()) != null) + { + stringBuilder.append(sCurrentLine).append("\n"); + } + return stringBuilder.toString(); + } +} diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/model/indexproperty/PropertyConfigurationsTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/model/indexproperty/PropertyConfigurationsTest.java deleted file mode 100644 index c5856c89befb04ce78865ec16f3f299671290f3f..0000000000000000000000000000000000000000 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/model/indexproperty/PropertyConfigurationsTest.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright © Schlumberger - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.opengroup.osdu.indexer.model.indexproperty; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import lombok.SneakyThrows; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.test.context.junit4.SpringRunner; - -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.List; - -@RunWith(SpringRunner.class) -public class PropertyConfigurationsTest { - private PropertyConfigurations configurations; - - @Before - public void setup() throws JsonProcessingException { - String jsonText = getJsonFromFile("well_configuration_record.json"); - ObjectMapper objectMapper = new ObjectMapper(); - configurations = objectMapper.readValue(jsonText, PropertyConfigurations.class); - } - - @Test - public void isValid() { - Assert.assertTrue(configurations.hasValidCode()); - Assert.assertTrue(configurations.hasValidConfigurations()); - Assert.assertFalse(configurations.hasInvalidConfigurations()); - Assert.assertTrue(configurations.isValid()); - } - - @Test - public void hasInvalidCode() { - String code = configurations.getCode(); - - configurations.setCode(code + "0.0"); - Assert.assertFalse(configurations.hasValidCode()); - Assert.assertFalse(configurations.isValid()); - - configurations.setCode("a:b:1."); - Assert.assertFalse(configurations.hasValidCode()); - Assert.assertFalse(configurations.isValid()); - - configurations.setCode(""); - Assert.assertFalse(configurations.hasValidCode()); - Assert.assertFalse(configurations.isValid()); - - configurations.setCode(null); - Assert.assertFalse(configurations.hasValidCode()); - Assert.assertFalse(configurations.isValid()); - } - - @Test - public void hasNoValidConfigurations() { - List<PropertyConfiguration> propertyConfigurations = configurations.getConfigurations(); - - configurations.setConfigurations(new ArrayList<>()); - Assert.assertFalse(configurations.hasValidConfigurations()); - Assert.assertFalse(configurations.hasInvalidConfigurations()); - Assert.assertFalse(configurations.isValid()); - - configurations.setConfigurations(null); - Assert.assertFalse(configurations.hasValidConfigurations()); - Assert.assertFalse(configurations.hasInvalidConfigurations()); - Assert.assertFalse(configurations.isValid()); - - propertyConfigurations.forEach(p -> p.setPolicy("")); - configurations.setConfigurations(propertyConfigurations); - Assert.assertFalse(configurations.hasValidConfigurations()); - Assert.assertTrue(configurations.hasInvalidConfigurations()); - Assert.assertFalse(configurations.isValid()); - } - - @Test - public void hasPartialValidConfigurations() { - List<PropertyConfiguration> propertyConfigurations = configurations.getConfigurations(); - Assert.assertEquals(2, propertyConfigurations.size()); - - propertyConfigurations.get(0).setPolicy(""); - Assert.assertTrue(configurations.hasValidConfigurations()); - Assert.assertTrue(configurations.hasInvalidConfigurations()); - Assert.assertTrue(configurations.isValid()); - } - - @SneakyThrows - private String getJsonFromFile(String file) { - InputStream inStream = this.getClass().getResourceAsStream("/indexproperty/" + file); - BufferedReader br = new BufferedReader(new InputStreamReader(inStream)); - StringBuilder stringBuilder = new StringBuilder(); - String sCurrentLine; - while ((sCurrentLine = br.readLine()) != null) - { - stringBuilder.append(sCurrentLine).append("\n"); - } - return stringBuilder.toString(); - } -} diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/model/indexproperty/jackson/PropertyPathDeserializerTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/model/indexproperty/jackson/PropertyPathDeserializerTest.java index d149703ab706598c8667ac354d9e6598fa7148a9..7073374ce85b601fac6a876ad2b10dd5300c215c 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/model/indexproperty/jackson/PropertyPathDeserializerTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/model/indexproperty/jackson/PropertyPathDeserializerTest.java @@ -22,7 +22,7 @@ import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.opengroup.osdu.indexer.model.indexproperty.PropertyConfiguration; -import org.opengroup.osdu.indexer.model.indexproperty.PropertyConfigurations; +import org.opengroup.osdu.indexer.model.indexproperty.AugmenterConfiguration; import org.opengroup.osdu.indexer.model.indexproperty.PropertyPath; import org.springframework.test.context.junit4.SpringRunner; @@ -36,11 +36,11 @@ public class PropertyPathDeserializerTest { public void deserialize_configurations_test() throws JsonProcessingException { String jsonText = getJsonFromFile("well_configuration_record.json"); ObjectMapper objectMapper = new ObjectMapper(); - PropertyConfigurations configurations = objectMapper.readValue(jsonText, PropertyConfigurations.class); - Assert.assertNotNull(configurations); - Assert.assertEquals(2, configurations.getConfigurations().size()); - PropertyConfiguration countryNameConfiguration = configurations.getConfigurations().get(0); - PropertyConfiguration wellUWIConfiguration = configurations.getConfigurations().get(1); + AugmenterConfiguration augmenterConfiguration = objectMapper.readValue(jsonText, AugmenterConfiguration.class); + Assert.assertNotNull(augmenterConfiguration); + Assert.assertEquals(2, augmenterConfiguration.getConfigurations().size()); + PropertyConfiguration countryNameConfiguration = augmenterConfiguration.getConfigurations().get(0); + PropertyConfiguration wellUWIConfiguration = augmenterConfiguration.getConfigurations().get(1); Assert.assertEquals("CountryNames", countryNameConfiguration.getName()); Assert.assertEquals(1, countryNameConfiguration.getPaths().size()); diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/PropertyConfigurationsServiceImplTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/AugmenterConfigurationServiceImplTest.java similarity index 90% rename from indexer-core/src/test/java/org/opengroup/osdu/indexer/service/PropertyConfigurationsServiceImplTest.java rename to indexer-core/src/test/java/org/opengroup/osdu/indexer/service/AugmenterConfigurationServiceImplTest.java index 4c5be0ea97eb23ba1d257c6e56bff84a7c5724d8..034393238cfa364cba74eee89c49392c4c13b85a 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/PropertyConfigurationsServiceImplTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/AugmenterConfigurationServiceImplTest.java @@ -40,7 +40,7 @@ import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; import org.opengroup.osdu.indexer.cache.partitionsafe.*; import org.opengroup.osdu.indexer.config.IndexerConfigurationProperties; import org.opengroup.osdu.indexer.model.*; -import org.opengroup.osdu.indexer.model.indexproperty.PropertyConfigurations; +import org.opengroup.osdu.indexer.model.indexproperty.AugmenterConfiguration; import org.opengroup.osdu.indexer.util.IndexerQueueTaskBuilder; import org.springframework.test.context.junit4.SpringRunner; @@ -57,18 +57,18 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.*; @RunWith(SpringRunner.class) -public class PropertyConfigurationsServiceImplTest { +public class AugmenterConfigurationServiceImplTest { private final Gson gson = new Gson(); @InjectMocks - private PropertyConfigurationsServiceImpl sut; + private AugmenterConfigurationServiceImpl sut; @Mock private IndexerConfigurationProperties configurationProperties; @Mock - private PropertyConfigurationsCache propertyConfigurationCache; + private AugmenterConfigurationCache augmenterConfigurationCache; @Mock - private ConfigurationsEnabledCache propertyConfigurationsEnabledCache; + private AugmenterConfigurationEnabledCache augmenterConfigurationEnabledCache; @Mock private ChildRelationshipSpecsCache parentChildRelationshipSpecsCache; @Mock @@ -90,89 +90,89 @@ public class PropertyConfigurationsServiceImplTest { @Mock private JaxRsDpsLog jaxRsDpsLog; - private final String propertyConfigurationKind = "osdu:wks:reference-data--IndexPropertyPathConfiguration:*"; + private final String augmenterConfigurationKind = "osdu:wks:reference-data--IndexPropertyPathConfiguration:*"; private String childKind; private String childId; private String parentKind; private String parentId; @Test - public void isPropertyConfigurationsEnabled_invalid_kind() { - Assert.assertFalse(sut.isPropertyConfigurationsEnabled(null)); - Assert.assertFalse(sut.isPropertyConfigurationsEnabled("")); - Assert.assertFalse(sut.isPropertyConfigurationsEnabled("anyAuth:anySource:anyEntity")); + public void isAugmenterConfigurationEnabled_invalid_kind() { + Assert.assertFalse(sut.isConfigurationEnabled(null)); + Assert.assertFalse(sut.isConfigurationEnabled("")); + Assert.assertFalse(sut.isConfigurationEnabled("anyAuth:anySource:anyEntity")); } @Test - public void isPropertyConfigurationsEnabled_with_value_true_in_cache() { + public void isAugmenterConfigurationEnabled_with_value_true_in_cache() { String kind = "anyAuth:anySource:anyEntity:1."; - when(this.propertyConfigurationsEnabledCache.get(any())).thenReturn(true); - Assert.assertTrue(sut.isPropertyConfigurationsEnabled(kind)); - verify(this.propertyConfigurationsEnabledCache, times(0)).put(any(), any()); + when(this.augmenterConfigurationEnabledCache.get(any())).thenReturn(true); + Assert.assertTrue(sut.isConfigurationEnabled(kind)); + verify(this.augmenterConfigurationEnabledCache, times(0)).put(any(), any()); } @Test - public void isPropertyConfigurationsEnabled_with_value_false_in_cache() { + public void isAugmenterConfigurationEnabled_with_value_false_in_cache() { String kind = "anyAuth:anySource:anyEntity:1."; - when(this.propertyConfigurationsEnabledCache.get(any())).thenReturn(false); - Assert.assertFalse(sut.isPropertyConfigurationsEnabled(kind)); - verify(this.propertyConfigurationsEnabledCache, times(0)).put(any(), any()); + when(this.augmenterConfigurationEnabledCache.get(any())).thenReturn(false); + Assert.assertFalse(sut.isConfigurationEnabled(kind)); + verify(this.augmenterConfigurationEnabledCache, times(0)).put(any(), any()); } @Test - public void isPropertyConfigurationsEnabled_with_result_from_search() throws URISyntaxException { + public void isAugmenterConfigurationEnabled_with_result_from_search() throws URISyntaxException { String kind = "anyAuth:anySource:anyEntity:1."; SearchResponse response = new SearchResponse(); response.setResults(Arrays.asList(new SearchRecord())); - when(this.propertyConfigurationsEnabledCache.get(any())).thenReturn(null); + when(this.augmenterConfigurationEnabledCache.get(any())).thenReturn(null); when(this.searchService.query(any())).thenReturn(response); - Assert.assertTrue(sut.isPropertyConfigurationsEnabled(kind)); - verify(this.propertyConfigurationsEnabledCache, times(1)).put(any(), any()); + Assert.assertTrue(sut.isConfigurationEnabled(kind)); + verify(this.augmenterConfigurationEnabledCache, times(1)).put(any(), any()); } @Test - public void isPropertyConfigurationsEnabled_without_result_from_search() throws URISyntaxException { + public void isAugmenterConfigurationEnabled_without_result_from_search() throws URISyntaxException { String kind = "anyAuth:anySource:anyEntity:1."; SearchResponse response = new SearchResponse(); - when(this.propertyConfigurationsEnabledCache.get(any())).thenReturn(null); + when(this.augmenterConfigurationEnabledCache.get(any())).thenReturn(null); when(this.searchService.query(any())).thenReturn(response); - Assert.assertFalse(sut.isPropertyConfigurationsEnabled(kind)); - verify(this.propertyConfigurationsEnabledCache, times(1)).put(any(), any()); + Assert.assertFalse(sut.isConfigurationEnabled(kind)); + verify(this.augmenterConfigurationEnabledCache, times(1)).put(any(), any()); } @Test - public void getPropertyConfigurations_invalid_kind() { - Assert.assertNull(sut.getPropertyConfigurations(null)); - Assert.assertNull(sut.getPropertyConfigurations("")); - Assert.assertNull(sut.getPropertyConfigurations("anyAuth:anySource:anyEntity")); + public void getAugmenterConfiguration_invalid_kind() { + Assert.assertNull(sut.getConfiguration(null)); + Assert.assertNull(sut.getConfiguration("")); + Assert.assertNull(sut.getConfiguration("anyAuth:anySource:anyEntity")); } @Test - public void getPropertyConfigurations_with_configuration_in_cache() { + public void getAugmenterConfiguration_with_configuration_in_cache() { String code = "anyAuth:anySource:anyEntity:1."; String kind = "anyAuth:anySource:anyEntity:1.0.0"; - PropertyConfigurations configuration = new PropertyConfigurations(); + AugmenterConfiguration configuration = new AugmenterConfiguration(); configuration.setCode(code); - when(this.propertyConfigurationCache.get(eq(code))).thenReturn(configuration); - PropertyConfigurations configuration2 = sut.getPropertyConfigurations(kind); + when(this.augmenterConfigurationCache.get(eq(code))).thenReturn(configuration); + AugmenterConfiguration configuration2 = sut.getConfiguration(kind); Assert.assertNotNull(configuration2); Assert.assertEquals(code, configuration2.getCode()); } @Test - public void getPropertyConfigurations_with_empty_configuration_in_cache() { + public void getAugmenterConfiguration_with_empty_configuration_in_cache() { String code = "anyAuth:anySource:anyEntity:1."; String kind = "anyAuth:anySource:anyEntity:1.0.0"; - PropertyConfigurations configuration = new PropertyConfigurations(); - when(this.propertyConfigurationCache.get(eq(code))).thenReturn(configuration); - PropertyConfigurations configuration2 = sut.getPropertyConfigurations(kind); + AugmenterConfiguration configuration = new AugmenterConfiguration(); + when(this.augmenterConfigurationCache.get(eq(code))).thenReturn(configuration); + AugmenterConfiguration configuration2 = sut.getConfiguration(kind); Assert.assertNull(configuration2); } @Test - public void getPropertyConfigurations_with_result_from_search() throws URISyntaxException { + public void getAugmenterConfiguration_with_result_from_search() throws URISyntaxException { Map<String, Object> data = this.getDataMap("well_configuration_record.json"); SearchRecord searchRecord = new SearchRecord(); searchRecord.setData(data); @@ -183,32 +183,32 @@ public class PropertyConfigurationsServiceImplTest { when(this.searchService.query(any())).thenReturn(searchResponse); String kind = "osdu:wks:master-data--Well:1.0.0"; String code = "osdu:wks:master-data--Well:1."; - PropertyConfigurations configuration = sut.getPropertyConfigurations(kind); + AugmenterConfiguration configuration = sut.getConfiguration(kind); - ArgumentCaptor<PropertyConfigurations> argumentCaptor = ArgumentCaptor.forClass(PropertyConfigurations.class); + ArgumentCaptor<AugmenterConfiguration> argumentCaptor = ArgumentCaptor.forClass(AugmenterConfiguration.class); // If we mock the implementation of propertyConfigurationCache, it should be called once - verify(this.propertyConfigurationCache, times(2)).put(any(), argumentCaptor.capture()); + verify(this.augmenterConfigurationCache, times(2)).put(any(), argumentCaptor.capture()); Assert.assertNotNull(configuration); Assert.assertEquals(code, configuration.getCode()); Assert.assertEquals(code, argumentCaptor.getValue().getCode()); } @Test - public void getPropertyConfigurations_without_result_from_search() throws URISyntaxException { + public void getAugmenterConfiguration_without_result_from_search() throws URISyntaxException { when(this.searchService.query(any())).thenReturn(new SearchResponse()); String kind = "osdu:wks:master-data--Well:1.0.0"; - PropertyConfigurations configuration = sut.getPropertyConfigurations(kind); + AugmenterConfiguration configuration = sut.getConfiguration(kind); - ArgumentCaptor<PropertyConfigurations> argumentCaptor = ArgumentCaptor.forClass(PropertyConfigurations.class); - verify(this.propertyConfigurationCache, times(1)).put(any(), argumentCaptor.capture()); + ArgumentCaptor<AugmenterConfiguration> argumentCaptor = ArgumentCaptor.forClass(AugmenterConfiguration.class); + verify(this.augmenterConfigurationCache, times(1)).put(any(), argumentCaptor.capture()); Assert.assertNull(configuration); Assert.assertNull(argumentCaptor.getValue().getCode()); } @Test public void getExtendedProperties_from_children_objects() throws JsonProcessingException, URISyntaxException { - PropertyConfigurations propertyConfigurations = getConfigurations("wellbore_configuration_record.json"); + AugmenterConfiguration propertyConfigurations = getConfiguration("wellbore_configuration_record.json"); Map<String, Object> originalDataMap = getDataMap("wellbore_data.json"); String jsonText = getJsonFromFile("welllog_search_records.json"); Type type = new TypeToken<List<SearchRecord>>() {}.getType(); @@ -224,7 +224,7 @@ public class PropertyConfigurationsServiceImplTest { @Test public void getExtendedProperties_from_self_and_parent_objects() throws JsonProcessingException, URISyntaxException { - PropertyConfigurations propertyConfigurations = getConfigurations("welllog_configuration_record.json"); + AugmenterConfiguration propertyConfigurations = getConfiguration("welllog_configuration_record.json"); Map<String, Object> originalDataMap = getDataMap("welllog_original_data.json"); SearchResponse searchResponse = new SearchResponse(); @@ -282,14 +282,14 @@ public class PropertyConfigurationsServiceImplTest { @Test public void getExtendedSchemaItems_from_self_and_parent_object_kind() throws JsonProcessingException { - PropertyConfigurations propertyConfigurations = getConfigurations("well_configuration_record.json"); + AugmenterConfiguration augmenterConfiguration = getConfiguration("well_configuration_record.json"); Schema originalSchema = getSchema("well_storage_schema.json"); Schema geoPoliticalEntitySchema = getSchema("geo_political_entity_storage_schema.json"); String relatedObjectKind = "osdu:wks:master-data--GeoPoliticalEntity:1."; Map<String, Schema> relatedObjectKindSchemas = new HashMap<>(); relatedObjectKindSchemas.put(relatedObjectKind, geoPoliticalEntitySchema); - List<SchemaItem> extendedSchemaItems = this.sut.getExtendedSchemaItems(originalSchema, relatedObjectKindSchemas, propertyConfigurations); + List<SchemaItem> extendedSchemaItems = this.sut.getExtendedSchemaItems(originalSchema, relatedObjectKindSchemas, augmenterConfiguration); Assert.assertEquals(3, extendedSchemaItems.size()); SchemaItem countryNameItem = extendedSchemaItems.stream().filter(item -> item.getPath().equals("CountryNames")).findFirst().orElse(null); Assert.assertNotNull(countryNameItem); @@ -306,7 +306,7 @@ public class PropertyConfigurationsServiceImplTest { @Test public void getExtendedSchemaItems_from_multiple_object_kinds() throws JsonProcessingException { - PropertyConfigurations propertyConfigurations = getConfigurations("welllog_configuration_record.json"); + AugmenterConfiguration augmenterConfiguration = getConfiguration("welllog_configuration_record.json"); Schema originalSchema = getSchema("welllog_storage_schema.json"); Map<String, Schema> relatedObjectKindSchemas = new HashMap<>(); Schema wellboreSchema = getSchema("wellbore_storage_schema.json"); @@ -318,7 +318,7 @@ public class PropertyConfigurationsServiceImplTest { Type type = new TypeToken<List<SchemaItem>>() {}.getType(); List<SchemaItem> expectedExtendedSchemaItems = gson.fromJson(jsonText, type); - List<SchemaItem> extendedSchemaItems = this.sut.getExtendedSchemaItems(originalSchema, relatedObjectKindSchemas, propertyConfigurations); + List<SchemaItem> extendedSchemaItems = this.sut.getExtendedSchemaItems(originalSchema, relatedObjectKindSchemas, augmenterConfiguration); Assert.assertEquals(expectedExtendedSchemaItems.size(), extendedSchemaItems.size()); for(int i = 0; i < expectedExtendedSchemaItems.size(); i++) { SchemaItem expectedExtendedSchemaItem = expectedExtendedSchemaItems.get(i); @@ -654,7 +654,7 @@ public class PropertyConfigurationsServiceImplTest { when(this.searchService.query(any())).thenAnswer(invocation -> { SearchRequest searchRequest = invocation.getArgument(0); SearchResponse searchResponse = new SearchResponse(); - if (searchRequest.getKind().toString().equals(propertyConfigurationKind)) { + if (searchRequest.getKind().toString().equals(augmenterConfigurationKind)) { if (searchRequest.getQuery().contains("ParentToChildren")) { // Return of getParentChildRelatedObjectsSpecs(...) Map<String, Object> dataMap = getDataMap("wellbore_configuration_record.json"); @@ -818,7 +818,7 @@ public class PropertyConfigurationsServiceImplTest { when(this.searchService.query(any())).thenAnswer(invocation -> { SearchRequest searchRequest = invocation.getArgument(0); SearchResponse searchResponse = new SearchResponse(); - if (searchRequest.getKind().toString().equals(propertyConfigurationKind)) { + if (searchRequest.getKind().toString().equals(augmenterConfigurationKind)) { if (searchRequest.getQuery().contains("ChildToParent") || searchRequest.getQuery().contains("data.Code:")) { // Return of getParentChildRelatedObjectsSpecs(...) or // getPropertyConfigurations(...) @@ -868,11 +868,11 @@ public class PropertyConfigurationsServiceImplTest { return gson.fromJson(jsonText, Schema.class); } - private PropertyConfigurations getConfigurations(String file) throws JsonProcessingException { + private AugmenterConfiguration getConfiguration(String file) throws JsonProcessingException { Map<String, Object> dataMap = getDataMap(file); ObjectMapper objectMapper = new ObjectMapper(); String data = objectMapper.writeValueAsString(dataMap); - PropertyConfigurations configurations = objectMapper.readValue(data, PropertyConfigurations.class); + AugmenterConfiguration configurations = objectMapper.readValue(data, AugmenterConfiguration.class); return configurations; } diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndexerSchemaServiceTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndexerSchemaServiceTest.java index be63bc65290b01154deffe67a96e14e18b28abdb..8f5cebc0cb16344d44ddb3d4afa6bd4b87225ceb 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndexerSchemaServiceTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndexerSchemaServiceTest.java @@ -34,7 +34,7 @@ import org.opengroup.osdu.core.common.model.storage.SchemaItem; import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver; import org.opengroup.osdu.indexer.cache.partitionsafe.FlattenedSchemaCache; import org.opengroup.osdu.indexer.cache.partitionsafe.SchemaCache; -import org.opengroup.osdu.indexer.model.indexproperty.PropertyConfigurations; +import org.opengroup.osdu.indexer.model.indexproperty.AugmenterConfiguration; import org.opengroup.osdu.indexer.schema.converter.exeption.SchemaProcessingException; import org.opengroup.osdu.indexer.schema.converter.interfaces.IVirtualPropertiesSchemaCache; import org.opengroup.osdu.indexer.util.AugmenterSetting; @@ -81,7 +81,7 @@ public class IndexerSchemaServiceTest { @Mock private IVirtualPropertiesSchemaCache virtualPropertiesSchemaCache; @Mock - private PropertyConfigurationsService propertyConfigurationsService; + private AugmenterConfigurationService propertyConfigurationsService; @Mock private AugmenterSetting augmenterSetting; @InjectMocks @@ -252,7 +252,7 @@ public class IndexerSchemaServiceTest { when(this.schemaCache.get(kind)).thenReturn(null); when(this.schemaService.getSchema(kind)).thenReturn(storageSchema); - when(this.propertyConfigurationsService.getPropertyConfigurations(kind)).thenReturn(new PropertyConfigurations()); + when(this.propertyConfigurationsService.getConfiguration(kind)).thenReturn(new AugmenterConfiguration()); when(this.propertyConfigurationsService.getExtendedSchemaItems(any(), any(), any())).thenReturn(extendedSchemaItems); IndexSchema indexSchema = this.sut.getIndexerInputSchema(kind, false); @@ -293,7 +293,7 @@ public class IndexerSchemaServiceTest { when(this.schemaCache.get(kind)).thenReturn(null); when(this.schemaService.getSchema(kind)).thenReturn(storageSchema); - when(this.propertyConfigurationsService.getPropertyConfigurations(kind)).thenReturn(new PropertyConfigurations()); + when(this.propertyConfigurationsService.getConfiguration(kind)).thenReturn(new AugmenterConfiguration()); when(this.propertyConfigurationsService.getExtendedSchemaItems(any(), any(), any())).thenReturn(extendedSchemaItems); IndexSchema indexSchema = this.sut.getIndexerInputSchema(kind, true); @@ -348,13 +348,13 @@ public class IndexerSchemaServiceTest { " ]\n" + "}"; ObjectMapper objectMapper = new ObjectMapper(); - PropertyConfigurations configurations = objectMapper.readValue(propertyConfigurations, PropertyConfigurations.class); + AugmenterConfiguration augmenterConfiguration = objectMapper.readValue(propertyConfigurations, AugmenterConfiguration.class); when(this.elasticIndexNameResolver.getIndexNameFromKind(kind)).thenReturn(kind.replace(":", "-")); when(this.schemaCache.get(kind)).thenReturn(null); when(this.indicesService.isIndexExist(any(), any())).thenReturn(true); when(this.schemaService.getSchema(kind)).thenReturn(storageSchema); - when(this.propertyConfigurationsService.getPropertyConfigurations(kind)).thenReturn(configurations); + when(this.propertyConfigurationsService.getConfiguration(kind)).thenReturn(augmenterConfiguration); when(this.propertyConfigurationsService.resolveConcreteKind(anyString())).thenAnswer(invocation -> { String relatedObjectKind = invocation.getArgument(0); return relatedObjectKind + "0.0"; diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndexerServiceImplTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndexerServiceImplTest.java index 0207a150d2dd9f4b0efc38550f0b9a675102e111..ebd9d604f4728c5a72687a807a0f4ae5d70c9dba 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndexerServiceImplTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndexerServiceImplTest.java @@ -30,8 +30,6 @@ import org.mockito.ArgumentCaptor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockedStatic; -import org.mockito.Spy; -import org.opengroup.osdu.core.common.http.HeadersUtil; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.core.common.model.entitlements.Acl; import org.opengroup.osdu.core.common.model.http.DpsHeaders; @@ -41,7 +39,7 @@ import org.opengroup.osdu.core.common.model.storage.ConversionStatus; import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver; import org.opengroup.osdu.indexer.logging.AuditLogger; -import org.opengroup.osdu.indexer.model.indexproperty.PropertyConfigurations; +import org.opengroup.osdu.indexer.model.indexproperty.AugmenterConfiguration; import org.opengroup.osdu.indexer.provider.interfaces.IPublisher; import org.opengroup.osdu.indexer.util.AugmenterSetting; import org.opengroup.osdu.indexer.util.ElasticClientHandler; @@ -101,7 +99,7 @@ public class IndexerServiceImplTest { @Mock private IPublisher progressPublisher; @Mock - private PropertyConfigurationsService propertyConfigurationsService; + private AugmenterConfigurationService propertyConfigurationsService; @Mock private IndexerQueueTaskBuilder indexerQueueTaskBuilder; @Mock @@ -182,7 +180,7 @@ public class IndexerServiceImplTest { prepareTestDataAndEnv(this.pubsubMsg); // setup property configuration - when(this.propertyConfigurationsService.isPropertyConfigurationsEnabled(any())).thenReturn(true); + when(this.propertyConfigurationsService.isConfigurationEnabled(any())).thenReturn(true); ArgumentCaptor<Map<String, List<String>>> upsertArgumentCaptor = ArgumentCaptor.forClass(Map.class); ArgumentCaptor<Map<String, List<String>>> deleteArgumentCaptor = ArgumentCaptor.forClass(Map.class); @@ -208,7 +206,7 @@ public class IndexerServiceImplTest { prepareTestDataAndEnv(this.pubsubMsgForDeletion); // setup property configuration - when(this.propertyConfigurationsService.isPropertyConfigurationsEnabled(any())).thenReturn(true); + when(this.propertyConfigurationsService.isConfigurationEnabled(any())).thenReturn(true); ArgumentCaptor<Map<String, List<String>>> upsertArgumentCaptor = ArgumentCaptor.forClass(Map.class); ArgumentCaptor<Map<String, List<String>>> deleteArgumentCaptor = ArgumentCaptor.forClass(Map.class); @@ -234,14 +232,14 @@ public class IndexerServiceImplTest { prepareTestDataAndEnv(this.pubsubMsg); // setup property configuration - when(this.propertyConfigurationsService.isPropertyConfigurationsEnabled(any())).thenReturn(true); - when(this.propertyConfigurationsService.getPropertyConfigurations(any())).thenReturn(new PropertyConfigurations()); + when(this.propertyConfigurationsService.isConfigurationEnabled(any())).thenReturn(true); + when(this.propertyConfigurationsService.getConfiguration(any())).thenReturn(new AugmenterConfiguration()); // test this.sut.processRecordChangedMessages(recordChangedMessages, recordInfos); // validate - verify(this.propertyConfigurationsService, times(2)).getPropertyConfigurations(any()); + verify(this.propertyConfigurationsService, times(2)).getConfiguration(any()); verify(this.propertyConfigurationsService, times(2)).getExtendedProperties(any(), any(), any()); verify(this.propertyConfigurationsService, times(2)).cacheDataRecord(any(), any(), any()); } catch (Exception e) {