mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-11-02 11:39:12 +00:00
parent
233699a7a1
commit
a75fd13695
@ -56,7 +56,7 @@ public class TypeRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeType(String typeName) {
|
||||
public void removeType(String typeName) {
|
||||
TYPES.remove(typeName);
|
||||
LOG.info("Deleted type {}\n", typeName);
|
||||
// TODO cleanup custom fields
|
||||
|
||||
@ -409,6 +409,8 @@ public abstract class EntityRepository<T extends EntityInterface> {
|
||||
PutResponse<T> response = createOrUpdateInternal(uriInfo, updated);
|
||||
if (response.getStatus() == Status.CREATED) {
|
||||
postCreate(response.getEntity());
|
||||
} else if (response.getStatus() == Status.OK) {
|
||||
postUpdate(response.getEntity());
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
@ -84,7 +84,12 @@ public class TypeRepository extends EntityRepository<Type> {
|
||||
|
||||
@Override
|
||||
protected void postDelete(Type entity) {
|
||||
TypeRegistry.removeType(entity.getName());
|
||||
TypeRegistry.instance().removeType(entity.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postUpdate(Type entity) {
|
||||
TypeRegistry.instance().addType(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -95,6 +100,7 @@ public class TypeRepository extends EntityRepository<Type> {
|
||||
public PutResponse<Type> addCustomField(UriInfo uriInfo, String updatedBy, String id, CustomField field)
|
||||
throws IOException {
|
||||
Type type = dao.findEntityById(UUID.fromString(id), Include.NON_DELETED);
|
||||
field.setFieldType(dao.findEntityReferenceById(field.getFieldType().getId(), Include.NON_DELETED));
|
||||
if (type.getCategory().equals(Category.Field)) {
|
||||
throw new IllegalArgumentException("Field types can't be extended");
|
||||
}
|
||||
|
||||
@ -41,6 +41,7 @@ import org.openmetadata.catalog.entity.type.CustomField;
|
||||
import org.openmetadata.catalog.resources.EntityResourceTest;
|
||||
import org.openmetadata.catalog.resources.types.TypeResource;
|
||||
import org.openmetadata.catalog.resources.types.TypeResource.TypeList;
|
||||
import org.openmetadata.catalog.type.EntityReference;
|
||||
import org.openmetadata.catalog.util.TestUtils;
|
||||
|
||||
@Slf4j
|
||||
@ -91,9 +92,13 @@ public class TypeResourceTest extends EntityResourceTest<Type, CreateType> {
|
||||
assertEquals(fieldA, tableEntity.getCustomFields().get(0));
|
||||
|
||||
// Add a second field with name intB with type integer
|
||||
CustomField fieldB =
|
||||
new CustomField().withName("intB").withDescription("intB").withFieldType(INT_TYPE.getEntityReference());
|
||||
EntityReference typeRef =
|
||||
new EntityReference()
|
||||
.withType(INT_TYPE.getEntityReference().getType())
|
||||
.withId(INT_TYPE.getEntityReference().getId());
|
||||
CustomField fieldB = new CustomField().withName("intB").withDescription("intB").withFieldType(typeRef);
|
||||
tableEntity = addCustomField(tableEntity.getId(), fieldB, Status.OK, ADMIN_AUTH_HEADERS);
|
||||
fieldB.setFieldType(INT_TYPE.getEntityReference());
|
||||
assertEquals(2, tableEntity.getCustomFields().size());
|
||||
assertEquals(fieldA, tableEntity.getCustomFields().get(0));
|
||||
assertEquals(fieldB, tableEntity.getCustomFields().get(1));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user