Commit f15995cc by apoorvnaik

ATLAS-2670: Validate entity guid when processing term dissociation

Change-Id: I5e2db1b9968a37482b9ff97ba8602aa262a2db80
parent f85ff28e
......@@ -142,7 +142,8 @@ public enum AtlasErrorCode {
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_CHILD_CATEGORY_DIFFERENT_GLOSSARY(400, "ATLAS-400-00-07F", "Invalid child category relationship: Child category (guid = {0}) belongs to different glossary"),
ATTRIBUTE_TYPE_INVALID(400, "ATLAS-400-00-080", "{0}.{1}: invalid attribute type. Attribute cannot be of type classification"),
INVALID_TERM_DISSOCIATION(400, "ATLAS-400-00-080", "Given term (guid={0}) is not associated to entity(guid={1})"),
ATTRIBUTE_TYPE_INVALID(400, "ATLAS-400-00-081", "{0}.{1}: invalid attribute type. Attribute cannot be of type classification"),
UNAUTHORIZED_ACCESS(403, "ATLAS-403-00-001", "{0} is not authorized to perform {1}"),
......
......@@ -100,6 +100,14 @@ public class GlossaryTermUtils extends GlossaryUtils {
}
Objects.requireNonNull(glossaryTerm);
Set<AtlasRelatedObjectId> assignedEntities = glossaryTerm.getAssignedEntities();
Map<String, AtlasRelatedObjectId> assignedEntityMap = new HashMap<>();
if (CollectionUtils.isNotEmpty(assignedEntities)) {
for (AtlasRelatedObjectId relatedObjectId : assignedEntities) {
assignedEntityMap.put(relatedObjectId.getGuid(), relatedObjectId);
}
}
if (CollectionUtils.isNotEmpty(relatedObjectIds)) {
for (AtlasRelatedObjectId relatedObjectId : relatedObjectIds) {
if (DEBUG_ENABLED) {
......@@ -108,7 +116,12 @@ public class GlossaryTermUtils extends GlossaryUtils {
if (Objects.isNull(relatedObjectId.getRelationshipGuid())) {
throw new AtlasBaseException(AtlasErrorCode.TERM_DISSOCIATION_MISSING_RELATION_GUID);
}
AtlasRelatedObjectId existingTermRelation = assignedEntityMap.get(relatedObjectId.getGuid());
if (CollectionUtils.isNotEmpty(assignedEntities) && isRelationshipGuidSame(existingTermRelation, relatedObjectId)) {
relationshipStore.deleteById(relatedObjectId.getRelationshipGuid());
} else {
throw new AtlasBaseException(AtlasErrorCode.INVALID_TERM_DISSOCIATION, glossaryTerm.getGuid(), relatedObjectId.getGuid());
}
}
}
......@@ -117,6 +130,10 @@ public class GlossaryTermUtils extends GlossaryUtils {
}
}
private boolean isRelationshipGuidSame(final AtlasRelatedObjectId existing, final AtlasRelatedObjectId relatedObjectId) {
return StringUtils.equals(relatedObjectId.getRelationshipGuid(), existing.getRelationshipGuid());
}
private void processTermAnchor(AtlasGlossaryTerm updatedTerm, AtlasGlossaryTerm existing, RelationshipOperation op) throws AtlasBaseException {
AtlasGlossaryHeader existingAnchor = existing.getAnchor();
AtlasGlossaryHeader updatedTermAnchor = updatedTerm.getAnchor();
......
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