fix(ownership-differ): standardise ownership change event payload (#5967)

* fix(ownership-differ): standardise ownership change event payload

* fix(ownership-differ): update test case

Co-authored-by: Shirshanka Das <shirshanka@apache.org>
Co-authored-by: John Joyce <john@acryl.io>
This commit is contained in:
Amanda Ng 2022-09-23 06:06:17 +08:00 committed by GitHub
parent 1ff6ccead1
commit 63ef9c04f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 6 deletions

View File

@ -2,6 +2,7 @@ package com.linkedin.metadata.timeline.data.entity;
import com.google.common.collect.ImmutableMap;
import com.linkedin.common.AuditStamp;
import com.linkedin.common.OwnershipType;
import com.linkedin.common.urn.Urn;
import com.linkedin.metadata.timeline.data.ChangeCategory;
import com.linkedin.metadata.timeline.data.ChangeEvent;
@ -25,7 +26,8 @@ public class OwnerChangeEvent extends ChangeEvent {
AuditStamp auditStamp,
SemanticChangeType semVerChange,
String description,
Urn ownerUrn
Urn ownerUrn,
OwnershipType ownerType
) {
super(
entityUrn,
@ -33,7 +35,8 @@ public class OwnerChangeEvent extends ChangeEvent {
operation,
modifier,
ImmutableMap.of(
"ownerUrn", ownerUrn.toString()
"ownerUrn", ownerUrn.toString(),
"ownerType", ownerType.toString()
),
auditStamp,
semVerChange,

View File

@ -46,15 +46,17 @@ public class OwnershipDiffer implements AspectDiffer<Ownership> {
if (comparison == 0) {
if (!baseOwner.getType().equals(targetOwner.getType())) {
// Ownership type has changed.
changeEvents.add(ChangeEvent.builder()
changeEvents.add(OwnerChangeEvent.entityOwnerChangeEventBuilder()
.modifier(targetOwner.getType().name())
.entityUrn(baseOwner.getOwner().toString())
.entityUrn(entityUrn)
.category(ChangeCategory.OWNER)
.operation(ChangeOperation.MODIFY)
.semVerChange(SemanticChangeType.PATCH)
.description(
String.format(OWNERSHIP_TYPE_CHANGE_FORMAT, baseOwner.getOwner().getId(), baseOwner.getType(),
targetOwner.getType(), entityUrn))
.ownerUrn(targetOwner.getOwner())
.ownerType(targetOwner.getType())
.auditStamp(auditStamp)
.build());
}
@ -70,6 +72,7 @@ public class OwnershipDiffer implements AspectDiffer<Ownership> {
.semVerChange(SemanticChangeType.MINOR)
.description(String.format(OWNER_REMOVED_FORMAT, baseOwner.getOwner().getId(), baseOwner.getType(), entityUrn))
.ownerUrn(baseOwner.getOwner())
.ownerType(baseOwner.getType())
.auditStamp(auditStamp)
.build());
++baseOwnerIdx;
@ -83,6 +86,7 @@ public class OwnershipDiffer implements AspectDiffer<Ownership> {
.semVerChange(SemanticChangeType.MINOR)
.description(String.format(OWNER_ADDED_FORMAT, targetOwner.getOwner().getId(), targetOwner.getType(), entityUrn))
.ownerUrn(targetOwner.getOwner())
.ownerType(targetOwner.getType())
.auditStamp(auditStamp)
.build());
++targetOwnerIdx;
@ -100,6 +104,7 @@ public class OwnershipDiffer implements AspectDiffer<Ownership> {
.semVerChange(SemanticChangeType.MINOR)
.description(String.format(OWNER_REMOVED_FORMAT, baseOwner.getOwner().getId(), baseOwner.getType(), entityUrn))
.ownerUrn(baseOwner.getOwner())
.ownerType(baseOwner.getType())
.auditStamp(auditStamp)
.build());
++baseOwnerIdx;
@ -115,6 +120,7 @@ public class OwnershipDiffer implements AspectDiffer<Ownership> {
.semVerChange(SemanticChangeType.MINOR)
.description(String.format(OWNER_ADDED_FORMAT, targetOwner.getOwner().getId(), targetOwner.getType(), entityUrn))
.ownerUrn(targetOwner.getOwner())
.ownerType(targetOwner.getType())
.auditStamp(auditStamp)
.build());
++targetOwnerIdx;

View File

@ -368,7 +368,8 @@ public class EntityChangeEventGeneratorHookTest {
ChangeOperation.ADD,
ownerUrn1.toString(),
ImmutableMap.of(
"ownerUrn", ownerUrn1.toString()
"ownerUrn", ownerUrn1.toString(),
"ownerType", OwnershipType.TECHNICAL_OWNER.toString()
),
Urn.createFromString(TEST_ACTOR_URN),
eventTime
@ -382,7 +383,8 @@ public class EntityChangeEventGeneratorHookTest {
ChangeOperation.ADD,
ownerUrn2.toString(),
ImmutableMap.of(
"ownerUrn", ownerUrn2.toString()
"ownerUrn", ownerUrn2.toString(),
"ownerType", OwnershipType.BUSINESS_OWNER.toString()
),
Urn.createFromString(TEST_ACTOR_URN),
eventTime