mirror of
https://github.com/datahub-project/datahub.git
synced 2025-12-28 18:38:17 +00:00
fix(owner): Corrects ownership aspect generation during update operations (#8399)
This commit is contained in:
parent
60b9623675
commit
e32d552039
@ -37,10 +37,17 @@ public class OwnerUpdateMapper implements ModelMapper<OwnerUpdate, Owner> {
|
||||
}
|
||||
if (input.getOwnershipTypeUrn() != null) {
|
||||
owner.setTypeUrn(UrnUtils.getUrn(input.getOwnershipTypeUrn()));
|
||||
} else if (input.getType() != null) {
|
||||
owner.setType(OwnershipType.valueOf(input.getType().toString()));
|
||||
} else {
|
||||
throw new RuntimeException("Ownership type not specified. Please define the ownership type urn.");
|
||||
}
|
||||
// For backwards compatibility we have to always set the deprecated type.
|
||||
// If the type exists we assume it's an old ownership type that we can map to.
|
||||
// Else if it's a net new custom ownership type set old type to CUSTOM.
|
||||
OwnershipType type = input.getType() != null ? OwnershipType.valueOf(input.getType().toString())
|
||||
: OwnershipType.CUSTOM;
|
||||
owner.setType(type);
|
||||
|
||||
if (input.getOwnershipTypeUrn() != null) {
|
||||
owner.setTypeUrn(UrnUtils.getUrn(input.getOwnershipTypeUrn()));
|
||||
owner.setType(OwnershipType.CUSTOM);
|
||||
}
|
||||
|
||||
owner.setSource(new OwnershipSource().setType(OwnershipSourceType.SERVICE));
|
||||
|
||||
@ -26,6 +26,8 @@ import static com.linkedin.metadata.entity.AspectUtils.*;
|
||||
@Slf4j
|
||||
public class OwnerService extends BaseService {
|
||||
|
||||
public static final String SYSTEM_ID = "__system__";
|
||||
|
||||
public OwnerService(@Nonnull EntityClient entityClient, @Nonnull Authentication systemAuthentication) {
|
||||
super(entityClient, systemAuthentication);
|
||||
}
|
||||
@ -205,10 +207,16 @@ public class OwnerService extends BaseService {
|
||||
for (Urn ownerUrn : ownersToAdd) {
|
||||
Owner newOwner = new Owner();
|
||||
newOwner.setOwner(ownerUrn);
|
||||
newOwner.setTypeUrn(mapOwnershipTypeToEntity(OwnershipType.NONE.name()));
|
||||
newOwner.setType(ownershipType);
|
||||
ownerAssociationArray.add(newOwner);
|
||||
}
|
||||
}
|
||||
@VisibleForTesting
|
||||
static Urn mapOwnershipTypeToEntity(String type) {
|
||||
final String typeName = SYSTEM_ID + type.toLowerCase();
|
||||
return Urn.createFromTuple(Constants.OWNERSHIP_TYPE_ENTITY_NAME, typeName);
|
||||
}
|
||||
|
||||
private static OwnerArray removeOwnersIfExists(Ownership owners, List<Urn> ownerUrns) {
|
||||
if (!owners.hasOwners()) {
|
||||
|
||||
@ -29,6 +29,8 @@ import org.testcontainers.shaded.com.google.common.collect.ImmutableMap;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static com.linkedin.metadata.service.OwnerService.*;
|
||||
|
||||
|
||||
public class OwnerServiceTest {
|
||||
|
||||
@ -63,6 +65,7 @@ public class OwnerServiceTest {
|
||||
ImmutableList.of(
|
||||
new Owner().setOwner(TEST_OWNER_URN_1).setType(OwnershipType.NONE),
|
||||
new Owner().setOwner(newOwnerUrn).setType(OwnershipType.NONE)
|
||||
.setTypeUrn(mapOwnershipTypeToEntity(OwnershipType.NONE.toString()))
|
||||
));
|
||||
|
||||
MetadataChangeProposal event1 = events.get(0);
|
||||
@ -102,7 +105,8 @@ public class OwnerServiceTest {
|
||||
mockAuthentication());
|
||||
|
||||
OwnerArray expectedOwners = new OwnerArray(
|
||||
ImmutableList.of(new Owner().setOwner(newOwnerUrn).setType(OwnershipType.NONE)));
|
||||
ImmutableList.of(new Owner().setOwner(newOwnerUrn).setType(OwnershipType.NONE)
|
||||
.setTypeUrn(mapOwnershipTypeToEntity(OwnershipType.NONE.toString()))));
|
||||
|
||||
MetadataChangeProposal event1 = events.get(0);
|
||||
Assert.assertEquals(event1.getAspectName(), Constants.OWNERSHIP_ASPECT_NAME);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user