diff --git a/NOTICE b/NOTICE index 84fce0ab8b27440e2ed9829ca5363c68df979117..878e5e17c130b55f98a6cc98bc813ced6ffe695a 100644 --- a/NOTICE +++ b/NOTICE @@ -815,7 +815,6 @@ The following software have components provided under the terms of this license: - OSGi resource locator (from ) - Project Lombok (from https://projectlombok.org) -- Project Lombok (from https://projectlombok.org) - javax.ws.rs-api (from http://jax-rs-spec.java.net) ======================================================================== @@ -904,7 +903,6 @@ The following software have components provided under the terms of this license: - Plexus :: Default Container (from ) - Plexus Default Interactivity Handler (from ) - Project Lombok (from https://projectlombok.org) -- Project Lombok (from https://projectlombok.org) - SLF4J API Module (from http://www.slf4j.org) - Spongy Castle (from http://rtyley.github.io/spongycastle/) - Spring Data for Azure Cosmos DB SQL API (from https://github.com/Azure/azure-sdk-for-java/tree/master/sdk/cosmos/azure-spring-data-cosmos) @@ -1006,7 +1004,6 @@ The following software have components provided under the terms of this license: - Microsoft Azure SDK for SQL API of Azure Cosmos DB Service (from https://github.com/Azure/azure-sdk-for-java) - Microsoft Azure client library for Blob Storage (from https://github.com/Azure/azure-sdk-for-java) - Project Lombok (from https://projectlombok.org) -- Project Lombok (from https://projectlombok.org) - Spring Security JWT Library (from http://github.com/spring-projects/spring-security-oauth) - Spring Security JWT Library (from http://github.com/spring-projects/spring-security-oauth) - Spring Web (from https://github.com/spring-projects/spring-framework) diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/PropertiesProcessor.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/PropertiesProcessor.java index 6de10d528cea2a4cbffe060409d361a21ef8c99a..3506c2ca092db2688a6f15a2eca790082ab9b05b 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/PropertiesProcessor.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/PropertiesProcessor.java @@ -56,6 +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); + } + String ref = allOfItem.getRef(); return Objects.isNull(ref) ? @@ -85,7 +89,15 @@ public class PropertiesProcessor { new AppException(HttpStatus.SC_NOT_FOUND, "Failed to find definition:" + definitionSubRef, "Unknown definition:" + definitionSubRef)); - return definition.getProperties().entrySet().stream().flatMap(this::processPropertyEntry); + if (Objects.nonNull(definition.getAllOf())) { + return definition.getAllOf().stream().flatMap(this::processItem); + } + + return processProperties(definition.getProperties()); + } + + public Stream<Map<String, Object>> processProperties(Map<String, TypeProperty> properties){ + return properties.entrySet().stream().flatMap(this::processPropertyEntry); } private Stream<Map<String, Object>> processPropertyEntry(Map.Entry<String, TypeProperty> entry) { @@ -106,6 +118,13 @@ public class PropertiesProcessor { return Stream.empty(); } + if (Objects.nonNull(entry.getValue().getAllOf())) { + PropertiesProcessor propertiesProcessor = new PropertiesProcessor(definitions, pathPrefixWithDot + entry.getKey() + , log, new SchemaConverterPropertiesConfig()); + + return entry.getValue().getAllOf().stream().flatMap(propertiesProcessor::processItem); + } + if (Objects.nonNull(entry.getValue().getProperties())) { PropertiesProcessor propertiesProcessor = new PropertiesProcessor(definitions, pathPrefixWithDot + entry.getKey() , log, new SchemaConverterPropertiesConfig()); @@ -163,7 +182,7 @@ public class PropertiesProcessor { private Supplier<String> getFromFormat(Supplier<String> formatSupplier){ return () -> { - String format = formatSupplier.get();; + String format = formatSupplier.get(); return Objects.nonNull(format) ? schemaConverterConfig.getPrimitiveTypesMap().getOrDefault(format, format) : null; }; } diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/SchemaToStorageFormatImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/SchemaToStorageFormatImpl.java index d35c8d257f4ac4f16ce4c214558ae6f3b0f4653d..1dc63193b3db8c761f492165f9363390a709bdca 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/SchemaToStorageFormatImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/SchemaToStorageFormatImpl.java @@ -101,6 +101,11 @@ public class SchemaToStorageFormatImpl implements SchemaToStorageFormat { storageSchemaItems.addAll(propertiesProcessor.processRef(schemaData.getRef()) .collect(Collectors.toList())); } + + if (schemaData.getProperties() != null) { + storageSchemaItems.addAll(propertiesProcessor.processProperties(schemaData.getProperties()) + .collect(Collectors.toList())); + } } } else { log.warning("Schema doesn't have properties, kind:" + kind); diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/tags/AllOfItem.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/tags/AllOfItem.java index 9499e5636227d0b5c3b8647ce8237856b185aec1..bef9a14bc622a148ddb9d2603914015d1d1bad73 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/tags/AllOfItem.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/tags/AllOfItem.java @@ -17,6 +17,7 @@ package org.opengroup.osdu.indexer.schema.converter.tags; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; +import java.util.List; import java.util.Map; @Data @@ -25,4 +26,5 @@ public class AllOfItem { private String ref; private String type; private Map<String, TypeProperty> properties; + private List<AllOfItem> allOf; } \ No newline at end of file diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/tags/Definition.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/tags/Definition.java index f1b820f3870962093d59c7fed97961daa96b82ae..be8292a287a15885b64f7da6b4770451b5b4d088 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/tags/Definition.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/tags/Definition.java @@ -16,9 +16,11 @@ package org.opengroup.osdu.indexer.schema.converter.tags; import lombok.Data; +import java.util.List; import java.util.Map; @Data public class Definition { private Map<String, TypeProperty> properties; + private List<AllOfItem> allOf; } diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/tags/PropertiesData.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/tags/PropertiesData.java index 706ee8b1172d5dd79dd7d8d9d0e6cef3bee1dce0..6c09c0116b6fbe269d93c13931a46493950fbc9a 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/tags/PropertiesData.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/tags/PropertiesData.java @@ -18,10 +18,12 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; import java.util.List; +import java.util.Map; @Data public class PropertiesData { private List<AllOfItem> allOf; @JsonProperty("$ref") private String ref; + private Map<String, TypeProperty> properties; } diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/tags/TypeProperty.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/tags/TypeProperty.java index 0710bedee52af3a9e06011cd58dec3897879b395..3053e5d20a85ee5165d5436147b9e5c9a1bafc37 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/tags/TypeProperty.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/schema/converter/tags/TypeProperty.java @@ -17,6 +17,7 @@ package org.opengroup.osdu.indexer.schema.converter.tags; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; +import java.util.List; import java.util.Map; @Data @@ -28,4 +29,5 @@ public class TypeProperty { private String ref; private Items items; private Map<String, TypeProperty> properties; + private List<AllOfItem> allOf; } diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/schema/converter/SchemaToStorageFormatImplTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/schema/converter/SchemaToStorageFormatImplTest.java index f43d626175c5c367da75cc7f107c43766ae66c5a..c90092879cf6047a76bb03a0f876abb59e40d358 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/schema/converter/SchemaToStorageFormatImplTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/schema/converter/SchemaToStorageFormatImplTest.java @@ -39,6 +39,8 @@ import static org.junit.Assert.fail; @SpringBootTest public class SchemaToStorageFormatImplTest { + private static final String KIND = "KIND_VAL"; + private ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build(); private JaxRsDpsLog jaxRsDpsLog = Mockito.mock(JaxRsDpsLog.class); @@ -52,19 +54,24 @@ public class SchemaToStorageFormatImplTest { testSingleFile("/converter/basic/schema.json", "osdu:osdu:Wellbore:1.0.0"); } + @Test + public void rootProperties() { + testSingleFile("/converter/root-properties/schema.json", KIND); + } + @Test public void integrationTestSchema1() { - testSingleFile("/converter/integration-tests/index_records_1.schema", "KIND_VAL"); + testSingleFile("/converter/integration-tests/index_records_1.schema", KIND); } @Test public void integrationTestSchema2() { - testSingleFile("/converter/integration-tests/index_records_2.schema", "KIND_VAL"); + testSingleFile("/converter/integration-tests/index_records_2.schema", KIND); } @Test public void integrationTestSchema3() { - testSingleFile("/converter/integration-tests/index_records_3.schema", "KIND_VAL"); + testSingleFile("/converter/integration-tests/index_records_3.schema", KIND); } @Test @@ -72,6 +79,21 @@ public class SchemaToStorageFormatImplTest { testSingleFile("/converter/wks/slb_wke_wellbore.json", "slb:wks:wellbore:1.0.6"); } + @Test + public void allOfInsideAllOf() { + testSingleFile("/converter/tags/allOf/allOf-inside-allOf.json", KIND); + } + + @Test + public void allOfInsideProperty() { + testSingleFile("/converter/tags/allOf/allOf-inside-property.json", KIND); + } + + @Test + public void allOfInDefinitions() { + testSingleFile("/converter/tags/allOf/indefinitions.json", KIND); + } + @Test public void folderPassed() throws URISyntaxException, IOException { @@ -85,8 +107,9 @@ public class SchemaToStorageFormatImplTest { private void testSingleFile(String filename, String kind) { String json = getSchemaFromSchemaService(filename); - Map<String, Object> expected = getStorageSchema( filename + ".res"); + Map<String, Object> converted = schemaToStorageFormatImpl.convertToMap(json, kind); + Map<String, Object> expected = getStorageSchema( filename + ".res"); compareSchemas(expected, converted, filename); } diff --git a/indexer-core/src/test/resources/converter/root-properties/schema.json b/indexer-core/src/test/resources/converter/root-properties/schema.json new file mode 100644 index 0000000000000000000000000000000000000000..55fe1a3024a45fb68d07b13a34f481962e240e92 --- /dev/null +++ b/indexer-core/src/test/resources/converter/root-properties/schema.json @@ -0,0 +1,12 @@ +{ + "properties": { + "data": { + "properties": { + "FacilityName": { + "type": "string" + } + }, + "type": "object" + } + } +} \ No newline at end of file diff --git a/indexer-core/src/test/resources/converter/root-properties/schema.json.res b/indexer-core/src/test/resources/converter/root-properties/schema.json.res new file mode 100644 index 0000000000000000000000000000000000000000..cd12f24cde95db3f254e2c347fb74054f4acf4c1 --- /dev/null +++ b/indexer-core/src/test/resources/converter/root-properties/schema.json.res @@ -0,0 +1,9 @@ +{ + "kind": "KIND_VAL", + "schema": [ + { + "kind": "string", + "path": "FacilityName" + } + ] +} \ No newline at end of file diff --git a/indexer-core/src/test/resources/converter/tags/allOf/allOf-inside-allOf.json b/indexer-core/src/test/resources/converter/tags/allOf/allOf-inside-allOf.json new file mode 100644 index 0000000000000000000000000000000000000000..8ba3af2519d300e8dfcbcc17f77f8cf12bfb3bb0 --- /dev/null +++ b/indexer-core/src/test/resources/converter/tags/allOf/allOf-inside-allOf.json @@ -0,0 +1,56 @@ +{ + "definitions": { + "wellboreData1": { + "properties": { + "prop1": { + "type": "string" + } + } + }, + "wellboreData2": { + "properties": { + "prop2": { + "type": "string" + } + } + }, + "wellboreData3": { + "properties": { + "prop3": { + "type": "string" + } + } + }, + "wellboreData4": { + "properties": { + "prop4": { + "type": "string" + } + } + } + }, + "properties": { + "data": { + "allOf": [ + { + "allOf": [ + { + "$ref": "#/definitions/wellboreData1" + }, + { + "$ref": "#/definitions/wellboreData2" + } + ] + }, + { + "$ref": "#/definitions/wellboreData3" + }, + { + "$ref": "#/definitions/wellboreData4" + } + ] + } + } +} + + diff --git a/indexer-core/src/test/resources/converter/tags/allOf/allOf-inside-allOf.json.res b/indexer-core/src/test/resources/converter/tags/allOf/allOf-inside-allOf.json.res new file mode 100644 index 0000000000000000000000000000000000000000..22a8e6a806ba17e51adbd690f0ef56ac4f9f7bbe --- /dev/null +++ b/indexer-core/src/test/resources/converter/tags/allOf/allOf-inside-allOf.json.res @@ -0,0 +1,21 @@ +{ + "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 diff --git a/indexer-core/src/test/resources/converter/tags/allOf/allOf-inside-property.json b/indexer-core/src/test/resources/converter/tags/allOf/allOf-inside-property.json new file mode 100644 index 0000000000000000000000000000000000000000..1f2d761d21a1501dbf05d3ac59c20f511238f16a --- /dev/null +++ b/indexer-core/src/test/resources/converter/tags/allOf/allOf-inside-property.json @@ -0,0 +1,33 @@ +{ + "definitions": { + "def1": { + "properties": { + "prop1": { + "type": "string" + } + } + } + }, + "properties": { + "data": { + "properties": { + "FacilityName": { + "allOf": [ + { + "$ref": "#/definitions/def1" + }, + { + "properties": { + "val" : { + "type": "string" } + } + } + ] + } + }, + "type": "object" + } + } +} + + diff --git a/indexer-core/src/test/resources/converter/tags/allOf/allOf-inside-property.json.res b/indexer-core/src/test/resources/converter/tags/allOf/allOf-inside-property.json.res new file mode 100644 index 0000000000000000000000000000000000000000..147f31d3c62c34db198da89583bc7e3fca5356e3 --- /dev/null +++ b/indexer-core/src/test/resources/converter/tags/allOf/allOf-inside-property.json.res @@ -0,0 +1,14 @@ +{ + "kind": "KIND_VAL", + "schema": [ + { + "kind": "string", + "path": "FacilityName.prop1" + }, + { + "kind": "string", + "path": "FacilityName.val" + } + + ] +} \ No newline at end of file diff --git a/indexer-core/src/test/resources/converter/tags/allOf/indefinitions.json b/indexer-core/src/test/resources/converter/tags/allOf/indefinitions.json new file mode 100644 index 0000000000000000000000000000000000000000..0064dd0ae4bc8ee01c7dff273f986a762f05ead7 --- /dev/null +++ b/indexer-core/src/test/resources/converter/tags/allOf/indefinitions.json @@ -0,0 +1,29 @@ +{ + "definitions": { + "wellboreData1": { + "properties": { + "prop1": { + "type": "string" + } + } + }, + "wellboreData2": { + "allOf": [ + { + "$ref": "#/definitions/wellboreData1" + } + ] + } + }, + "properties": { + "data": { + "type": "object", + "properties": { + "Field": { + "$ref": "#/definitions/wellboreData2" + } + } + } + } +} + diff --git a/indexer-core/src/test/resources/converter/tags/allOf/indefinitions.json.res b/indexer-core/src/test/resources/converter/tags/allOf/indefinitions.json.res new file mode 100644 index 0000000000000000000000000000000000000000..e17ce90d066d023859f6b91d7756717b494a7a45 --- /dev/null +++ b/indexer-core/src/test/resources/converter/tags/allOf/indefinitions.json.res @@ -0,0 +1,9 @@ +{ + "kind": "KIND_VAL", + "schema": [ + { + "kind": "string", + "path": "Field.prop1" + } + ] +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index eef38efd9dc660066d903e17802171631c6f969e..a85a2d468a67dec3503db2bae8cb53a4be71f1aa 100644 --- a/pom.xml +++ b/pom.xml @@ -125,7 +125,7 @@ <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> - <version>1.18.8</version> + <version>1.18.16</version> <scope>provided</scope> </dependency> </dependencies> diff --git a/provider/indexer-gcp/cloudbuild/cloudbuild.yaml b/provider/indexer-gcp/cloudbuild/cloudbuild.yaml index a0839623e8b0b66a821dd324a3e5bfeff8d2ab98..1d0c9ba890efb3b13d71d7517e9ce2951f56eb00 100644 --- a/provider/indexer-gcp/cloudbuild/cloudbuild.yaml +++ b/provider/indexer-gcp/cloudbuild/cloudbuild.yaml @@ -17,13 +17,13 @@ steps: - name: 'gcr.io/cloud-builders/docker' args: [ - 'build', - '--build-arg', 'PROVIDER_NAME=${_PROVIDER_NAME}', - '--build-arg', 'PORT=${_PORT}', - '-t', 'gcr.io/$PROJECT_ID/${_APPLICATION_NAME}/${_GCP_SERVICE}-${_PROVIDER_NAME}:${_SHORT_SHA}', - '-t', 'gcr.io/$PROJECT_ID/${_APPLICATION_NAME}/${_GCP_SERVICE}-${_PROVIDER_NAME}:latest', - '-f', 'provider/${_GCP_SERVICE}-${_PROVIDER_NAME}/cloudbuild/Dockerfile.cloudbuild', - '.' + 'build', + '--build-arg', 'PROVIDER_NAME=${_PROVIDER_NAME}', + '--build-arg', 'PORT=${_PORT}', + '-t', 'gcr.io/$PROJECT_ID/${_APPLICATION_NAME}/${_GCP_SERVICE}-${_PROVIDER_NAME}:${_SHORT_SHA}', + '-t', 'gcr.io/$PROJECT_ID/${_APPLICATION_NAME}/${_GCP_SERVICE}-${_PROVIDER_NAME}:latest', + '-f', 'provider/${_GCP_SERVICE}-${_PROVIDER_NAME}/cloudbuild/Dockerfile.cloudbuild', + '.' ] images: