mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-09-25 08:50:18 +00:00
Issue #14067: DatabaseSchema Restore operation throws error EntityNotFound, if a table that belongs to schema is already restored (#14112)
* Issue #14067: DatabaseSchema Restore operation throws error EntityNotFound, if a table that belongs to schema is already restored * Issue #14067: DatabaseSchema Restore operation throws error EntityNotFound, if a table that belongs to schema is already restored
This commit is contained in:
parent
b85f896e0f
commit
d4fa62b3bb
@ -1363,14 +1363,20 @@ public abstract class EntityRepository<T extends EntityInterface> {
|
||||
|
||||
// Finally set entity deleted flag to false
|
||||
LOG.info("Restoring the {} {}", entityType, id);
|
||||
T original = find(id, DELETED);
|
||||
setFieldsInternal(original, putFields);
|
||||
T updated = JsonUtils.readValue(JsonUtils.pojoToJson(original), entityClass);
|
||||
updated.setUpdatedBy(updatedBy);
|
||||
updated.setUpdatedAt(System.currentTimeMillis());
|
||||
EntityUpdater updater = getUpdater(original, updated, Operation.PUT);
|
||||
updater.update();
|
||||
return new PutResponse<>(Status.OK, updated, RestUtil.ENTITY_RESTORED);
|
||||
|
||||
try {
|
||||
T original = find(id, DELETED);
|
||||
setFieldsInternal(original, putFields);
|
||||
T updated = JsonUtils.readValue(JsonUtils.pojoToJson(original), entityClass);
|
||||
updated.setUpdatedBy(updatedBy);
|
||||
updated.setUpdatedAt(System.currentTimeMillis());
|
||||
EntityUpdater updater = getUpdater(original, updated, Operation.PUT);
|
||||
updater.update();
|
||||
return new PutResponse<>(Status.OK, updated, RestUtil.ENTITY_RESTORED);
|
||||
} catch (EntityNotFoundException e) {
|
||||
LOG.info("Entity is not in deleted state {} {}", entityType, id);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void addRelationship(UUID fromId, UUID toId, String fromEntity, String toEntity, Relationship relationship) {
|
||||
|
@ -22,14 +22,18 @@ import static org.openmetadata.service.util.TestUtils.assertListNotNull;
|
||||
import static org.openmetadata.service.util.TestUtils.assertListNull;
|
||||
import static org.openmetadata.service.util.TestUtils.assertResponseContains;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import javax.ws.rs.core.Response;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.http.client.HttpResponseException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInfo;
|
||||
import org.openmetadata.schema.api.data.CreateDatabaseSchema;
|
||||
import org.openmetadata.schema.api.data.CreateTable;
|
||||
import org.openmetadata.schema.api.data.RestoreEntity;
|
||||
import org.openmetadata.schema.entity.data.DatabaseSchema;
|
||||
import org.openmetadata.schema.entity.data.Table;
|
||||
import org.openmetadata.schema.type.EntityReference;
|
||||
import org.openmetadata.service.Entity;
|
||||
import org.openmetadata.service.resources.EntityResourceTest;
|
||||
@ -55,6 +59,30 @@ class DatabaseSchemaResourceTest extends EntityResourceTest<DatabaseSchema, Crea
|
||||
assertResponseContains(() -> createEntity(create, ADMIN_AUTH_HEADERS), BAD_REQUEST, "database must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
void delete_schemaWithTables_200(TestInfo test) throws IOException {
|
||||
CreateDatabaseSchema create = createRequest(test).withDatabase(DATABASE.getFullyQualifiedName());
|
||||
DatabaseSchema createdSchema = createAndCheckEntity(create, ADMIN_AUTH_HEADERS);
|
||||
TableResourceTest tableResourceTest = new TableResourceTest();
|
||||
CreateTable createTable =
|
||||
tableResourceTest.createRequest("t1", "", "", null).withDatabaseSchema(createdSchema.getFullyQualifiedName());
|
||||
Table table1 = tableResourceTest.createEntity(createTable, ADMIN_AUTH_HEADERS);
|
||||
createTable =
|
||||
tableResourceTest.createRequest("t2", "", "", null).withDatabaseSchema(createdSchema.getFullyQualifiedName());
|
||||
Table table2 = tableResourceTest.createEntity(createTable, ADMIN_AUTH_HEADERS);
|
||||
|
||||
// recursively soft delete schema
|
||||
deleteAndCheckEntity(createdSchema, true, false, ADMIN_AUTH_HEADERS);
|
||||
|
||||
// Restore one of the tables.
|
||||
tableResourceTest.restoreEntity(new RestoreEntity().withId(table2.getId()), Response.Status.OK, ADMIN_AUTH_HEADERS);
|
||||
|
||||
// Restore Schema
|
||||
restoreEntity(new RestoreEntity().withId(createdSchema.getId()), Response.Status.OK, ADMIN_AUTH_HEADERS);
|
||||
DatabaseSchema schema = getEntity(createdSchema.getId(), ADMIN_AUTH_HEADERS);
|
||||
assertNotNull(schema);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DatabaseSchema validateGetWithDifferentFields(DatabaseSchema schema, boolean byName)
|
||||
throws HttpResponseException {
|
||||
|
Loading…
x
Reference in New Issue
Block a user