Skip to content

Commit

Permalink
Add check to restrict moving a term with multiple categories to anoth…
Browse files Browse the repository at this point in the history
…er glossary
  • Loading branch information
ektavarma10 committed Dec 19, 2023
1 parent 0f9fb53 commit 1afd685
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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<AtlasObjectId> categories = (List<AtlasObjectId>) 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);

Expand Down

0 comments on commit 1afd685

Please sign in to comment.