Skip to content

Commit

Permalink
Add check to restrict moving a category with terms linked to multiple…
Browse files Browse the repository at this point in the history
… categories
  • Loading branch information
ektavarma10 committed Dec 20, 2023
1 parent 145ec39 commit 6b3a97b
Showing 1 changed file with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;

import static org.apache.atlas.AtlasErrorCode.BAD_REQUEST;
Expand Down Expand Up @@ -127,8 +121,8 @@ private void processCreateCategory(AtlasEntity entity, AtlasVertex vertex) throw
validateParent(glossaryQualifiedName);

entity.setAttribute(QUALIFIED_NAME, createQualifiedName(vertex));
AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_CREATE, new AtlasEntityHeader(entity)),
"create entity: type=", entity.getTypeName());
// AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, AtlasPrivilege.ENTITY_CREATE, new AtlasEntityHeader(entity)),
// "create entity: type=", entity.getTypeName());

validateChildren(entity, null);

Expand Down Expand Up @@ -309,6 +303,19 @@ public void moveChildTermToAnotherGlossary(AtlasVertex termVertex,
}
}

private 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 validateParentForGlossaryChange(AtlasEntity category,
AtlasVertex categoryVertex,
String targetGlossaryQualifiedName) throws AtlasBaseException {
Expand Down

0 comments on commit 6b3a97b

Please sign in to comment.