Fix #8083: Adding a child term to a parent term in glossary produces error (#9088)

* Fix #8083: Adding a child term to a parent term in glossary produces error

* checkstyle fix

Co-authored-by: mohitdeuex <mohit.y@deuexsolutions.com>
Co-authored-by: Mohit Yadav <105265192+mohityadav766@users.noreply.github.com>
This commit is contained in:
Sriharsha Chintalapani 2022-12-01 01:18:55 -08:00 committed by GitHub
parent 00375341f7
commit 0050243479
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions

View File

@ -102,6 +102,10 @@ public class GlossaryTermRepository extends EntityRepository<GlossaryTerm> {
@Override
public void prepare(GlossaryTerm entity) throws IOException {
// Validate parent term
EntityReference parentTerm = Entity.getEntityReference(entity.getParent());
entity.setParent(parentTerm);
validateHierarchy(entity);
// Validate glossary
@ -111,10 +115,6 @@ public class GlossaryTermRepository extends EntityRepository<GlossaryTerm> {
// If reviewers is not set in the glossary term, then carry it from the glossary
entity.setReviewers(entity.getReviewers() == null ? glossary.getReviewers() : entity.getReviewers());
// Validate parent term
EntityReference parentTerm = Entity.getEntityReference(entity.getParent());
entity.setParent(parentTerm);
// Validate related terms
EntityUtil.populateEntityReferences(entity.getRelatedTerms());

View File

@ -32,7 +32,6 @@ import static org.openmetadata.service.resources.databases.TableResourceTest.get
import static org.openmetadata.service.util.EntityUtil.fieldAdded;
import static org.openmetadata.service.util.EntityUtil.fieldDeleted;
import static org.openmetadata.service.util.EntityUtil.fieldUpdated;
import static org.openmetadata.service.util.EntityUtil.getEntityReference;
import static org.openmetadata.service.util.EntityUtil.getId;
import static org.openmetadata.service.util.EntityUtil.toTagLabels;
import static org.openmetadata.service.util.TestUtils.ADMIN_AUTH_HEADERS;
@ -366,7 +365,11 @@ public class GlossaryTermResourceTest extends EntityResourceTest<GlossaryTerm, C
public GlossaryTerm createTerm(
Glossary glossary, GlossaryTerm parent, String termName, List<EntityReference> reviewers) throws IOException {
EntityReference glossaryRef = glossary.getEntityReference();
EntityReference parentRef = getEntityReference(parent);
// sending required fields only for entity reference
EntityReference parentRef = null;
if (parent != null) {
parentRef = new EntityReference().withId(parent.getId()).withType(GLOSSARY_TERM);
}
CreateGlossaryTerm createGlossaryTerm =
createRequest(termName, "", "", null).withGlossary(glossaryRef).withParent(parentRef).withReviewers(reviewers);
return createAndCheckEntity(createGlossaryTerm, ADMIN_AUTH_HEADERS);