mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-09-06 15:43:04 +00:00
Fixes 13146 - Patch operation not working for Domain (#13164)
This commit is contained in:
parent
a22d7bb87f
commit
1865f46ab5
@ -16,10 +16,8 @@ package org.openmetadata.service.jdbi3;
|
||||
import static org.openmetadata.common.utils.CommonUtil.listOrEmpty;
|
||||
import static org.openmetadata.schema.type.Include.ALL;
|
||||
import static org.openmetadata.service.Entity.DOMAIN;
|
||||
import static org.openmetadata.service.Entity.FIELD_EXPERTS;
|
||||
import static org.openmetadata.service.resources.EntityResource.searchClient;
|
||||
|
||||
import java.util.List;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.openmetadata.schema.entity.domains.Domain;
|
||||
import org.openmetadata.schema.type.EntityReference;
|
||||
@ -59,7 +57,6 @@ public class DomainRepository extends EntityRepository<Domain> {
|
||||
@Override
|
||||
public void storeEntity(Domain entity, boolean update) {
|
||||
EntityReference parent = entity.getParent();
|
||||
List<EntityReference> children = entity.getChildren();
|
||||
entity.withParent(null);
|
||||
store(entity, update);
|
||||
entity.withParent(parent);
|
||||
@ -133,21 +130,7 @@ public class DomainRepository extends EntityRepository<Domain> {
|
||||
|
||||
@Override
|
||||
public void entitySpecificUpdate() {
|
||||
updateExperts();
|
||||
}
|
||||
|
||||
private void updateExperts() {
|
||||
List<EntityReference> origExperts = listOrEmpty(original.getExperts());
|
||||
List<EntityReference> updatedExperts = listOrEmpty(updated.getExperts());
|
||||
updateToRelationships(
|
||||
FIELD_EXPERTS,
|
||||
DOMAIN,
|
||||
original.getId(),
|
||||
Relationship.EXPERT,
|
||||
Entity.USER,
|
||||
origExperts,
|
||||
updatedExperts,
|
||||
false);
|
||||
recordChange("domainType", original.getDomainType(), updated.getDomainType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -416,7 +416,7 @@ public abstract class EntityRepository<T extends EntityInterface> {
|
||||
// Clone the entity from the cache and reset all the fields that are not already set
|
||||
// Cloning is necessary to ensure different threads making a call to this method don't
|
||||
// overwrite the fields of the entity being returned
|
||||
T entityClone = JsonUtils.readValue(JsonUtils.pojoToJson(entity), entityClass);
|
||||
T entityClone = JsonUtils.deepCopy(entity, entityClass);
|
||||
clearFieldsInternal(entityClone, fields);
|
||||
return withHref(uriInfo, entityClone);
|
||||
}
|
||||
@ -461,7 +461,7 @@ public abstract class EntityRepository<T extends EntityInterface> {
|
||||
// Clone the entity from the cache and reset all the fields that are not already set
|
||||
// Cloning is necessary to ensure different threads making a call to this method don't
|
||||
// overwrite the fields of the entity being returned
|
||||
T entityClone = JsonUtils.readValue(JsonUtils.pojoToJson(entity), entityClass);
|
||||
T entityClone = JsonUtils.deepCopy(entity, entityClass);
|
||||
clearFieldsInternal(entityClone, fields);
|
||||
return withHref(uriInfo, entityClone);
|
||||
}
|
||||
@ -1931,7 +1931,7 @@ public abstract class EntityRepository<T extends EntityInterface> {
|
||||
List<EntityReference> updatedExperts = listOrEmpty(updated.getExperts());
|
||||
updateToRelationships(
|
||||
FIELD_EXPERTS,
|
||||
Entity.DATA_PRODUCT,
|
||||
entityType,
|
||||
original.getId(),
|
||||
Relationship.EXPERT,
|
||||
Entity.USER,
|
||||
|
@ -133,6 +133,7 @@ import org.openmetadata.schema.CreateEntity;
|
||||
import org.openmetadata.schema.EntityInterface;
|
||||
import org.openmetadata.schema.api.data.RestoreEntity;
|
||||
import org.openmetadata.schema.api.data.TermReference;
|
||||
import org.openmetadata.schema.api.domains.CreateDomain.DomainType;
|
||||
import org.openmetadata.schema.api.feed.CreateThread;
|
||||
import org.openmetadata.schema.api.teams.CreateTeam;
|
||||
import org.openmetadata.schema.api.teams.CreateTeam.TeamType;
|
||||
@ -2427,6 +2428,8 @@ public abstract class EntityResourceTest<T extends EntityInterface, K extends Cr
|
||||
actualTags.forEach(tagLabel -> assertNotNull(tagLabel.getDescription()));
|
||||
} else if (fieldName.startsWith("extension")) { // Custom properties related extension field changes
|
||||
assertEquals(expected.toString(), actual.toString());
|
||||
} else if (fieldName.equals("domainType")) { // Custom properties related extension field changes
|
||||
assertEquals(expected, DomainType.fromValue(actual.toString()));
|
||||
} else {
|
||||
// All the other fields
|
||||
assertEquals(expected, actual, "Field name " + fieldName);
|
||||
|
@ -2,6 +2,9 @@ package org.openmetadata.service.resources.domains;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.openmetadata.common.utils.CommonUtil.listOf;
|
||||
import static org.openmetadata.service.util.EntityUtil.fieldAdded;
|
||||
import static org.openmetadata.service.util.EntityUtil.fieldDeleted;
|
||||
import static org.openmetadata.service.util.EntityUtil.fieldUpdated;
|
||||
import static org.openmetadata.service.util.TestUtils.ADMIN_AUTH_HEADERS;
|
||||
import static org.openmetadata.service.util.TestUtils.assertEntityReferenceNames;
|
||||
import static org.openmetadata.service.util.TestUtils.assertListNotNull;
|
||||
@ -10,16 +13,20 @@ import static org.openmetadata.service.util.TestUtils.assertListNull;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
import org.apache.http.client.HttpResponseException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInfo;
|
||||
import org.openmetadata.schema.api.domains.CreateDomain;
|
||||
import org.openmetadata.schema.api.domains.CreateDomain.DomainType;
|
||||
import org.openmetadata.schema.entity.domains.Domain;
|
||||
import org.openmetadata.schema.type.ChangeDescription;
|
||||
import org.openmetadata.schema.type.EntityReference;
|
||||
import org.openmetadata.service.Entity;
|
||||
import org.openmetadata.service.resources.EntityResourceTest;
|
||||
import org.openmetadata.service.resources.domains.DomainResource.DomainList;
|
||||
import org.openmetadata.service.util.JsonUtils;
|
||||
import org.openmetadata.service.util.TestUtils.UpdateType;
|
||||
|
||||
public class DomainResourceTest extends EntityResourceTest<Domain, CreateDomain> {
|
||||
public DomainResourceTest() {
|
||||
@ -32,6 +39,57 @@ public class DomainResourceTest extends EntityResourceTest<Domain, CreateDomain>
|
||||
createEntity(createRequest("sub-domain").withParent(DOMAIN.getFullyQualifiedName()), ADMIN_AUTH_HEADERS);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDomainExpertsUpdate(TestInfo test) throws IOException {
|
||||
CreateDomain create = createRequest(getEntityName(test)).withExperts(listOf(USER1.getFullyQualifiedName()));
|
||||
Domain domain = createAndCheckEntity(create, ADMIN_AUTH_HEADERS);
|
||||
|
||||
// Add User2 as expert using PUT
|
||||
create.withExperts(List.of(USER1.getFullyQualifiedName(), USER2.getFullyQualifiedName()));
|
||||
ChangeDescription change = getChangeDescription(domain.getVersion());
|
||||
fieldAdded(change, "experts", listOf(USER2.getEntityReference()));
|
||||
domain = updateAndCheckEntity(create, Status.OK, ADMIN_AUTH_HEADERS, UpdateType.MINOR_UPDATE, change);
|
||||
|
||||
// Remove User2 as expert using PUT
|
||||
create.withExperts(List.of(USER1.getFullyQualifiedName()));
|
||||
change = getChangeDescription(domain.getVersion());
|
||||
fieldDeleted(change, "experts", listOf(USER2.getEntityReference()));
|
||||
domain = updateAndCheckEntity(create, Status.OK, ADMIN_AUTH_HEADERS, UpdateType.MINOR_UPDATE, change);
|
||||
|
||||
// Add User2 as expert using PATCH
|
||||
String json = JsonUtils.pojoToJson(domain);
|
||||
domain.withExperts(List.of(USER1.getEntityReference(), USER2.getEntityReference()));
|
||||
change = getChangeDescription(domain.getVersion());
|
||||
fieldAdded(change, "experts", listOf(USER2.getEntityReference()));
|
||||
domain = patchEntityAndCheck(domain, json, ADMIN_AUTH_HEADERS, UpdateType.MINOR_UPDATE, change);
|
||||
|
||||
// Remove User2 as expert using PATCH
|
||||
json = JsonUtils.pojoToJson(domain);
|
||||
domain.withExperts(List.of(USER1.getEntityReference()));
|
||||
change = getChangeDescription(domain.getVersion());
|
||||
fieldDeleted(change, "experts", listOf(USER2.getEntityReference()));
|
||||
patchEntityAndCheck(domain, json, ADMIN_AUTH_HEADERS, UpdateType.MINOR_UPDATE, change);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDomainTypeUpdate(TestInfo test) throws IOException {
|
||||
CreateDomain create = createRequest(getEntityName(test)).withExperts(listOf(USER1.getFullyQualifiedName()));
|
||||
Domain domain = createAndCheckEntity(create, ADMIN_AUTH_HEADERS);
|
||||
|
||||
// Change domain type from AGGREGATE to SOURCE_ALIGNED using PUT
|
||||
create.withDomainType(DomainType.SOURCE_ALIGNED);
|
||||
ChangeDescription change = getChangeDescription(domain.getVersion());
|
||||
fieldUpdated(change, "domainType", DomainType.AGGREGATE, DomainType.SOURCE_ALIGNED);
|
||||
domain = updateAndCheckEntity(create, Status.OK, ADMIN_AUTH_HEADERS, UpdateType.MINOR_UPDATE, change);
|
||||
|
||||
// Change domain type from SOURCE_ALIGNED to CONSUMER_ALIGNED using PATCH
|
||||
String json = JsonUtils.pojoToJson(domain);
|
||||
domain.withDomainType(DomainType.CONSUMER_ALIGNED);
|
||||
change = getChangeDescription(domain.getVersion());
|
||||
fieldUpdated(change, "domainType", DomainType.SOURCE_ALIGNED, DomainType.CONSUMER_ALIGNED);
|
||||
patchEntityAndCheck(domain, json, ADMIN_AUTH_HEADERS, UpdateType.MINOR_UPDATE, change);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CreateDomain createRequest(String name) {
|
||||
return new CreateDomain()
|
||||
|
Loading…
x
Reference in New Issue
Block a user