From 1afd68517f0884d0d80edaee513c9fb813257d81 Mon Sep 17 00:00:00 2001 From: ektavarma10 Date: Tue, 19 Dec 2023 11:21:15 +0530 Subject: [PATCH] Add check to restrict moving a term with multiple categories to another glossary --- .../preprocessor/glossary/TermPreProcessor.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/glossary/TermPreProcessor.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/glossary/TermPreProcessor.java index 53e12ea93e..387ad40031 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/glossary/TermPreProcessor.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/glossary/TermPreProcessor.java @@ -45,6 +45,7 @@ import org.springframework.stereotype.Component; import java.util.Iterator; import java.util.List; +import java.util.Objects; import static org.apache.atlas.repository.Constants.*; import static org.apache.atlas.repository.graph.GraphHelper.getActiveParentVertices; @@ -129,6 +130,8 @@ private void processUpdateTerm(AtlasEntity entity, AtlasVertex vertex) throws At //Auth check isAuthorized(currentGlossaryHeader, anchor); + ensureOnlyOneCategoryIsAssociated(entity); + String updatedTermQualifiedName = moveTermToAnotherGlossary(entity, vertex, currentGlossaryQualifiedName, newGlossaryQualifiedName, termQualifiedName); if (checkEntityTermAssociation(termQualifiedName)) { @@ -159,6 +162,19 @@ private void processUpdateTerm(AtlasEntity entity, AtlasVertex vertex) throws At RequestContext.get().endMetricRecord(metricRecorder); } + private static void ensureOnlyOneCategoryIsAssociated(AtlasEntity entity) throws AtlasBaseException { + if(entity.hasRelationshipAttribute(ATTR_CATEGORIES) && Objects.nonNull(entity.getRelationshipAttribute(ATTR_CATEGORIES))) { + List categories = (List) entity.getRelationshipAttribute(ATTR_CATEGORIES); + + if(categories.size() > 1) { + throw new AtlasBaseException(AtlasErrorCode.BAD_REQUEST, "Cannot move term with multiple " + + "categories associated to another glossary"); + } + + } + + } + private void validateCategory(AtlasEntity entity) throws AtlasBaseException { String glossaryQualifiedName = (String) anchor.getAttribute(QUALIFIED_NAME);