Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • osdu/platform/system/indexer-service
  • schundu/indexer-service
2 results
Show changes
Commits on Source (9)
Showing
with 339 additions and 14 deletions
......@@ -56,8 +56,10 @@ public class PropertiesProcessor {
public Stream<Map<String, Object>> processItem(AllOfItem allOfItem) {
Preconditions.checkNotNull(allOfItem, "allOfItem cannot be null");
if (Objects.nonNull(allOfItem.getAllOf())) {
return allOfItem.getAllOf().stream().flatMap(this::processItem);
Stream<Map<String, Object>> ofItems = processOfItems(allOfItem.getAllOf(), allOfItem.getAnyOf(), allOfItem.getOneOf());
if (Objects.nonNull(ofItems)) {
return ofItems;
}
String ref = allOfItem.getRef();
......@@ -89,13 +91,34 @@ public class PropertiesProcessor {
new AppException(HttpStatus.SC_NOT_FOUND, "Failed to find definition:" + definitionSubRef,
"Unknown definition:" + definitionSubRef));
if (Objects.nonNull(definition.getAllOf())) {
return definition.getAllOf().stream().flatMap(this::processItem);
Stream<Map<String, Object>> ofItems =
processOfItems(definition.getAllOf(), definition.getAnyOf(), definition.getOneOf());
if (Objects.nonNull(ofItems)) {
return ofItems;
}
return processProperties(definition.getProperties());
}
private Stream<Map<String, Object>> processOfItems(List<AllOfItem> allOf, List<AllOfItem> anyOf, List<AllOfItem> oneOf) {
Stream<Map<String, Object>> ofItems = null;
if (Objects.nonNull(allOf)) {
ofItems = allOf.stream().flatMap(this::processItem);
}
if (Objects.nonNull(anyOf)) {
ofItems = Stream.concat(Optional.ofNullable(ofItems).orElseGet(Stream::empty), anyOf.stream().flatMap(this::processItem));
}
if (Objects.nonNull(oneOf)) {
ofItems = Stream.concat(Optional.ofNullable(ofItems).orElseGet(Stream::empty), oneOf.stream().flatMap(this::processItem));
}
return ofItems;
}
public Stream<Map<String, Object>> processProperties(Map<String, TypeProperty> properties){
return properties.entrySet().stream().flatMap(this::processPropertyEntry);
}
......@@ -118,11 +141,10 @@ public class PropertiesProcessor {
return Stream.empty();
}
if (Objects.nonNull(entry.getValue().getAllOf())) {
PropertiesProcessor propertiesProcessor = new PropertiesProcessor(definitions, pathPrefixWithDot + entry.getKey()
, log, new SchemaConverterPropertiesConfig());
Stream<Map<String, Object>> ofItems = processOfItems(entry);
return entry.getValue().getAllOf().stream().flatMap(propertiesProcessor::processItem);
if (Objects.nonNull(ofItems)) {
return ofItems;
}
if (Objects.nonNull(entry.getValue().getProperties())) {
......@@ -139,6 +161,35 @@ public class PropertiesProcessor {
return storageSchemaEntry(getTypeByDefinitionProperty(entry.getValue()), pathPrefixWithDot + entry.getKey());
}
private Stream<Map<String, Object>> processOfItems(Map.Entry<String, TypeProperty> entry) {
Stream<Map<String, Object>> ofItems = null;
if (Objects.nonNull(entry.getValue().getAllOf())) {
PropertiesProcessor propertiesProcessor = new PropertiesProcessor(definitions, pathPrefixWithDot + entry.getKey()
, log, new SchemaConverterPropertiesConfig());
ofItems = entry.getValue().getAllOf().stream().flatMap(propertiesProcessor::processItem);
}
if (Objects.nonNull(entry.getValue().getAnyOf())) {
PropertiesProcessor propertiesProcessor = new PropertiesProcessor(definitions, pathPrefixWithDot + entry.getKey()
, log, new SchemaConverterPropertiesConfig());
ofItems = Stream.concat(Optional.ofNullable(ofItems).orElseGet(Stream::empty),
entry.getValue().getAnyOf().stream().flatMap(propertiesProcessor::processItem));
}
if (Objects.nonNull(entry.getValue().getOneOf())) {
PropertiesProcessor propertiesProcessor = new PropertiesProcessor(definitions, pathPrefixWithDot + entry.getKey()
, log, new SchemaConverterPropertiesConfig());
ofItems = Stream.concat(Optional.ofNullable(ofItems).orElseGet(Stream::empty),
entry.getValue().getOneOf().stream().flatMap(propertiesProcessor::processItem));
}
return ofItems;
}
private Stream<Map<String, Object>> storageSchemaEntry(String kind, String path) {
Preconditions.checkNotNullOrEmpty(kind, "kind cannot be null or empty");
Preconditions.checkNotNullOrEmpty(path, "path cannot be null or empty");
......
......@@ -97,6 +97,18 @@ public class SchemaToStorageFormatImpl implements SchemaToStorageFormat {
.collect(Collectors.toList()));
}
if (schemaData.getAnyOf() != null) {
storageSchemaItems.addAll(schemaServiceSchema.getProperties().getData().getAnyOf().stream()
.flatMap(propertiesProcessor::processItem)
.collect(Collectors.toList()));
}
if (schemaData.getOneOf() != null) {
storageSchemaItems.addAll(schemaServiceSchema.getProperties().getData().getOneOf().stream()
.flatMap(propertiesProcessor::processItem)
.collect(Collectors.toList()));
}
if (schemaData.getRef() != null) {
storageSchemaItems.addAll(propertiesProcessor.processRef(schemaData.getRef())
.collect(Collectors.toList()));
......
......@@ -299,4 +299,67 @@ Ignored for now (array of references)
```
\"kind\": \"long\"
\ No newline at end of file
\"kind\": \"long\"
Processing specifics
----------------------------------------------------------------------------
allOf, anyOf and oneOf tags are processed at the same way. All internal data(properties) are included into converted schema.
For instance
```json
{
"definitions": {
"wellboreData1": {
"properties": {
"prop1": {
"type": "string"
}
}
},
"wellboreData2": {
"properties": {
"prop2": {
"type": "string"
}
}
}
},
"properties": {
"data": {
"allOf": [
{
"anyOf": [
{
"$ref": "#/definitions/wellboreData1"
} ],
"oneOf": [
{
"$ref": "#/definitions/wellboreData2"
}
]
}
]
}
}
}
```
is converted to
```json
{
"kind": "KIND_VAL",
"schema": [
{
"kind": "string",
"path": "prop1"
},
{
"kind": "string",
"path": "prop2"
}
]
}
```
......@@ -27,4 +27,6 @@ public class AllOfItem {
private String type;
private Map<String, TypeProperty> properties;
private List<AllOfItem> allOf;
private List<AllOfItem> oneOf;
private List<AllOfItem> anyOf;
}
\ No newline at end of file
......@@ -23,4 +23,6 @@ import java.util.Map;
public class Definition {
private Map<String, TypeProperty> properties;
private List<AllOfItem> allOf;
private List<AllOfItem> oneOf;
private List<AllOfItem> anyOf;
}
......@@ -23,6 +23,8 @@ import java.util.Map;
@Data
public class PropertiesData {
private List<AllOfItem> allOf;
private List<AllOfItem> oneOf;
private List<AllOfItem> anyOf;
@JsonProperty("$ref")
private String ref;
private Map<String, TypeProperty> properties;
......
......@@ -30,4 +30,6 @@ public class TypeProperty {
private Items items;
private Map<String, TypeProperty> properties;
private List<AllOfItem> allOf;
private List<AllOfItem> oneOf;
private List<AllOfItem> anyOf;
}
......@@ -94,6 +94,21 @@ public class SchemaToStorageFormatImplTest {
testSingleFile("/converter/tags/allOf/indefinitions.json", KIND);
}
@Test
public void oneOfInDefinitions() {
testSingleFile("/converter/tags/oneOf/indefinitions.json", KIND);
}
@Test
public void anyOfInDefinitions() {
testSingleFile("/converter/tags/anyOf/indefinitions.json", KIND);
}
@Test
public void mixAllAnyOneOf() {
testSingleFile("/converter/tags/mixAllAnyOneOf/mix.json", KIND);
}
@Test
public void folderPassed() throws URISyntaxException, IOException {
......
......@@ -20,7 +20,11 @@
},
"County": {
"type": "string"
},
}}}],
"anyOf": [
{
"type": "object",
"properties": {
"State": {
"type": "string"
},
......@@ -41,7 +45,11 @@
},
"EmptyAttribute": {
"type": "string"
},
}}}],
"oneOf": [
{
"type": "object",
"properties": {
"Rank": {
"type": "integer"
},
......
{
"definitions": {
"wellboreData1": {
"properties": {
"prop1": {
"type": "string"
}
}
},
"wellboreData2": {
"anyOf": [
{
"$ref": "#/definitions/wellboreData1"
}
]
}
},
"properties": {
"data": {
"type": "object",
"properties": {
"Field": {
"$ref": "#/definitions/wellboreData2"
}
}
}
}
}
{
"kind": "KIND_VAL",
"schema": [
{
"kind": "string",
"path": "Field.prop1"
}
]
}
\ No newline at end of file
{
"definitions": {
"wellboreData1": {
"properties": {
"prop1": {
"type": "string"
}
}
},
"wellboreData2": {
"properties": {
"prop2": {
"type": "string"
}
}
},
"wellboreData3": {
"properties": {
"prop3": {
"type": "string"
}
}
},
"wellboreData4": {
"properties": {
"prop4": {
"type": "string"
}
}
}
},
"properties": {
"data": {
"allOf": [
{
"anyOf": [
{
"$ref": "#/definitions/wellboreData1"
} ],
"oneOf": [
{
"$ref": "#/definitions/wellboreData2"
}
]
},
{
"$ref": "#/definitions/wellboreData3"
},
{
"$ref": "#/definitions/wellboreData4"
}
]
}
}
}
{
"kind": "KIND_VAL",
"schema": [
{
"kind": "string",
"path": "prop1"
},
{
"kind": "string",
"path": "prop2"
},
{
"kind": "string",
"path": "prop3"
},
{
"kind": "string",
"path": "prop4"
}
]
}
\ No newline at end of file
{
"definitions": {
"wellboreData1": {
"properties": {
"prop1": {
"type": "string"
}
}
},
"wellboreData2": {
"anyOf": [
{
"$ref": "#/definitions/wellboreData1"
}
]
}
},
"properties": {
"data": {
"type": "object",
"properties": {
"Field": {
"$ref": "#/definitions/wellboreData2"
}
}
}
}
}
{
"kind": "KIND_VAL",
"schema": [
{
"kind": "string",
"path": "Field.prop1"
}
]
}
\ No newline at end of file
......@@ -4,7 +4,7 @@
"authority": "tenant1",
"source": "indexer-int-test",
"entityType": "sample-schema-1",
"schemaVersionMajor": "1",
"schemaVersionMajor": "2",
"schemaVersionMinor": "0",
"schemaVersionPatch": "4"
},
......@@ -32,7 +32,14 @@
},
"County": {
"type": "string"
},
}
}
}
],
"anyOf": [
{
"type": "object",
"properties": {
"State": {
"type": "string"
},
......@@ -53,7 +60,14 @@
},
"EmptyAttribute": {
"type": "string"
},
}
}
}
],
"oneOf": [
{
"type": "object",
"properties": {
"Rank": {
"type": "integer"
},
......