Skip to content
Snippets Groups Projects
Commit 31f562f3 authored by Rustam Lotsmanenko (EPAM)'s avatar Rustam Lotsmanenko (EPAM)
Browse files

support array of complex types processing for Items with ref or allOf

parent f7c24d70
No related branches found
No related tags found
1 merge request!142Array of Objects support by Indexer (GONRG-2028)
Pipeline #38369 failed
......@@ -17,6 +17,7 @@ package org.opengroup.osdu.indexer.schema.converter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Supplier;
......@@ -173,50 +174,11 @@ public class PropertiesProcessor {
if ("array".equals(entry.getValue().getType())) {
Items items = entry.getValue().getItems();
if(Objects.isNull(items)){
return Stream.empty();
if(Objects.nonNull(items) && items.isComplexTypeItems()){
return processComplexTypeItems(entry, items);
}
if(Objects.nonNull(items.getProperties()) && !items.getProperties().isEmpty()){
Map<String, String> type = entry.getValue().getIndexingType();
String indexingType = Objects.isNull(type) ?
schemaConverterConfig.getDefaultObjectArraysType() :
type.getOrDefault(TYPE_KEY,schemaConverterConfig.getDefaultObjectArraysType());
/*Schema item inner properties will be processed if they are present & indexingType in schema configured for processing
result ex:
{
path = ArrayItem,
kind = nested,
properties = [{
path = InnerProperty,
kind = double
}, {
path = OtherInnerProperty,
kind = string
}
]
}
*/
if(schemaConverterConfig.getProcessedArraysTypes().contains(indexingType)){
PropertiesProcessor propertiesProcessor = new PropertiesProcessor(definitions, log, new SchemaConverterPropertiesConfig());
return storageSchemaObjectArrayEntry(
indexingType,
entry.getKey(),
items.getProperties().entrySet().stream().flatMap(propertiesProcessor::processPropertyEntry));
/*Otherwise inner properties won't be processed
result ex:
{
path = ArrayItem,
kind = []object
}
*/
}else {
return storageSchemaEntry(indexingType, pathPrefixWithDot + entry.getKey());
}
}
if (schemaConverterConfig.getSupportedArrayTypes().contains(items.getType()) && Objects.isNull(items.getProperties())) {
if (schemaConverterConfig.getSupportedArrayTypes().contains(items.getType()) && !items.isComplexTypeItems()) {
return storageSchemaEntry("[]" + getTypeByDefinitionProperty(entry.getValue()), pathPrefixWithDot + entry.getKey());
}
......@@ -243,6 +205,36 @@ public class PropertiesProcessor {
return storageSchemaEntry(getTypeByDefinitionProperty(entry.getValue()), pathPrefixWithDot + entry.getKey());
}
private Stream<Map<String, Object>> processComplexTypeItems(Entry<String, TypeProperty> entry, Items items) {
Map<String, String> indexHint = entry.getValue().getIndexHint();
String indexingType = Objects.isNull(indexHint) ?
schemaConverterConfig.getDefaultObjectArraysType() :
indexHint.getOrDefault(TYPE_KEY,schemaConverterConfig.getDefaultObjectArraysType());
if(schemaConverterConfig.getProcessedArraysTypes().contains(indexingType)){
PropertiesProcessor propertiesProcessor = new PropertiesProcessor(definitions, log, new SchemaConverterPropertiesConfig());
Stream<Map<String, Object>> propertiesStream = Stream.empty();
if(Objects.nonNull(items.getProperties())){
propertiesStream = items.getProperties().entrySet().stream().flatMap(propertiesProcessor::processPropertyEntry);
}
if (Objects.nonNull(items.getRef())){
propertiesStream = Stream.concat(propertiesStream, propertiesProcessor.processRef(items.getRef()));
}
if(Objects.nonNull(items.getAllOf())){
propertiesStream = Stream.concat(propertiesStream, items.getAllOf().stream().flatMap(propertiesProcessor::processItem));
}
return storageSchemaObjectArrayEntry(
indexingType,
entry.getKey(),
propertiesStream);
}else {
return storageSchemaEntry(indexingType, pathPrefixWithDot + entry.getKey());
}
}
private Stream<Map<String, Object>> processOfItems(Map.Entry<String, TypeProperty> entry) {
Stream<Map<String, Object>> ofItems = null;
......
......@@ -14,12 +14,23 @@
package org.opengroup.osdu.indexer.schema.converter.tags;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import lombok.Data;
@Data
public class Items {
@JsonProperty("$ref")
private String ref;
private List<AllOfItem> allOf;
private String type;
private String pattern;
private Map<String, TypeProperty> properties;
public boolean isComplexTypeItems(){
return Objects.nonNull(ref) || Objects.nonNull(allOf) || Objects.nonNull(properties);
}
}
......@@ -22,7 +22,7 @@ import lombok.Data;
@Data
public class TypeProperty {
@JsonProperty("x-osdu-indexing")
private Map<String, String> indexingType;
private Map<String, String> indexHint;
private String type;
private String pattern;
private String format;
......
......@@ -117,7 +117,7 @@ public class PropertiesProcessorTest {
items.setProperties(itemsProperties);
TypeProperty arrayProperty = new TypeProperty();
arrayProperty.setIndexingType(ImmutableMap.of("type","nested"));
arrayProperty.setIndexHint(ImmutableMap.of("type","nested"));
arrayProperty.setType("array");
arrayProperty.setItems(items);
......@@ -145,7 +145,7 @@ public class PropertiesProcessorTest {
items.setProperties(itemsProperties);
TypeProperty arrayProperty = new TypeProperty();
arrayProperty.setIndexingType(ImmutableMap.of("type","flattened"));
arrayProperty.setIndexHint(ImmutableMap.of("type","flattened"));
arrayProperty.setType("array");
arrayProperty.setItems(items);
......
......@@ -132,6 +132,42 @@
{
"kind": "link",
"path": "GeographicBottomHoleLocation.SpatialGeometryTypeID"
},
{
"path": "VerticalMeasurements",
"kind": "[]object"
},
{
"path": "DrillingReason",
"kind": "[]object"
},
{
"path": "FacilityNameAlias",
"kind": "[]object"
},
{
"path": "FacilityState",
"kind": "[]object"
},
{
"path": "FacilityEvent",
"kind": "[]object"
},
{
"path": "FacilitySpecification",
"kind": "[]object"
},
{
"path": "FacilityOperator",
"kind": "[]object"
},
{
"path": "SpatialLocation",
"kind": "[]object"
},
{
"path": "GeoContexts",
"kind": "[]object"
}
]
}
\ No newline at end of file
......@@ -72,6 +72,14 @@
{
"path": "VersionCreationReason",
"kind": "string"
},
{
"path": "GeoContexts",
"kind": "[]object"
},
{
"path": "NameAliases",
"kind": "[]object"
}
]
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment