Skip to content

Commit 2fa73cc

Browse files
committed
enhance logic
1 parent 75b9240 commit 2fa73cc

File tree

1 file changed

+43
-9
lines changed

1 file changed

+43
-9
lines changed

repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,29 +1927,63 @@ private void addRemovedProcessRelationshipToDiffEntity(AtlasEntity diffEntity, A
19271927
// Get vertices from the edge
19281928
AtlasVertex vertexA = removedEdge.getOutVertex();
19291929
AtlasVertex vertexB = removedEdge.getInVertex();
1930+
String edgeLabel = removedEdge.getLabel();
1931+
1932+
if (edgeLabel == null) {
1933+
LOG.warn("Cannot add removed process relationship: edgeLabel is null");
1934+
return;
1935+
}
1936+
1937+
// Determine which end the diffEntity corresponds to
1938+
// vertexA (OutVertex) corresponds to EndDef1, vertexB (InVertex) corresponds to EndDef2
1939+
AtlasRelationshipDef relationshipDef = typeRegistry.getRelationshipDefByLabel(edgeLabel);
1940+
if (relationshipDef == null) {
1941+
LOG.warn("Cannot add removed process relationship: relationshipDef not found for edgeLabel: {}", edgeLabel);
1942+
return;
1943+
}
1944+
19301945
AtlasVertex otherVertex;
1946+
AtlasVertex diffVertex;
1947+
String attributeName;
19311948
if (diffEntity.getGuid().equals(GraphHelper.getGuid(vertexA))) {
19321949
otherVertex = vertexB;
1950+
diffVertex = vertexA;
1951+
// diffEntity is EndDef1 (OutVertex)
1952+
attributeName = relationshipDef.getEndDef1().getName();
19331953
} else {
19341954
otherVertex = vertexA;
1955+
diffVertex = vertexB;
1956+
// diffEntity is EndDef2 (InVertex)
1957+
attributeName = relationshipDef.getEndDef2().getName();
19351958
}
19361959

19371960
if (otherVertex == null) {
1938-
LOG.warn("Cannot add removed process relationship: processVertex is null");
1961+
LOG.warn("Cannot add removed process relationship: otherVertex is null");
19391962
return;
19401963
}
19411964

1942-
1943-
String edgeLabel = removedEdge.getLabel();
1944-
1945-
if (edgeLabel == null) {
1946-
LOG.warn("Cannot add removed process relationship: edgeLabel is null");
1965+
if (diffVertex == null) {
1966+
LOG.warn("Cannot add removed process relationship: diffVertex is null");
19471967
return;
19481968
}
19491969

1950-
String attributeName = typeRegistry.getRelationshipDefByLabel(edgeLabel).getEndDef1().getName();
1951-
// Add to removedRelationshipAttributes
1952-
diffEntity.setRemovedRelationshipAttribute(attributeName, new AtlasObjectId(getGuid(otherVertex), getTypeName(otherVertex)));
1970+
1971+
1972+
AtlasEntityType entityType = typeRegistry.getEntityTypeByName(getTypeName(diffVertex));
1973+
AtlasAttribute relationshipAttribute = entityType != null ?
1974+
entityType.getRelationshipAttribute(attributeName, relationshipDef.getName()) : null;
1975+
1976+
TypeCategory typeCategory = relationshipAttribute != null && relationshipAttribute.getAttributeType() != null ?
1977+
relationshipAttribute.getAttributeType().getTypeCategory() : null;
1978+
1979+
AtlasObjectId objectId = new AtlasObjectId(getGuid(otherVertex), getTypeName(otherVertex));
1980+
1981+
// If attribute is an array type, pass as a list; otherwise pass as a single object
1982+
if (typeCategory == TypeCategory.ARRAY) {
1983+
diffEntity.setRemovedRelationshipAttribute(attributeName, Collections.singletonList(objectId));
1984+
} else {
1985+
diffEntity.setRemovedRelationshipAttribute(attributeName, objectId);
1986+
}
19531987
} catch (Exception e) {
19541988
LOG.warn("Failed to add removed process relationship to diff entity for notification: {}", e.getMessage(), e);
19551989
}

0 commit comments

Comments
 (0)