3737import org .apache .atlas .model .tasks .TaskSearchResult ;
3838import org .apache .atlas .model .typedef .AtlasRelationshipDef ;
3939import org .apache .atlas .model .typedef .AtlasRelationshipDef .PropagateTags ;
40+ import org .apache .atlas .model .typedef .AtlasRelationshipEndDef ;
4041import org .apache .atlas .model .typedef .AtlasStructDef .AtlasAttributeDef ;
4142import org .apache .atlas .repository .graph .GraphHelper ;
4243import org .apache .atlas .repository .graphdb .AtlasEdge ;
@@ -1728,6 +1729,8 @@ public void resetHasLineageOnInputOutputDelete(Collection<AtlasEdge> removedEdge
17281729 AtlasGraphUtilsV2 .setEncodedProperty (processVertex , HAS_LINEAGE , false );
17291730 AtlasEntity diffEntity = getOrInitializeDiffEntity (processVertex );
17301731 diffEntity .setAttribute (HAS_LINEAGE , false );
1732+ // Add removed relationship attribute for notification
1733+ addRemovedProcessRelationshipToDiffEntity (diffEntity , atlasEdge , removedEdges );
17311734
17321735 String oppositeEdgeLabel = isOutputEdge ? PROCESS_INPUTS : PROCESS_OUTPUTS ;
17331736
@@ -1845,7 +1848,6 @@ private void updateAssetHasLineageStatus(AtlasVertex assetVertex, AtlasEdge curr
18451848 }
18461849 private void updateAssetHasLineageStatusV1 (AtlasVertex assetVertex , AtlasEdge currentEdge , Collection <AtlasEdge > removedEdges ) {
18471850 AtlasPerfMetrics .MetricRecorder metricRecorder = RequestContext .get ().startMetricRecord ("updateAssetHasLineageStatusV1" );
1848-
18491851 removedEdges .forEach (edge -> RequestContext .get ().addToDeletedEdgesIdsForResetHasLineage (edge .getIdForDisplay ()));
18501852
18511853 Iterator <AtlasEdge > edgeIterator = assetVertex .query ()
@@ -1873,6 +1875,8 @@ private void updateAssetHasLineageStatusV1(AtlasVertex assetVertex, AtlasEdge cu
18731875 AtlasGraphUtilsV2 .setEncodedProperty (assetVertex , HAS_LINEAGE , false );
18741876 AtlasEntity diffEntity = getOrInitializeDiffEntity (assetVertex );
18751877 diffEntity .setAttribute (HAS_LINEAGE , false );
1878+ // Add removed relationship attribute for notification
1879+ addRemovedProcessRelationshipToDiffEntity (diffEntity , currentEdge , removedEdges );
18761880 }
18771881
18781882 RequestContext .get ().endMetricRecord (metricRecorder );
@@ -1890,6 +1894,67 @@ private AtlasEntity getOrInitializeDiffEntity(AtlasVertex vertex) {
18901894 return diffEntity ;
18911895 }
18921896
1897+ /**
1898+ * Helper method to add removed process relationship to diff entity's removedRelationshipAttributes
1899+ * when hasLineage changes to false
1900+ */
1901+ private void addRemovedProcessRelationshipToDiffEntity (AtlasEntity diffEntity , AtlasEdge removedEdge , Collection <AtlasEdge > removedEdgesList ) {
1902+ try {
1903+ // Null checks for input parameters
1904+ if (diffEntity == null ) {
1905+ LOG .warn ("Cannot add removed process relationship: diffEntity is null" );
1906+ return ;
1907+ }
1908+
1909+ if (removedEdge == null ) {
1910+ LOG .warn ("Cannot add removed process relationship: currentEdge is null" );
1911+ return ;
1912+ }
1913+
1914+
1915+ String edgeIdForDisplay = removedEdge .getIdForDisplay ();
1916+ boolean isEdgeInDeletedList = false ;
1917+ if (edgeIdForDisplay != null && RequestContext .get () != null ) {
1918+ isEdgeInDeletedList = RequestContext .get ().getDeletedEdgesIdsForResetHasLineage ().contains (edgeIdForDisplay );
1919+ }
1920+
1921+ Set <AtlasEdge > removedEdges = new HashSet <>(removedEdgesList );
1922+ if (!isEdgeInDeletedList && !removedEdges .contains (removedEdge )) {
1923+ // Edge is not deleted and not in the deleted list, skip processing
1924+ return ;
1925+ }
1926+
1927+ // Get vertices from the edge
1928+ AtlasVertex vertexA = removedEdge .getOutVertex ();
1929+ AtlasVertex vertexB = removedEdge .getInVertex ();
1930+ AtlasVertex otherVertex ;
1931+ if (diffEntity .getGuid ().equals (GraphHelper .getGuid (vertexA ))) {
1932+ otherVertex = vertexB ;
1933+ } else {
1934+ otherVertex = vertexA ;
1935+ }
1936+
1937+ if (otherVertex == null ) {
1938+ LOG .warn ("Cannot add removed process relationship: processVertex is null" );
1939+ return ;
1940+ }
1941+
1942+
1943+ String edgeLabel = removedEdge .getLabel ();
1944+
1945+ if (edgeLabel == null ) {
1946+ LOG .warn ("Cannot add removed process relationship: edgeLabel is null" );
1947+ return ;
1948+ }
1949+
1950+ String attributeName = typeRegistry .getRelationshipDefByLabel (edgeLabel ).getEndDef1 ().getName ();
1951+ // Add to removedRelationshipAttributes
1952+ diffEntity .setRemovedRelationshipAttribute (attributeName , new AtlasObjectId (getGuid (otherVertex ), getTypeName (otherVertex )));
1953+ } catch (Exception e ) {
1954+ LOG .warn ("Failed to add removed process relationship to diff entity for notification: {}" , e .getMessage (), e );
1955+ }
1956+ }
1957+
18931958 private void updateAssetHasLineageStatusV2 (AtlasVertex assetVertex , AtlasEdge currentEdge , Collection <AtlasEdge > removedEdges ) {
18941959 AtlasPerfMetrics .MetricRecorder metricRecorder = RequestContext .get ().startMetricRecord ("updateAssetHasLineageStatusV2" );
18951960
@@ -1909,6 +1974,8 @@ private void updateAssetHasLineageStatusV2(AtlasVertex assetVertex, AtlasEdge cu
19091974 AtlasGraphUtilsV2 .setEncodedProperty (assetVertex , HAS_LINEAGE , false );
19101975 AtlasEntity diffEntity = getOrInitializeDiffEntity (assetVertex );
19111976 diffEntity .setAttribute (HAS_LINEAGE , false );
1977+ // Add removed relationship attribute for notification
1978+ addRemovedProcessRelationshipToDiffEntity (diffEntity , currentEdge , removedEdges );
19121979 }
19131980
19141981 RequestContext .get ().endMetricRecord (metricRecorder );
0 commit comments