This is an automated email from the ASF dual-hosted git repository.

mandarambawane pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/atlas.git


The following commit(s) were added to refs/heads/master by this push:
     new a410f40ec ATLAS-4848: Atlas 'updateTime' parameter is not updated when 
term is added (#348)
a410f40ec is described below

commit a410f40ecd070317b0cabe4bcbfb282c6df44a66
Author: sheetalshah1007 <sheetal.s...@freestoneinfotech.com>
AuthorDate: Thu May 15 15:21:15 2025 +0530

    ATLAS-4848: Atlas 'updateTime' parameter is not updated when term is added 
(#348)
    
    Co-authored-by: Sheetal Shah <sheetal.s...@cloudera.com>
---
 .../apache/atlas/glossary/GlossaryTermUtils.java   |  5 +++
 .../apache/atlas/glossary/GlossaryServiceTest.java | 40 ++++++++++++++++++++--
 2 files changed, 43 insertions(+), 2 deletions(-)

diff --git 
a/repository/src/main/java/org/apache/atlas/glossary/GlossaryTermUtils.java 
b/repository/src/main/java/org/apache/atlas/glossary/GlossaryTermUtils.java
index 601d4ac1e..a3e1f335c 100644
--- a/repository/src/main/java/org/apache/atlas/glossary/GlossaryTermUtils.java
+++ b/repository/src/main/java/org/apache/atlas/glossary/GlossaryTermUtils.java
@@ -61,6 +61,7 @@ import static java.util.Objects.isNull;
 import static java.util.Objects.nonNull;
 import static java.util.Objects.requireNonNull;
 import static 
org.apache.atlas.bulkimport.BulkImportResponse.ImportStatus.FAILED;
+import static 
org.apache.atlas.repository.graph.GraphHelper.updateModificationMetadata;
 
 public class GlossaryTermUtils extends GlossaryUtils {
     private static final Logger LOG = 
LoggerFactory.getLogger(GlossaryTermUtils.class);
@@ -131,6 +132,8 @@ public class GlossaryTermUtils extends GlossaryUtils {
             LOG.debug("Assigning term guid={}, to entity guid = {}", 
glossaryTerm.getGuid(), objectId.getGuid());
 
             createRelationship(defineTermAssignment(glossaryTerm.getGuid(), 
objectId));
+            AtlasVertex vertex = 
AtlasGraphUtilsV2.findByGuid(objectId.getGuid());
+            updateModificationMetadata(vertex);
         }
 
         LOG.debug("<== GlossaryTermUtils.processTermAssignments()");
@@ -162,6 +165,8 @@ public class GlossaryTermUtils extends GlossaryUtils {
 
                 if (CollectionUtils.isNotEmpty(assignedEntities) && 
isRelationshipGuidSame(existingTermRelation, relatedObjectId)) {
                     
relationshipStore.deleteById(relatedObjectId.getRelationshipGuid(), true);
+                    AtlasVertex vertex = 
AtlasGraphUtilsV2.findByGuid(relatedObjectId.getGuid());
+                    updateModificationMetadata(vertex);
                 } else {
                     throw new 
AtlasBaseException(AtlasErrorCode.INVALID_TERM_DISSOCIATION, 
relatedObjectId.getRelationshipGuid(), glossaryTerm.getGuid(), 
relatedObjectId.getGuid());
                 }
diff --git 
a/repository/src/test/java/org/apache/atlas/glossary/GlossaryServiceTest.java 
b/repository/src/test/java/org/apache/atlas/glossary/GlossaryServiceTest.java
index fd92a60be..20880dc3d 100644
--- 
a/repository/src/test/java/org/apache/atlas/glossary/GlossaryServiceTest.java
+++ 
b/repository/src/test/java/org/apache/atlas/glossary/GlossaryServiceTest.java
@@ -18,6 +18,7 @@
 package org.apache.atlas.glossary;
 
 import org.apache.atlas.AtlasErrorCode;
+import org.apache.atlas.RequestContext;
 import org.apache.atlas.SortOrder;
 import org.apache.atlas.TestModules;
 import org.apache.atlas.bulkimport.BulkImportResponse;
@@ -1035,6 +1036,8 @@ public class GlossaryServiceTest {
         assetEntity.setAttribute("qualifiedName", "testAsset");
         assetEntity.setAttribute("name", "testAsset");
 
+        long originalUpdateTime         = 0L;
+        long updatedTimeAfterAssignment = 0L;
         try {
             EntityMutationResponse response           = 
entityStore.createOrUpdate(new AtlasEntityStream(assetEntity), false);
             AtlasEntityHeader      firstEntityCreated = 
response.getFirstEntityCreated();
@@ -1045,12 +1048,31 @@ public class GlossaryServiceTest {
             relatedObjectId.setTypeName(firstEntityCreated.getTypeName());
 
             assertNotNull(relatedObjectId);
+            AtlasEntity.AtlasEntityWithExtInfo entityInfo    = 
entityStore.getById(relatedObjectId.getGuid());
+            AtlasEntity                        createdEntity = 
entityInfo.getEntity();
+            assertNotNull(createdEntity);
+            originalUpdateTime = createdEntity.getUpdateTime().getTime();
         } catch (AtlasBaseException e) {
             fail("Entity creation should've succeeded", e);
         }
 
+        long mockRequestTimeAssign = System.currentTimeMillis() + 5000;  // 
simulate later timestamp
         try {
-            glossaryService.assignTermToEntities(fixedRateMortgage.getGuid(), 
Collections.singletonList(relatedObjectId));
+            try (MockedStatic<RequestContext> mockedRequestContext = 
Mockito.mockStatic(RequestContext.class)) {
+                RequestContext mockContext = mock(RequestContext.class);
+                
when(mockContext.getRequestTime()).thenReturn(mockRequestTimeAssign);
+                
mockedRequestContext.when(RequestContext::get).thenReturn(mockContext);
+
+                
glossaryService.assignTermToEntities(fixedRateMortgage.getGuid(), 
Collections.singletonList(relatedObjectId));
+
+                //verify updateTime after assignment
+                AtlasEntity.AtlasEntityWithExtInfo updatedInfo                 
 = entityStore.getById(relatedObjectId.getGuid());
+                AtlasEntity                        
updatedEntityAfterAssignment = updatedInfo.getEntity();
+                updatedTimeAfterAssignment = 
updatedEntityAfterAssignment.getUpdateTime().getTime();
+
+                assertEquals(updatedTimeAfterAssignment, 
mockRequestTimeAssign);
+                assertTrue(updatedTimeAfterAssignment > originalUpdateTime, 
"updateTime should have increased after term assignment");
+            }
         } catch (AtlasBaseException e) {
             fail("Term assignment to asset should've succeeded", e);
         }
@@ -1072,8 +1094,22 @@ public class GlossaryServiceTest {
 
         // Dissociate term from entities
         try {
-            
glossaryService.removeTermFromEntities(fixedRateMortgage.getGuid(), 
Collections.singletonList(relatedObjectId));
+            long mockRequestTimeRemove = mockRequestTimeAssign + 5000;
+            try (MockedStatic<RequestContext> mockedRequestContext = 
Mockito.mockStatic(RequestContext.class)) {
+                RequestContext mockContext = mock(RequestContext.class);
+                
when(mockContext.getRequestTime()).thenReturn(mockRequestTimeRemove);
+                
mockedRequestContext.when(RequestContext::get).thenReturn(mockContext);
+
+                
glossaryService.removeTermFromEntities(fixedRateMortgage.getGuid(), 
Collections.singletonList(relatedObjectId));
 
+                //verify updateTime after dissociation
+                AtlasEntity.AtlasEntityWithExtInfo updatedInfo                 
   = entityStore.getById(relatedObjectId.getGuid());
+                AtlasEntity                        
updatedEntityAfterDissociation = updatedInfo.getEntity();
+                long                               
updatedTimeAfterDissociation   = 
updatedEntityAfterDissociation.getUpdateTime().getTime();
+
+                assertEquals(updatedTimeAfterDissociation, 
mockRequestTimeRemove);
+                assertTrue(updatedTimeAfterDissociation > 
updatedTimeAfterAssignment, "updateTime should have increased after term 
dissociation");
+            }
             AtlasGlossaryTerm term = 
glossaryService.getTerm(fixedRateMortgage.getGuid());
 
             assertNotNull(term);

Reply via email to