mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-10-27 16:55:06 +00:00
Fixes #7569 - Adding Reviewers at the root of the Glossary should be applied to all the children of Glossary (#8740)
This commit is contained in:
parent
11ad9192a4
commit
2edaec4155
@ -37,6 +37,7 @@ import org.openmetadata.service.exception.EntityNotFoundException;
|
||||
import org.openmetadata.service.jdbi3.EntityDAO;
|
||||
import org.openmetadata.service.jdbi3.EntityRepository;
|
||||
import org.openmetadata.service.util.EntityUtil;
|
||||
import org.openmetadata.service.util.EntityUtil.Fields;
|
||||
|
||||
@Slf4j
|
||||
public final class Entity {
|
||||
@ -216,6 +217,11 @@ public final class Entity {
|
||||
return !ACTIVITY_FEED_EXCLUDED_ENTITIES.contains(entityType);
|
||||
}
|
||||
|
||||
public static <T> Fields getFields(String entityType, String fields) throws IOException {
|
||||
EntityRepository<?> entityRepository = Entity.getEntityRepository(entityType);
|
||||
return entityRepository.getFields(fields);
|
||||
}
|
||||
|
||||
public static <T> T getEntity(EntityReference ref, EntityUtil.Fields fields, Include include) throws IOException {
|
||||
return getEntity(ref.getType(), ref.getId(), fields, include);
|
||||
}
|
||||
|
||||
@ -1103,6 +1103,9 @@ public abstract class EntityRepository<T extends EntityInterface> {
|
||||
}
|
||||
|
||||
public final Fields getFields(String fields) {
|
||||
if (fields != null && fields.equals("*")) {
|
||||
return new Fields(allowedFields, String.join(",", allowedFields));
|
||||
}
|
||||
return new Fields(allowedFields, fields);
|
||||
}
|
||||
|
||||
|
||||
@ -29,8 +29,10 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.openmetadata.schema.api.data.TermReference;
|
||||
import org.openmetadata.schema.entity.data.Glossary;
|
||||
import org.openmetadata.schema.entity.data.GlossaryTerm;
|
||||
import org.openmetadata.schema.type.EntityReference;
|
||||
import org.openmetadata.schema.type.Include;
|
||||
import org.openmetadata.schema.type.ProviderType;
|
||||
import org.openmetadata.schema.type.Relationship;
|
||||
import org.openmetadata.schema.type.TagLabel;
|
||||
@ -38,6 +40,7 @@ import org.openmetadata.schema.type.TagLabel.TagSource;
|
||||
import org.openmetadata.service.Entity;
|
||||
import org.openmetadata.service.exception.CatalogExceptionMessage;
|
||||
import org.openmetadata.service.jdbi3.CollectionDAO.EntityRelationshipRecord;
|
||||
import org.openmetadata.service.jdbi3.EntityRepository.EntityUpdater;
|
||||
import org.openmetadata.service.resources.glossary.GlossaryTermResource;
|
||||
import org.openmetadata.service.util.EntityUtil;
|
||||
import org.openmetadata.service.util.EntityUtil.Fields;
|
||||
@ -97,8 +100,14 @@ public class GlossaryTermRepository extends EntityRepository<GlossaryTerm> {
|
||||
@Override
|
||||
public void prepare(GlossaryTerm entity) throws IOException {
|
||||
// Validate glossary
|
||||
EntityReference glossary = Entity.getEntityReference(entity.getGlossary());
|
||||
entity.setGlossary(glossary);
|
||||
Fields glossaryFields = Entity.getFields(Entity.GLOSSARY, "reviewers");
|
||||
Glossary glossary = Entity.getEntity(entity.getGlossary(), glossaryFields, Include.NON_DELETED);
|
||||
entity.setGlossary(glossary.getEntityReference());
|
||||
|
||||
// If reviewers is not set in the glossary term, then carry it from the glossary
|
||||
System.out.println("XXX reviewers " + entity.getReviewers());
|
||||
System.out.println("XXX glossary reviewers " + glossary.getReviewers());
|
||||
entity.setReviewers(entity.getReviewers() == null ? glossary.getReviewers() : entity.getReviewers());
|
||||
|
||||
// Validate parent term
|
||||
EntityReference parentTerm = Entity.getEntityReference(entity.getParent());
|
||||
|
||||
@ -65,10 +65,7 @@ public abstract class EntityResource<T extends EntityInterface, K extends Entity
|
||||
}
|
||||
|
||||
public final Fields getFields(String fields) {
|
||||
if (fields != null && fields.equals("*")) {
|
||||
return new Fields(allowedFields, String.join(",", allowedFields));
|
||||
}
|
||||
return new Fields(allowedFields, fields);
|
||||
return dao.getFields(fields);
|
||||
}
|
||||
|
||||
public abstract T addHref(UriInfo uriInfo, T entity);
|
||||
|
||||
@ -94,7 +94,8 @@ public class GlossaryResourceTest extends EntityResourceTest<Glossary, CreateGlo
|
||||
.createRequest("g1t1", "", "", null)
|
||||
.withRelatedTerms(null)
|
||||
.withGlossary(GLOSSARY1_REF)
|
||||
.withTags(List.of(PII_SENSITIVE_TAG_LABEL, PERSONAL_DATA_TAG_LABEL));
|
||||
.withTags(List.of(PII_SENSITIVE_TAG_LABEL, PERSONAL_DATA_TAG_LABEL))
|
||||
.withReviewers(GLOSSARY1.getReviewers());
|
||||
GLOSSARY1_TERM1 = glossaryTermResourceTest.createAndCheckEntity(createGlossaryTerm, ADMIN_AUTH_HEADERS);
|
||||
GLOSSARY1_TERM1_REF = GLOSSARY1_TERM1.getEntityReference();
|
||||
GLOSSARY1_TERM1_LABEL = EntityUtil.getTagLabel(GLOSSARY1_TERM1);
|
||||
@ -104,7 +105,8 @@ public class GlossaryResourceTest extends EntityResourceTest<Glossary, CreateGlo
|
||||
glossaryTermResourceTest
|
||||
.createRequest("g2t1", "", "", null)
|
||||
.withRelatedTerms(List.of(GLOSSARY1_TERM1_REF))
|
||||
.withGlossary(GLOSSARY2_REF);
|
||||
.withGlossary(GLOSSARY2_REF)
|
||||
.withReviewers(GLOSSARY1.getReviewers());
|
||||
GLOSSARY2_TERM1 = glossaryTermResourceTest.createAndCheckEntity(createGlossaryTerm, ADMIN_AUTH_HEADERS);
|
||||
GLOSSARY2_TERM1_REF = GLOSSARY2_TERM1.getEntityReference();
|
||||
GLOSSARY2_TERM1_LABEL = EntityUtil.getTagLabel(GLOSSARY2_TERM1);
|
||||
@ -141,7 +143,7 @@ public class GlossaryResourceTest extends EntityResourceTest<Glossary, CreateGlo
|
||||
@Test
|
||||
void patch_renameSystemGlossary_400() throws IOException {
|
||||
// Renaming of system glossary and terms are not allowed
|
||||
CreateGlossary create = createRequest("renameGlossaryNotAllowed", "", "", null).withProvider(SYSTEM);
|
||||
CreateGlossary create = createRequest("renameGlossaryNotAllowed").withProvider(ProviderType.SYSTEM);
|
||||
Glossary glossary = createEntity(create, ADMIN_AUTH_HEADERS);
|
||||
|
||||
GlossaryTermResourceTest glossaryTermResourceTest = new GlossaryTermResourceTest();
|
||||
@ -163,7 +165,7 @@ public class GlossaryResourceTest extends EntityResourceTest<Glossary, CreateGlo
|
||||
// Create glossary with terms t1, t2
|
||||
// Create children terms t11, t12 under t1
|
||||
// Create children terms t21, t22 under t2
|
||||
CreateGlossary create = createRequest("renameGlossary", "", "", null);
|
||||
CreateGlossary create = createRequest("renameGlossary");
|
||||
Glossary glossary = createEntity(create, ADMIN_AUTH_HEADERS);
|
||||
|
||||
GlossaryTermResourceTest glossaryTermResourceTest = new GlossaryTermResourceTest();
|
||||
@ -203,7 +205,7 @@ public class GlossaryResourceTest extends EntityResourceTest<Glossary, CreateGlo
|
||||
|
||||
@Override
|
||||
public CreateGlossary createRequest(String name) {
|
||||
return new CreateGlossary().withName(name);
|
||||
return new CreateGlossary().withName(name).withDescription("d");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -157,6 +157,24 @@ public class GlossaryTermResourceTest extends EntityResourceTest<GlossaryTerm, C
|
||||
glossaryTermMismatch(term1.getId().toString(), glossary2.getId().toString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_inheritGlossaryReviewer(TestInfo test) throws IOException {
|
||||
//
|
||||
// When reviewers are not set for a glossary term, carry it forward from the glossary
|
||||
//
|
||||
GlossaryResourceTest glossaryTest = new GlossaryResourceTest();
|
||||
CreateGlossary create =
|
||||
glossaryTest.createRequest(getEntityName(test)).withReviewers(List.of(USER1_REF)).withDescription("d");
|
||||
Glossary glossary = glossaryTest.createEntity(create, ADMIN_AUTH_HEADERS);
|
||||
|
||||
// Create terms t1 and a term t12 under t1 in the glossary without reviewers
|
||||
GlossaryTerm t1 = createTerm(glossary, null, "t1", null);
|
||||
assertEquals(create.getReviewers(), t1.getReviewers()); // Reviewers are inherited
|
||||
|
||||
GlossaryTerm t12 = createTerm(glossary, t1, "t12", null);
|
||||
assertEquals(create.getReviewers(), t12.getReviewers()); // Reviewers are inherited
|
||||
}
|
||||
|
||||
@Test
|
||||
void patch_addDeleteReviewers(TestInfo test) throws IOException {
|
||||
CreateGlossaryTerm create = createRequest(getEntityName(test), "", "", null).withReviewers(null).withSynonyms(null);
|
||||
@ -309,10 +327,15 @@ public class GlossaryTermResourceTest extends EntityResourceTest<GlossaryTerm, C
|
||||
}
|
||||
|
||||
public GlossaryTerm createTerm(Glossary glossary, GlossaryTerm parent, String termName) throws IOException {
|
||||
return createTerm(glossary, parent, termName, glossary.getReviewers());
|
||||
}
|
||||
|
||||
public GlossaryTerm createTerm(
|
||||
Glossary glossary, GlossaryTerm parent, String termName, List<EntityReference> reviewers) throws IOException {
|
||||
EntityReference glossaryRef = glossary.getEntityReference();
|
||||
EntityReference parentRef = parent != null ? parent.getEntityReference() : null;
|
||||
CreateGlossaryTerm createGlossaryTerm =
|
||||
createRequest(termName, "", "", null).withGlossary(glossaryRef).withParent(parentRef);
|
||||
createRequest(termName, "", "", null).withGlossary(glossaryRef).withParent(parentRef).withReviewers(reviewers);
|
||||
return createAndCheckEntity(createGlossaryTerm, ADMIN_AUTH_HEADERS);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user