Fix #2377: Need versions support for deleted entities (#2380)

This commit is contained in:
Alberto Miorin 2022-01-24 14:56:32 +01:00 committed by GitHub
parent 71a2b0145c
commit 7a6e9a8060
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -332,7 +332,7 @@ public abstract class EntityRepository<T> {
return JsonUtils.readValue(json, entityClass);
}
// If requested the latest version, return it from current version of the entity
T entity = setFields(dao.findEntityById(UUID.fromString(id)), putFields);
T entity = setFields(dao.findEntityById(UUID.fromString(id), Include.ALL), putFields);
EntityInterface<T> entityInterface = getEntityInterface(entity);
if (entityInterface.getVersion().equals(requestedVersion)) {
return entity;
@ -343,7 +343,7 @@ public abstract class EntityRepository<T> {
@Transaction
public EntityHistory listVersions(String id) throws IOException, ParseException {
T latest = setFields(dao.findEntityById(UUID.fromString(id)), putFields);
T latest = setFields(dao.findEntityById(UUID.fromString(id), Include.ALL), putFields);
String extensionPrefix = EntityUtil.getVersionExtensionPrefix(entityType);
List<EntityVersionPair> oldVersions = daoCollection.entityExtensionDAO().getEntityVersions(id, extensionPrefix);
oldVersions.sort(EntityUtil.compareVersion.reversed());

View File

@ -537,6 +537,19 @@ public abstract class EntityResourceTest<T> extends CatalogApplicationTest {
validateGetWithDifferentFields(entity, true);
}
@Test
void get_deletedVersion(TestInfo test) throws IOException, URISyntaxException {
Object create = createRequest(getEntityName(test), "description", "displayName", USER_OWNER1);
T entity = createEntity(create, adminAuthHeaders());
EntityInterface<T> entityInterface = getEntityInterface(entity);
getEntity(entityInterface.getId(), null, allFields, adminAuthHeaders());
deleteAndCheckEntity(entity, adminAuthHeaders());
EntityHistory history = getVersionList(entityInterface.getId(), adminAuthHeaders());
T latestVersion = JsonUtils.readValue((String) history.getVersions().get(0), entityClass);
entityInterface = getEntityInterface(latestVersion);
getVersion(entityInterface.getId(), entityInterface.getVersion(), adminAuthHeaders());
}
@Test
void get_entityIncludeDeleted_200(TestInfo test) throws IOException, URISyntaxException {
Object create = createRequest(getEntityName(test), "description", "displayName", USER_OWNER1);