mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2026-01-08 13:36:32 +00:00
This commit is contained in:
parent
ba97b40c79
commit
fd30229f4c
@ -72,14 +72,14 @@ public class GlossaryTermRepository extends EntityRepository<GlossaryTerm> {
|
||||
|
||||
private EntityReference getParent(GlossaryTerm entity) throws IOException {
|
||||
List<String> ids =
|
||||
findFrom(entity.getId(), Entity.GLOSSARY_TERM, Relationship.PARENT_OF, Entity.GLOSSARY, entity.getDeleted());
|
||||
findFrom(
|
||||
entity.getId(), Entity.GLOSSARY_TERM, Relationship.PARENT_OF, Entity.GLOSSARY_TERM, entity.getDeleted());
|
||||
return ids.size() == 1 ? Entity.getEntityReference(Entity.GLOSSARY_TERM, UUID.fromString(ids.get(0))) : null;
|
||||
}
|
||||
|
||||
private List<EntityReference> getChildren(GlossaryTerm entity) throws IOException {
|
||||
List<String> ids =
|
||||
findBoth(
|
||||
entity.getId(), Entity.GLOSSARY_TERM, Relationship.PARENT_OF, Entity.GLOSSARY_TERM, entity.getDeleted());
|
||||
findTo(entity.getId(), Entity.GLOSSARY_TERM, Relationship.PARENT_OF, Entity.GLOSSARY_TERM, entity.getDeleted());
|
||||
List<EntityReference> children = new ArrayList<>();
|
||||
for (String id : ids) {
|
||||
children.add(Entity.getEntityReference(Entity.GLOSSARY_TERM, UUID.fromString(id)));
|
||||
@ -120,7 +120,7 @@ public class GlossaryTermRepository extends EntityRepository<GlossaryTerm> {
|
||||
entity.setFullyQualifiedName(entity.getGlossary().getName() + "." + entity.getName());
|
||||
} else {
|
||||
EntityReference parent = Entity.getEntityReference(entity.getParent());
|
||||
entity.setFullyQualifiedName(entity.getParent().getName() + "." + entity.getName());
|
||||
entity.setFullyQualifiedName(parent.getName() + "." + entity.getName());
|
||||
entity.setParent(parent);
|
||||
}
|
||||
|
||||
|
||||
@ -367,7 +367,6 @@ public class TableRepository extends EntityRepository<Table> {
|
||||
@Override
|
||||
public void storeRelationships(Table table) {
|
||||
// Add relationship from database to table
|
||||
String databaseId = table.getDatabase().getId().toString();
|
||||
addRelationship(table.getDatabase().getId(), table.getId(), DATABASE, TABLE, Relationship.CONTAINS);
|
||||
|
||||
// Add table owner relationship
|
||||
|
||||
@ -92,6 +92,7 @@ public class GlossaryTermResource {
|
||||
term.withHref(RestUtil.getHref(uriInfo, COLLECTION_PATH, term.getId()));
|
||||
Entity.withHref(uriInfo, term.getGlossary());
|
||||
Entity.withHref(uriInfo, term.getParent());
|
||||
Entity.withHref(uriInfo, term.getChildren());
|
||||
Entity.withHref(uriInfo, term.getRelatedTerms());
|
||||
Entity.withHref(uriInfo, term.getReviewers());
|
||||
return term;
|
||||
|
||||
@ -34,6 +34,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.joda.time.Period;
|
||||
import org.joda.time.format.ISOPeriodFormat;
|
||||
import org.openmetadata.catalog.Entity;
|
||||
import org.openmetadata.catalog.entity.data.GlossaryTerm;
|
||||
import org.openmetadata.catalog.entity.teams.Team;
|
||||
import org.openmetadata.catalog.entity.teams.User;
|
||||
import org.openmetadata.catalog.exception.CatalogExceptionMessage;
|
||||
@ -123,6 +124,9 @@ public final class EntityUtil {
|
||||
(filter1, filter2) ->
|
||||
filter1.getEventType().equals(filter2.getEventType()) && filter1.getEntities().equals(filter2.getEntities());
|
||||
|
||||
public static final BiPredicate<GlossaryTerm, GlossaryTerm> glossaryTermMatch =
|
||||
(filter1, filter2) -> filter1.getFullyQualifiedName().equals(filter2.getFullyQualifiedName());
|
||||
|
||||
private EntityUtil() {}
|
||||
|
||||
/** Validate Ingestion Schedule */
|
||||
|
||||
@ -75,8 +75,6 @@
|
||||
"default": false
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"id",
|
||||
"name"
|
||||
]
|
||||
}
|
||||
"required": ["id", "name"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
|
||||
@ -23,10 +23,11 @@
|
||||
"type": "string",
|
||||
"format": "uri"
|
||||
}
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"status" : {
|
||||
"type" : "string",
|
||||
"status": {
|
||||
"type": "string",
|
||||
"enum": ["Draft", "Approved", "Deprecated"],
|
||||
"default": "Draft"
|
||||
}
|
||||
@ -62,12 +63,12 @@
|
||||
}
|
||||
},
|
||||
"glossary": {
|
||||
"description": "Glosary that this term belongs to.",
|
||||
"$ref" : "../../type/entityReference.json"
|
||||
"description": "Glossary that this term belongs to.",
|
||||
"$ref": "../../type/entityReference.json"
|
||||
},
|
||||
"parent": {
|
||||
"description": "Parent glossary term that this term is child of. When `null` this term is the root term of the glossary.",
|
||||
"$ref" : "../../type/entityReference.json"
|
||||
"$ref": "../../type/entityReference.json"
|
||||
},
|
||||
"children": {
|
||||
"description": "Other glossary terms that are children of this glossary term.",
|
||||
@ -117,9 +118,9 @@
|
||||
"description": "Change that lead to this version of the entity.",
|
||||
"$ref": "../../type/entityHistory.json#/definitions/changeDescription"
|
||||
},
|
||||
"status" : {
|
||||
"description" : "Status of the glossary term.",
|
||||
"$ref" : "#/definitions/status"
|
||||
"status": {
|
||||
"description": "Status of the glossary term.",
|
||||
"$ref": "#/definitions/status"
|
||||
},
|
||||
"deleted": {
|
||||
"description": "When `true` indicates the entity has been soft deleted.",
|
||||
@ -127,9 +128,6 @@
|
||||
"default": false
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"id",
|
||||
"name",
|
||||
"glossary"
|
||||
]
|
||||
}
|
||||
"required": ["id", "name", "glossary"],
|
||||
"additionalProperties": false
|
||||
}
|
||||
|
||||
@ -763,7 +763,7 @@ public abstract class EntityResourceTest<T, K> extends CatalogApplicationTest {
|
||||
String[] split = entityInterface.getFullyQualifiedName().split("\\.");
|
||||
String actualName = split[split.length - 1];
|
||||
assertTrue(actualName.contains("foo_DOT_bar"));
|
||||
assertTrue(!actualName.contains("foo.bar"));
|
||||
assertFalse(actualName.contains("foo.bar"));
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -18,6 +18,7 @@ package org.openmetadata.catalog.resources.glossary;
|
||||
|
||||
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.openmetadata.catalog.exception.CatalogExceptionMessage.glossaryTermMismatch;
|
||||
import static org.openmetadata.catalog.util.TestUtils.ADMIN_AUTH_HEADERS;
|
||||
@ -114,8 +115,12 @@ public class GlossaryTermResourceTest extends EntityResourceTest<GlossaryTerm, C
|
||||
Glossary glossary1 = glossaryResourceTest.createEntity(createGlossary, ADMIN_AUTH_HEADERS);
|
||||
|
||||
GlossaryTerm term1 = createTerm(glossary1, null, "term1");
|
||||
createTerm(glossary1, term1, "term11");
|
||||
createTerm(glossary1, term1, "term12");
|
||||
GlossaryTerm term11 = createTerm(glossary1, term1, "term11");
|
||||
GlossaryTerm term12 = createTerm(glossary1, term1, "term12");
|
||||
term1.setChildren(
|
||||
List.of(
|
||||
new GlossaryTermEntityInterface(term11).getEntityReference(),
|
||||
new GlossaryTermEntityInterface(term12).getEntityReference()));
|
||||
|
||||
// Create the following glossary
|
||||
// glossary2
|
||||
@ -126,43 +131,45 @@ public class GlossaryTermResourceTest extends EntityResourceTest<GlossaryTerm, C
|
||||
Glossary glossary2 = glossaryResourceTest.createEntity(createGlossary, ADMIN_AUTH_HEADERS);
|
||||
|
||||
GlossaryTerm term2 = createTerm(glossary2, null, "term2");
|
||||
createTerm(glossary2, term2, "term21");
|
||||
createTerm(glossary2, term2, "term22");
|
||||
GlossaryTerm term21 = createTerm(glossary2, term2, "term21");
|
||||
GlossaryTerm term22 = createTerm(glossary2, term2, "term22");
|
||||
term2.setChildren(
|
||||
List.of(
|
||||
new GlossaryTermEntityInterface(term21).getEntityReference(),
|
||||
new GlossaryTermEntityInterface(term22).getEntityReference()));
|
||||
|
||||
// List terms without any filters
|
||||
ResultList<GlossaryTerm> list = listEntities(null, ADMIN_AUTH_HEADERS);
|
||||
List<String> expectedTerms =
|
||||
Arrays.asList(
|
||||
GLOSSARY_TERM1.getName(),
|
||||
GLOSSARY_TERM2.getName(),
|
||||
"term1",
|
||||
"term11",
|
||||
"term12",
|
||||
"term2",
|
||||
"term21",
|
||||
"term22");
|
||||
assertContains(list, expectedTerms);
|
||||
Map<String, String> queryParams = new HashMap<>();
|
||||
queryParams.put("fields", "children,relatedTerms,reviewers,tags");
|
||||
ResultList<GlossaryTerm> list = listEntities(queryParams, ADMIN_AUTH_HEADERS);
|
||||
List<GlossaryTerm> expectedTerms =
|
||||
Arrays.asList(GLOSSARY_TERM1, GLOSSARY_TERM2, term1, term11, term12, term2, term21, term22);
|
||||
assertContains(expectedTerms, list.getData());
|
||||
|
||||
// List terms under glossary1
|
||||
Map<String, String> queryParams = new HashMap<>();
|
||||
queryParams = new HashMap<>();
|
||||
queryParams.put("fields", "children,relatedTerms,reviewers,tags");
|
||||
queryParams.put("glossary", glossary1.getId().toString());
|
||||
list = listEntities(queryParams, ADMIN_AUTH_HEADERS);
|
||||
assertContains(list, Arrays.asList("term1", "term11", "term12"));
|
||||
assertContains(Arrays.asList(term1, term11, term12), list.getData());
|
||||
|
||||
// List terms under glossary1 parent term1
|
||||
queryParams = new HashMap<>();
|
||||
queryParams.put("fields", "children,relatedTerms,reviewers,tags");
|
||||
queryParams.put("glossary", glossary1.getId().toString());
|
||||
queryParams.put("parent", term1.getId().toString());
|
||||
list = listEntities(queryParams, ADMIN_AUTH_HEADERS);
|
||||
assertContains(list, Arrays.asList("term11", "term12"));
|
||||
assertContains(Arrays.asList(term11, term12), list.getData());
|
||||
|
||||
// List terms under glossary2
|
||||
queryParams = new HashMap<>();
|
||||
queryParams.put("fields", "children,relatedTerms,reviewers,tags");
|
||||
queryParams.put("glossary", glossary2.getId().toString());
|
||||
list = listEntities(queryParams, ADMIN_AUTH_HEADERS);
|
||||
assertContains(list, Arrays.asList("term2", "term21", "term22"));
|
||||
assertContains(Arrays.asList(term2, term21, term22), list.getData());
|
||||
|
||||
// List terms under glossary 2 but give glossary term1 in glossary 1 as parent
|
||||
queryParams.put("fields", "children,relatedTerms,reviewers,tags");
|
||||
queryParams.put("parent", term1.getId().toString());
|
||||
Map<String, String> map = Collections.unmodifiableMap(queryParams);
|
||||
assertResponse(
|
||||
@ -179,9 +186,20 @@ public class GlossaryTermResourceTest extends EntityResourceTest<GlossaryTerm, C
|
||||
return createEntity(createGlossaryTerm, ADMIN_AUTH_HEADERS);
|
||||
}
|
||||
|
||||
public void assertContains(ResultList<GlossaryTerm> list, List<String> expectedTerm) {
|
||||
assertEquals(expectedTerm.size(), list.getData().size());
|
||||
list.getData().forEach(term -> assertTrue(expectedTerm.contains(term.getName())));
|
||||
public void assertContains(List<GlossaryTerm> expectedTerms, List<GlossaryTerm> actualTerms)
|
||||
throws HttpResponseException {
|
||||
assertEquals(expectedTerms.size(), actualTerms.size());
|
||||
for (GlossaryTerm expected : expectedTerms) {
|
||||
GlossaryTerm actual =
|
||||
actualTerms.stream().filter(a -> EntityUtil.glossaryTermMatch.test(a, expected)).findAny().orElse(null);
|
||||
assertNotNull(actual, "Expected glossaryTerm " + expected.getFullyQualifiedName() + " not found");
|
||||
assertEquals(expected.getFullyQualifiedName(), actual.getFullyQualifiedName());
|
||||
assertEquals(expected.getSynonyms(), actual.getSynonyms());
|
||||
assertEquals(expected.getParent(), actual.getParent());
|
||||
assertEntityReferenceList(expected.getChildren(), actual.getChildren());
|
||||
assertEntityReferenceList(expected.getReviewers(), actual.getReviewers());
|
||||
TestUtils.validateTags(expected.getTags(), actual.getTags());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user