Skip to content

Commit a410f40

Browse files
sheetalshah1007Sheetal Shah
andauthored
ATLAS-4848: Atlas 'updateTime' parameter is not updated when term is added (#348)
Co-authored-by: Sheetal Shah <sheetal.shah@cloudera.com>
1 parent 79cac30 commit a410f40

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

repository/src/main/java/org/apache/atlas/glossary/GlossaryTermUtils.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import static java.util.Objects.nonNull;
6262
import static java.util.Objects.requireNonNull;
6363
import static org.apache.atlas.bulkimport.BulkImportResponse.ImportStatus.FAILED;
64+
import static org.apache.atlas.repository.graph.GraphHelper.updateModificationMetadata;
6465

6566
public class GlossaryTermUtils extends GlossaryUtils {
6667
private static final Logger LOG = LoggerFactory.getLogger(GlossaryTermUtils.class);
@@ -131,6 +132,8 @@ public void processTermAssignments(AtlasGlossaryTerm glossaryTerm, Collection<At
131132
LOG.debug("Assigning term guid={}, to entity guid = {}", glossaryTerm.getGuid(), objectId.getGuid());
132133

133134
createRelationship(defineTermAssignment(glossaryTerm.getGuid(), objectId));
135+
AtlasVertex vertex = AtlasGraphUtilsV2.findByGuid(objectId.getGuid());
136+
updateModificationMetadata(vertex);
134137
}
135138

136139
LOG.debug("<== GlossaryTermUtils.processTermAssignments()");
@@ -162,6 +165,8 @@ public void processTermDissociation(AtlasGlossaryTerm glossaryTerm, Collection<A
162165

163166
if (CollectionUtils.isNotEmpty(assignedEntities) && isRelationshipGuidSame(existingTermRelation, relatedObjectId)) {
164167
relationshipStore.deleteById(relatedObjectId.getRelationshipGuid(), true);
168+
AtlasVertex vertex = AtlasGraphUtilsV2.findByGuid(relatedObjectId.getGuid());
169+
updateModificationMetadata(vertex);
165170
} else {
166171
throw new AtlasBaseException(AtlasErrorCode.INVALID_TERM_DISSOCIATION, relatedObjectId.getRelationshipGuid(), glossaryTerm.getGuid(), relatedObjectId.getGuid());
167172
}

repository/src/test/java/org/apache/atlas/glossary/GlossaryServiceTest.java

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.atlas.glossary;
1919

2020
import org.apache.atlas.AtlasErrorCode;
21+
import org.apache.atlas.RequestContext;
2122
import org.apache.atlas.SortOrder;
2223
import org.apache.atlas.TestModules;
2324
import org.apache.atlas.bulkimport.BulkImportResponse;
@@ -1035,6 +1036,8 @@ public void testTermAssignmentAndDissociation() {
10351036
assetEntity.setAttribute("qualifiedName", "testAsset");
10361037
assetEntity.setAttribute("name", "testAsset");
10371038

1039+
long originalUpdateTime = 0L;
1040+
long updatedTimeAfterAssignment = 0L;
10381041
try {
10391042
EntityMutationResponse response = entityStore.createOrUpdate(new AtlasEntityStream(assetEntity), false);
10401043
AtlasEntityHeader firstEntityCreated = response.getFirstEntityCreated();
@@ -1045,12 +1048,31 @@ public void testTermAssignmentAndDissociation() {
10451048
relatedObjectId.setTypeName(firstEntityCreated.getTypeName());
10461049

10471050
assertNotNull(relatedObjectId);
1051+
AtlasEntity.AtlasEntityWithExtInfo entityInfo = entityStore.getById(relatedObjectId.getGuid());
1052+
AtlasEntity createdEntity = entityInfo.getEntity();
1053+
assertNotNull(createdEntity);
1054+
originalUpdateTime = createdEntity.getUpdateTime().getTime();
10481055
} catch (AtlasBaseException e) {
10491056
fail("Entity creation should've succeeded", e);
10501057
}
10511058

1059+
long mockRequestTimeAssign = System.currentTimeMillis() + 5000; // simulate later timestamp
10521060
try {
1053-
glossaryService.assignTermToEntities(fixedRateMortgage.getGuid(), Collections.singletonList(relatedObjectId));
1061+
try (MockedStatic<RequestContext> mockedRequestContext = Mockito.mockStatic(RequestContext.class)) {
1062+
RequestContext mockContext = mock(RequestContext.class);
1063+
when(mockContext.getRequestTime()).thenReturn(mockRequestTimeAssign);
1064+
mockedRequestContext.when(RequestContext::get).thenReturn(mockContext);
1065+
1066+
glossaryService.assignTermToEntities(fixedRateMortgage.getGuid(), Collections.singletonList(relatedObjectId));
1067+
1068+
//verify updateTime after assignment
1069+
AtlasEntity.AtlasEntityWithExtInfo updatedInfo = entityStore.getById(relatedObjectId.getGuid());
1070+
AtlasEntity updatedEntityAfterAssignment = updatedInfo.getEntity();
1071+
updatedTimeAfterAssignment = updatedEntityAfterAssignment.getUpdateTime().getTime();
1072+
1073+
assertEquals(updatedTimeAfterAssignment, mockRequestTimeAssign);
1074+
assertTrue(updatedTimeAfterAssignment > originalUpdateTime, "updateTime should have increased after term assignment");
1075+
}
10541076
} catch (AtlasBaseException e) {
10551077
fail("Term assignment to asset should've succeeded", e);
10561078
}
@@ -1072,8 +1094,22 @@ public void testTermAssignmentAndDissociation() {
10721094

10731095
// Dissociate term from entities
10741096
try {
1075-
glossaryService.removeTermFromEntities(fixedRateMortgage.getGuid(), Collections.singletonList(relatedObjectId));
1097+
long mockRequestTimeRemove = mockRequestTimeAssign + 5000;
1098+
try (MockedStatic<RequestContext> mockedRequestContext = Mockito.mockStatic(RequestContext.class)) {
1099+
RequestContext mockContext = mock(RequestContext.class);
1100+
when(mockContext.getRequestTime()).thenReturn(mockRequestTimeRemove);
1101+
mockedRequestContext.when(RequestContext::get).thenReturn(mockContext);
1102+
1103+
glossaryService.removeTermFromEntities(fixedRateMortgage.getGuid(), Collections.singletonList(relatedObjectId));
10761104

1105+
//verify updateTime after dissociation
1106+
AtlasEntity.AtlasEntityWithExtInfo updatedInfo = entityStore.getById(relatedObjectId.getGuid());
1107+
AtlasEntity updatedEntityAfterDissociation = updatedInfo.getEntity();
1108+
long updatedTimeAfterDissociation = updatedEntityAfterDissociation.getUpdateTime().getTime();
1109+
1110+
assertEquals(updatedTimeAfterDissociation, mockRequestTimeRemove);
1111+
assertTrue(updatedTimeAfterDissociation > updatedTimeAfterAssignment, "updateTime should have increased after term dissociation");
1112+
}
10771113
AtlasGlossaryTerm term = glossaryService.getTerm(fixedRateMortgage.getGuid());
10781114

10791115
assertNotNull(term);

0 commit comments

Comments
 (0)