From 542f3907daffea82b50a963fda184fc9ff0137b4 Mon Sep 17 00:00:00 2001 From: mohitdeuex Date: Tue, 17 Dec 2024 01:42:14 +0530 Subject: [PATCH 1/2] Fix Entity Schema --- .../elasticsearch/ElasticSearchClient.java | 20 ++++----- .../search/opensearch/OpenSearchClient.java | 20 ++++----- .../glossary/GlossaryTermResourceTest.java | 4 +- .../json/schema/type/entityHierarchy.json | 41 +++---------------- .../ui/src/generated/type/entityHierarchy.ts | 10 +++-- 5 files changed, 34 insertions(+), 61 deletions(-) diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/ElasticSearchClient.java b/openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/ElasticSearchClient.java index fec119ce0a46..5ffe54a23ad1 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/ElasticSearchClient.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/search/elasticsearch/ElasticSearchClient.java @@ -148,7 +148,7 @@ import org.openmetadata.schema.dataInsight.custom.DataInsightCustomChart; import org.openmetadata.schema.dataInsight.custom.DataInsightCustomChartResultList; import org.openmetadata.schema.dataInsight.custom.FormulaHolder; -import org.openmetadata.schema.entity.data.EntityHierarchy__1; +import org.openmetadata.schema.entity.data.EntityHierarchy; import org.openmetadata.schema.entity.data.Table; import org.openmetadata.schema.service.configuration.elasticsearch.ElasticSearchConfiguration; import org.openmetadata.schema.tests.DataQualityReport; @@ -592,21 +592,21 @@ public List buildSearchHierarchy(SearchRequest request, SearchResponse search return response; } - public List buildGlossaryTermSearchHierarchy(SearchResponse searchResponse) { - Map termMap = + public List buildGlossaryTermSearchHierarchy(SearchResponse searchResponse) { + Map termMap = new LinkedHashMap<>(); // termMap represent glossary terms - Map rootTerms = + Map rootTerms = new LinkedHashMap<>(); // rootTerms represent glossaries for (var hit : searchResponse.getHits().getHits()) { String jsonSource = hit.getSourceAsString(); - EntityHierarchy__1 term = JsonUtils.readValue(jsonSource, EntityHierarchy__1.class); - EntityHierarchy__1 glossaryInfo = + EntityHierarchy term = JsonUtils.readValue(jsonSource, EntityHierarchy.class); + EntityHierarchy glossaryInfo = JsonUtils.readTree(jsonSource).path("glossary").isMissingNode() ? null : JsonUtils.convertValue( - JsonUtils.readTree(jsonSource).path("glossary"), EntityHierarchy__1.class); + JsonUtils.readTree(jsonSource).path("glossary"), EntityHierarchy.class); if (glossaryInfo != null) { rootTerms.putIfAbsent(glossaryInfo.getFullyQualifiedName(), glossaryInfo); @@ -626,15 +626,15 @@ public List buildGlossaryTermSearchHierarchy(SearchResponse String termFQN = term.getFullyQualifiedName(); if (parentFQN != null && termMap.containsKey(parentFQN)) { - EntityHierarchy__1 parentTerm = termMap.get(parentFQN); - List children = parentTerm.getChildren(); + EntityHierarchy parentTerm = termMap.get(parentFQN); + List children = parentTerm.getChildren(); children.removeIf( child -> child.getFullyQualifiedName().equals(term.getFullyQualifiedName())); children.add(term); parentTerm.setChildren(children); } else { if (rootTerms.containsKey(termFQN)) { - EntityHierarchy__1 rootTerm = rootTerms.get(termFQN); + EntityHierarchy rootTerm = rootTerms.get(termFQN); rootTerm.setChildren(term.getChildren()); } } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OpenSearchClient.java b/openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OpenSearchClient.java index 2ba538f37cdc..4b3346b493be 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OpenSearchClient.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OpenSearchClient.java @@ -68,7 +68,7 @@ import org.openmetadata.schema.dataInsight.custom.DataInsightCustomChart; import org.openmetadata.schema.dataInsight.custom.DataInsightCustomChartResultList; import org.openmetadata.schema.dataInsight.custom.FormulaHolder; -import org.openmetadata.schema.entity.data.EntityHierarchy__1; +import org.openmetadata.schema.entity.data.EntityHierarchy; import org.openmetadata.schema.entity.data.Table; import org.openmetadata.schema.service.configuration.elasticsearch.ElasticSearchConfiguration; import org.openmetadata.schema.tests.DataQualityReport; @@ -584,21 +584,21 @@ public List buildSearchHierarchy(SearchRequest request, SearchResponse search return response; } - public List buildGlossaryTermSearchHierarchy(SearchResponse searchResponse) { - Map termMap = + public List buildGlossaryTermSearchHierarchy(SearchResponse searchResponse) { + Map termMap = new LinkedHashMap<>(); // termMap represent glossary terms - Map rootTerms = + Map rootTerms = new LinkedHashMap<>(); // rootTerms represent glossaries for (var hit : searchResponse.getHits().getHits()) { String jsonSource = hit.getSourceAsString(); - EntityHierarchy__1 term = JsonUtils.readValue(jsonSource, EntityHierarchy__1.class); - EntityHierarchy__1 glossaryInfo = + EntityHierarchy term = JsonUtils.readValue(jsonSource, EntityHierarchy.class); + EntityHierarchy glossaryInfo = JsonUtils.readTree(jsonSource).path("glossary").isMissingNode() ? null : JsonUtils.convertValue( - JsonUtils.readTree(jsonSource).path("glossary"), EntityHierarchy__1.class); + JsonUtils.readTree(jsonSource).path("glossary"), EntityHierarchy.class); if (glossaryInfo != null) { rootTerms.putIfAbsent(glossaryInfo.getFullyQualifiedName(), glossaryInfo); @@ -618,15 +618,15 @@ public List buildGlossaryTermSearchHierarchy(SearchResponse String termFQN = term.getFullyQualifiedName(); if (parentFQN != null && termMap.containsKey(parentFQN)) { - EntityHierarchy__1 parentTerm = termMap.get(parentFQN); - List children = parentTerm.getChildren(); + EntityHierarchy parentTerm = termMap.get(parentFQN); + List children = parentTerm.getChildren(); children.removeIf( child -> child.getFullyQualifiedName().equals(term.getFullyQualifiedName())); children.add(term); parentTerm.setChildren(children); } else { if (rootTerms.containsKey(termFQN)) { - EntityHierarchy__1 rootTerm = rootTerms.get(termFQN); + EntityHierarchy rootTerm = rootTerms.get(termFQN); rootTerm.setChildren(term.getChildren()); } } diff --git a/openmetadata-service/src/test/java/org/openmetadata/service/resources/glossary/GlossaryTermResourceTest.java b/openmetadata-service/src/test/java/org/openmetadata/service/resources/glossary/GlossaryTermResourceTest.java index c2e15538a3aa..de7141b67d55 100644 --- a/openmetadata-service/src/test/java/org/openmetadata/service/resources/glossary/GlossaryTermResourceTest.java +++ b/openmetadata-service/src/test/java/org/openmetadata/service/resources/glossary/GlossaryTermResourceTest.java @@ -73,7 +73,7 @@ import org.openmetadata.schema.api.data.CreateTable; import org.openmetadata.schema.api.data.TermReference; import org.openmetadata.schema.api.feed.ResolveTask; -import org.openmetadata.schema.entity.data.EntityHierarchy__1; +import org.openmetadata.schema.entity.data.EntityHierarchy; import org.openmetadata.schema.entity.data.Glossary; import org.openmetadata.schema.entity.data.GlossaryTerm; import org.openmetadata.schema.entity.data.GlossaryTerm.Status; @@ -862,7 +862,7 @@ public void test_buildGlossaryTermNestedHierarchy(TestInfo test) throws HttpResp GlossaryTerm childGlossaryTerm = createEntity(create, ADMIN_AUTH_HEADERS); String response = getResponseFormSearchWithHierarchy("glossary_term_search_index", "*childGlossaryTerm*"); - List glossaries = JsonUtils.readObjects(response, EntityHierarchy__1.class); + List glossaries = JsonUtils.readObjects(response, EntityHierarchy.class); boolean isChild = glossaries.stream() .filter(glossary -> "g1".equals(glossary.getName())) // Find glossary with name "g1" diff --git a/openmetadata-spec/src/main/resources/json/schema/type/entityHierarchy.json b/openmetadata-spec/src/main/resources/json/schema/type/entityHierarchy.json index 73fbe9afce77..684264e266dd 100644 --- a/openmetadata-spec/src/main/resources/json/schema/type/entityHierarchy.json +++ b/openmetadata-spec/src/main/resources/json/schema/type/entityHierarchy.json @@ -7,38 +7,12 @@ "type": "object", "javaType": "org.openmetadata.schema.entity.data.EntityHierarchy", "definitions": { - "EntityHierarchy": { - "type": "object", - "properties": { - "id": { - "description": "Unique identifier of an entity hierarchy instance.", - "$ref": "../type/basic.json#/definitions/uuid" - }, - "name": { - "description": "Preferred name for the entity hierarchy.", - "$ref": "../type/basic.json#/definitions/entityName" - }, - "displayName": { - "description": "Display name that identifies this hierarchy.", - "type": "string" - }, - "description": { - "description": "Description of the entity hierarchy.", - "$ref": "../type/basic.json#/definitions/markdown" - }, - "fullyQualifiedName": { - "description": "A unique name that identifies an entity within the hierarchy. It captures name hierarchy in the form of `rootEntity.childEntity`.", - "$ref": "../type/basic.json#/definitions/fullyQualifiedEntityName" - }, - "children": { - "description": "Other entities that are children of this entity.", - "type": "array", - "items": { - "$ref": "#/definitions/EntityHierarchy" - } - } + "entityHierarchyList": { + "type": "array", + "items": { + "$ref": "entityHierarchy.json" }, - "required": ["id", "name", "description"] + "default": null } }, "properties": { @@ -64,10 +38,7 @@ }, "children": { "description": "Other entities that are children of this entity.", - "type": "array", - "items": { - "$ref": "#/definitions/EntityHierarchy" - } + "$ref" : "#/definitions/entityHierarchyList" } }, "required": ["id", "name", "description"], diff --git a/openmetadata-ui/src/main/resources/ui/src/generated/type/entityHierarchy.ts b/openmetadata-ui/src/main/resources/ui/src/generated/type/entityHierarchy.ts index 14ec82f949ff..0264a74d9e44 100644 --- a/openmetadata-ui/src/main/resources/ui/src/generated/type/entityHierarchy.ts +++ b/openmetadata-ui/src/main/resources/ui/src/generated/type/entityHierarchy.ts @@ -10,9 +10,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - - - /** +/** * This schema defines the entity hierarchy structure. */ export interface EntityHierarchy { @@ -43,6 +41,11 @@ export interface EntityHierarchy { name: string; } +/** + * Other entities that are children of this entity. + * + * This schema defines the entity hierarchy structure. + */ export interface ChildElement { /** * Other entities that are children of this entity. @@ -69,5 +72,4 @@ export interface ChildElement { * Preferred name for the entity hierarchy. */ name: string; - [property: string]: any; } From ceaf9b4a7fbac1638631ac62d1e44c82205a5592 Mon Sep 17 00:00:00 2001 From: sonikashah Date: Tue, 17 Dec 2024 19:00:25 +0530 Subject: [PATCH 2/2] fix additionalProperties in entityHierarchy json --- .../src/main/resources/json/schema/type/entityHierarchy.json | 5 ++--- .../main/resources/ui/src/generated/type/entityHierarchy.ts | 2 ++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/openmetadata-spec/src/main/resources/json/schema/type/entityHierarchy.json b/openmetadata-spec/src/main/resources/json/schema/type/entityHierarchy.json index 684264e266dd..859b97024b95 100644 --- a/openmetadata-spec/src/main/resources/json/schema/type/entityHierarchy.json +++ b/openmetadata-spec/src/main/resources/json/schema/type/entityHierarchy.json @@ -12,7 +12,7 @@ "items": { "$ref": "entityHierarchy.json" }, - "default": null + "default": [] } }, "properties": { @@ -41,6 +41,5 @@ "$ref" : "#/definitions/entityHierarchyList" } }, - "required": ["id", "name", "description"], - "additionalProperties": false + "required": ["id", "name", "description"] } diff --git a/openmetadata-ui/src/main/resources/ui/src/generated/type/entityHierarchy.ts b/openmetadata-ui/src/main/resources/ui/src/generated/type/entityHierarchy.ts index 0264a74d9e44..50e646899932 100644 --- a/openmetadata-ui/src/main/resources/ui/src/generated/type/entityHierarchy.ts +++ b/openmetadata-ui/src/main/resources/ui/src/generated/type/entityHierarchy.ts @@ -39,6 +39,7 @@ export interface EntityHierarchy { * Preferred name for the entity hierarchy. */ name: string; + [property: string]: any; } /** @@ -72,4 +73,5 @@ export interface ChildElement { * Preferred name for the entity hierarchy. */ name: string; + [property: string]: any; }