Commit 9e3af41b by apoorvnaik

ATLAS-2655: Restrict child category to be within the same glossary

Change-Id: I1356f2f37c99445fd96ab07da3f615a5e1e46dea
parent 3f9fc5c9
...@@ -141,7 +141,7 @@ public enum AtlasErrorCode { ...@@ -141,7 +141,7 @@ public enum AtlasErrorCode {
GLOSSARY_CATEGORY_QUALIFIED_NAME_CANT_BE_DERIVED(400, "ATLAS-400-00-07B", "Attributes qualifiedName, displayName & glossary name are missing. Failed to derive a unique name for Glossary category"), GLOSSARY_CATEGORY_QUALIFIED_NAME_CANT_BE_DERIVED(400, "ATLAS-400-00-07B", "Attributes qualifiedName, displayName & glossary name are missing. Failed to derive a unique name for Glossary category"),
RELATIONSHIP_END_IS_NULL(400, "ATLAS-400-00-07D", "Relationship end is invalid. Expected {0} but is NULL"), RELATIONSHIP_END_IS_NULL(400, "ATLAS-400-00-07D", "Relationship end is invalid. Expected {0} but is NULL"),
INVALID_TERM_RELATION_TO_SELF(400, "ATLAS-400-00-07E", "Invalid Term relationship: Term can't have a relationship with self"), INVALID_TERM_RELATION_TO_SELF(400, "ATLAS-400-00-07E", "Invalid Term relationship: Term can't have a relationship with self"),
INVALID_CHILD_CATEGORY_DIFFERENT_GLOSSARY(400, "ATLAS-400-00-07F", "Invalid child category relationship: Child category belongs to different glossary"), INVALID_CHILD_CATEGORY_DIFFERENT_GLOSSARY(400, "ATLAS-400-00-07F", "Invalid child category relationship: Child category (guid = {0}) belongs to different glossary"),
UNAUTHORIZED_ACCESS(403, "ATLAS-403-00-001", "{0} is not authorized to perform {1}"), UNAUTHORIZED_ACCESS(403, "ATLAS-403-00-001", "{0} is not authorized to perform {1}"),
......
...@@ -25,6 +25,7 @@ import org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader; ...@@ -25,6 +25,7 @@ import org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader;
import org.apache.atlas.model.instance.AtlasObjectId; import org.apache.atlas.model.instance.AtlasObjectId;
import org.apache.atlas.model.instance.AtlasRelationship; import org.apache.atlas.model.instance.AtlasRelationship;
import org.apache.atlas.model.instance.AtlasStruct; import org.apache.atlas.model.instance.AtlasStruct;
import org.apache.atlas.repository.ogm.DataAccess;
import org.apache.atlas.repository.store.graph.AtlasRelationshipStore; import org.apache.atlas.repository.store.graph.AtlasRelationshipStore;
import org.apache.atlas.type.AtlasRelationshipType; import org.apache.atlas.type.AtlasRelationshipType;
import org.apache.atlas.type.AtlasTypeRegistry; import org.apache.atlas.type.AtlasTypeRegistry;
...@@ -46,8 +47,8 @@ public class GlossaryCategoryUtils extends GlossaryUtils { ...@@ -46,8 +47,8 @@ public class GlossaryCategoryUtils extends GlossaryUtils {
private static final Logger LOG = LoggerFactory.getLogger(GlossaryCategoryUtils.class); private static final Logger LOG = LoggerFactory.getLogger(GlossaryCategoryUtils.class);
private static final boolean DEBUG_ENABLED = LOG.isDebugEnabled(); private static final boolean DEBUG_ENABLED = LOG.isDebugEnabled();
protected GlossaryCategoryUtils(AtlasRelationshipStore relationshipStore, AtlasTypeRegistry typeRegistry) { protected GlossaryCategoryUtils(AtlasRelationshipStore relationshipStore, AtlasTypeRegistry typeRegistry, DataAccess dataAccess) {
super(relationshipStore, typeRegistry); super(relationshipStore, typeRegistry, dataAccess);
} }
public void processCategoryRelations(AtlasGlossaryCategory updatedCategory, AtlasGlossaryCategory existing, RelationshipOperation op) throws AtlasBaseException { public void processCategoryRelations(AtlasGlossaryCategory updatedCategory, AtlasGlossaryCategory existing, RelationshipOperation op) throws AtlasBaseException {
...@@ -347,9 +348,7 @@ public class GlossaryCategoryUtils extends GlossaryUtils { ...@@ -347,9 +348,7 @@ public class GlossaryCategoryUtils extends GlossaryUtils {
Map<String, AtlasRelatedCategoryHeader> map = new HashMap<>(); Map<String, AtlasRelatedCategoryHeader> map = new HashMap<>();
for (AtlasRelatedCategoryHeader c : category.getChildrenCategories()) { for (AtlasRelatedCategoryHeader c : category.getChildrenCategories()) {
AtlasRelatedCategoryHeader header = map.get(c.getCategoryGuid()); AtlasRelatedCategoryHeader header = map.get(c.getCategoryGuid());
if (header == null) { if (header == null || (StringUtils.isEmpty(header.getRelationGuid()) && StringUtils.isNotEmpty(c.getRelationGuid()))) {
map.put(c.getCategoryGuid(), c);
} else if (StringUtils.isEmpty(header.getRelationGuid()) && StringUtils.isNotEmpty(c.getRelationGuid())) {
map.put(c.getCategoryGuid(), c); map.put(c.getCategoryGuid(), c);
} }
} }
...@@ -368,10 +367,24 @@ public class GlossaryCategoryUtils extends GlossaryUtils { ...@@ -368,10 +367,24 @@ public class GlossaryCategoryUtils extends GlossaryUtils {
} }
continue; continue;
} }
if (DEBUG_ENABLED) { if (DEBUG_ENABLED) {
LOG.debug("Creating new child, category = {}, child = {}", existing.getDisplayName(), child.getDisplayText()); LOG.debug("Loading the child category to perform glossary check");
}
AtlasGlossaryCategory childCategory = new AtlasGlossaryCategory();
childCategory.setGuid(child.getCategoryGuid());
childCategory = dataAccess.load(childCategory);
if (StringUtils.equals(existing.getAnchor().getGlossaryGuid(), childCategory.getAnchor().getGlossaryGuid())) {
if (DEBUG_ENABLED) {
LOG.debug("Creating new child, category = {}, child = {}", existing.getDisplayName(), child.getDisplayText());
}
createRelationship(defineCategoryHierarchyLink(existing.getGuid(), child));
} else {
throw new AtlasBaseException(AtlasErrorCode.INVALID_CHILD_CATEGORY_DIFFERENT_GLOSSARY, child.getCategoryGuid());
} }
createRelationship(defineCategoryHierarchyLink(existing.getGuid(), child));
} }
} }
} }
......
...@@ -66,8 +66,8 @@ public class GlossaryService { ...@@ -66,8 +66,8 @@ public class GlossaryService {
public GlossaryService(DataAccess dataAccess, final AtlasRelationshipStore relationshipStore, final AtlasTypeRegistry typeRegistry) { public GlossaryService(DataAccess dataAccess, final AtlasRelationshipStore relationshipStore, final AtlasTypeRegistry typeRegistry) {
this.dataAccess = dataAccess; this.dataAccess = dataAccess;
this.atlasTypeRegistry = typeRegistry; this.atlasTypeRegistry = typeRegistry;
glossaryTermUtils = new GlossaryTermUtils(relationshipStore, typeRegistry); glossaryTermUtils = new GlossaryTermUtils(relationshipStore, typeRegistry, dataAccess);
glossaryCategoryUtils = new GlossaryCategoryUtils(relationshipStore, typeRegistry); glossaryCategoryUtils = new GlossaryCategoryUtils(relationshipStore, typeRegistry, dataAccess);
} }
/** /**
......
...@@ -27,6 +27,7 @@ import org.apache.atlas.model.instance.AtlasObjectId; ...@@ -27,6 +27,7 @@ import org.apache.atlas.model.instance.AtlasObjectId;
import org.apache.atlas.model.instance.AtlasRelatedObjectId; import org.apache.atlas.model.instance.AtlasRelatedObjectId;
import org.apache.atlas.model.instance.AtlasRelationship; import org.apache.atlas.model.instance.AtlasRelationship;
import org.apache.atlas.model.instance.AtlasStruct; import org.apache.atlas.model.instance.AtlasStruct;
import org.apache.atlas.repository.ogm.DataAccess;
import org.apache.atlas.repository.store.graph.AtlasRelationshipStore; import org.apache.atlas.repository.store.graph.AtlasRelationshipStore;
import org.apache.atlas.type.AtlasRelationshipType; import org.apache.atlas.type.AtlasRelationshipType;
import org.apache.atlas.type.AtlasTypeRegistry; import org.apache.atlas.type.AtlasTypeRegistry;
...@@ -46,8 +47,8 @@ public class GlossaryTermUtils extends GlossaryUtils { ...@@ -46,8 +47,8 @@ public class GlossaryTermUtils extends GlossaryUtils {
private static final Logger LOG = LoggerFactory.getLogger(GlossaryTermUtils.class); private static final Logger LOG = LoggerFactory.getLogger(GlossaryTermUtils.class);
private static final boolean DEBUG_ENABLED = LOG.isDebugEnabled(); private static final boolean DEBUG_ENABLED = LOG.isDebugEnabled();
protected GlossaryTermUtils(AtlasRelationshipStore relationshipStore, AtlasTypeRegistry typeRegistry) { protected GlossaryTermUtils(AtlasRelationshipStore relationshipStore, AtlasTypeRegistry typeRegistry, DataAccess dataAccess) {
super(relationshipStore, typeRegistry); super(relationshipStore, typeRegistry, dataAccess);
} }
public void processTermRelations(AtlasGlossaryTerm updatedTerm, AtlasGlossaryTerm existing, RelationshipOperation op) throws AtlasBaseException { public void processTermRelations(AtlasGlossaryTerm updatedTerm, AtlasGlossaryTerm existing, RelationshipOperation op) throws AtlasBaseException {
......
...@@ -21,6 +21,7 @@ import org.apache.atlas.AtlasErrorCode; ...@@ -21,6 +21,7 @@ import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader; import org.apache.atlas.model.glossary.relations.AtlasRelatedTermHeader;
import org.apache.atlas.model.instance.AtlasRelationship; import org.apache.atlas.model.instance.AtlasRelationship;
import org.apache.atlas.repository.ogm.DataAccess;
import org.apache.atlas.repository.store.graph.AtlasRelationshipStore; import org.apache.atlas.repository.store.graph.AtlasRelationshipStore;
import org.apache.atlas.type.AtlasTypeRegistry; import org.apache.atlas.type.AtlasTypeRegistry;
...@@ -54,11 +55,13 @@ public abstract class GlossaryUtils { ...@@ -54,11 +55,13 @@ public abstract class GlossaryUtils {
protected static final String TERM_RELATION_ATTR_STATUS = "status"; protected static final String TERM_RELATION_ATTR_STATUS = "status";
protected final AtlasRelationshipStore relationshipStore; protected final AtlasRelationshipStore relationshipStore;
protected final AtlasTypeRegistry typeRegistry; protected final AtlasTypeRegistry typeRegistry;
protected final DataAccess dataAccess;
protected GlossaryUtils(final AtlasRelationshipStore relationshipStore, final AtlasTypeRegistry typeRegistry) { protected GlossaryUtils(final AtlasRelationshipStore relationshipStore, final AtlasTypeRegistry typeRegistry, final DataAccess dataAccess) {
this.relationshipStore = relationshipStore; this.relationshipStore = relationshipStore;
this.typeRegistry = typeRegistry; this.typeRegistry = typeRegistry;
this.dataAccess = dataAccess;
} }
protected void createRelationship(AtlasRelationship relationship) throws AtlasBaseException { protected void createRelationship(AtlasRelationship relationship) throws AtlasBaseException {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment