Skip to content

Commit

Permalink
feat(ece): support custom ownership type urns in ECE generation (data…
Browse files Browse the repository at this point in the history
  • Loading branch information
hsheth2 authored Jul 26, 2024
1 parent bc75f7a commit fdbcb68
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,29 @@ public OwnerChangeEvent(
SemanticChangeType semVerChange,
String description,
Urn ownerUrn,
OwnershipType ownerType) {
OwnershipType ownerType,
Urn ownerTypeUrn) {
super(
entityUrn,
category,
operation,
modifier,
ImmutableMap.of(
"ownerUrn", ownerUrn.toString(),
"ownerType", ownerType.toString()),
buildParameters(ownerUrn, ownerType, ownerTypeUrn),
auditStamp,
semVerChange,
description);
}

private static ImmutableMap<String, Object> buildParameters(
Urn ownerUrn, OwnershipType ownerType, Urn ownerTypeUrn) {
ImmutableMap.Builder<String, Object> builder =
new ImmutableMap.Builder<String, Object>()
.put("ownerUrn", ownerUrn.toString())
.put("ownerType", ownerType.toString());
if (ownerTypeUrn != null) {
builder.put("ownerTypeUrn", ownerTypeUrn.toString());
}

return builder.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ private static List<ChangeEvent> computeDiffs(
entityUrn))
.ownerUrn(targetOwner.getOwner())
.ownerType(targetOwner.getType())
.ownerTypeUrn(targetOwner.getTypeUrn())
.auditStamp(auditStamp)
.build());
}
Expand All @@ -84,6 +85,7 @@ private static List<ChangeEvent> computeDiffs(
entityUrn))
.ownerUrn(baseOwner.getOwner())
.ownerType(baseOwner.getType())
.ownerTypeUrn(baseOwner.getTypeUrn())
.auditStamp(auditStamp)
.build());
++baseOwnerIdx;
Expand All @@ -104,6 +106,7 @@ private static List<ChangeEvent> computeDiffs(
entityUrn))
.ownerUrn(targetOwner.getOwner())
.ownerType(targetOwner.getType())
.ownerTypeUrn(targetOwner.getTypeUrn())
.auditStamp(auditStamp)
.build());
++targetOwnerIdx;
Expand All @@ -128,6 +131,7 @@ private static List<ChangeEvent> computeDiffs(
entityUrn))
.ownerUrn(baseOwner.getOwner())
.ownerType(baseOwner.getType())
.ownerTypeUrn(baseOwner.getTypeUrn())
.auditStamp(auditStamp)
.build());
++baseOwnerIdx;
Expand All @@ -150,6 +154,7 @@ private static List<ChangeEvent> computeDiffs(
entityUrn))
.ownerUrn(targetOwner.getOwner())
.ownerType(targetOwner.getType())
.ownerTypeUrn(targetOwner.getTypeUrn())
.auditStamp(auditStamp)
.build());
++targetOwnerIdx;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,16 @@ public void testInvokeEntityOwnerChange() throws Exception {
final Ownership newOwners = new Ownership();
final Urn ownerUrn1 = Urn.createFromString("urn:li:corpuser:test1");
final Urn ownerUrn2 = Urn.createFromString("urn:li:corpuser:test2");
final Urn ownerUrn3 = Urn.createFromString("urn:li:corpuser:test3");
newOwners.setOwners(
new OwnerArray(
ImmutableList.of(
new Owner().setOwner(ownerUrn1).setType(OwnershipType.TECHNICAL_OWNER),
new Owner().setOwner(ownerUrn2).setType(OwnershipType.BUSINESS_OWNER))));
new Owner().setOwner(ownerUrn2).setType(OwnershipType.BUSINESS_OWNER),
new Owner()
.setOwner(ownerUrn3)
.setType(OwnershipType.CUSTOM)
.setTypeUrn(Urn.createFromString("urn:li:ownershipType:my_custom_type")))));
final Ownership prevOwners = new Ownership();
prevOwners.setOwners(new OwnerArray());
event.setAspect(GenericRecordUtils.serializeAspect(newOwners));
Expand Down Expand Up @@ -354,7 +359,24 @@ public void testInvokeEntityOwnerChange() throws Exception {
"ownerType",
OwnershipType.BUSINESS_OWNER.toString()),
actorUrn);
verifyProducePlatformEvent(_mockClient, platformEvent2, true);
verifyProducePlatformEvent(_mockClient, platformEvent2, false);

PlatformEvent platformEvent3 =
createChangeEvent(
DATASET_ENTITY_NAME,
Urn.createFromString(TEST_DATASET_URN),
ChangeCategory.OWNER,
ChangeOperation.ADD,
ownerUrn3.toString(),
ImmutableMap.of(
"ownerUrn",
ownerUrn3.toString(),
"ownerType",
OwnershipType.CUSTOM.toString(),
"ownerTypeUrn",
"urn:li:ownershipType:my_custom_type"),
actorUrn);
verifyProducePlatformEvent(_mockClient, platformEvent3, true);
}

@Test
Expand Down

0 comments on commit fdbcb68

Please sign in to comment.