Fixes 1106 - Version API returning 204 No Content for latest version

This commit is contained in:
sureshms 2021-11-09 18:32:31 -08:00
parent a41e1d751e
commit bc725f2b1b
5 changed files with 29 additions and 8 deletions

View File

@ -55,4 +55,8 @@ public final class CatalogExceptionMessage {
public static String invalidColumnFQN(String fqn) { public static String invalidColumnFQN(String fqn) {
return String.format("Invalid fully qualified column name %s", fqn); return String.format("Invalid fully qualified column name %s", fqn);
} }
public static String entityVersionNotFound(String entity, String id, Double version) {
return String.format("%s instance for %s and version %s not found", StringUtils.capitalize(entity), id, version);
}
} }

View File

@ -3,6 +3,8 @@ package org.openmetadata.catalog.jdbi3;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import org.jdbi.v3.sqlobject.transaction.Transaction; import org.jdbi.v3.sqlobject.transaction.Transaction;
import org.openmetadata.catalog.Entity; import org.openmetadata.catalog.Entity;
import org.openmetadata.catalog.exception.CatalogExceptionMessage;
import org.openmetadata.catalog.exception.EntityNotFoundException;
import org.openmetadata.catalog.jdbi3.CollectionDAO.EntityVersionPair; import org.openmetadata.catalog.jdbi3.CollectionDAO.EntityVersionPair;
import org.openmetadata.catalog.type.ChangeDescription; import org.openmetadata.catalog.type.ChangeDescription;
import org.openmetadata.catalog.type.EntityHistory; import org.openmetadata.catalog.type.EntityHistory;
@ -127,10 +129,23 @@ public abstract class EntityRepository<T> {
} }
@Transaction @Transaction
public T getVersion(String id, String version) throws IOException { public T getVersion(String id, String version) throws IOException, ParseException {
String extension = EntityUtil.getVersionExtension(entityName, Double.parseDouble(version)); Double requestedVersion = Double.parseDouble(version);
String extension = EntityUtil.getVersionExtension(entityName, requestedVersion);
// Get previous version from version history
String json = daoCollection.entityExtensionDAO().getEntityVersion(id, extension); String json = daoCollection.entityExtensionDAO().getEntityVersion(id, extension);
return JsonUtils.readValue(json, entityClass); if (json != null) {
return JsonUtils.readValue(json, entityClass);
}
// If requested latest version, return it from current version of the entity
T entity = setFields(dao.findEntityById(UUID.fromString(id)), putFields);
EntityInterface<T> entityInterface = getEntityInterface(entity);
if (entityInterface.getVersion().equals(requestedVersion)) {
return entity;
}
throw EntityNotFoundException.byMessage(
CatalogExceptionMessage.entityVersionNotFound(entityName, id, requestedVersion));
} }
@Transaction @Transaction

View File

@ -28,8 +28,6 @@ import io.swagger.v3.oas.annotations.parameters.RequestBody;
import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponse;
import org.openmetadata.catalog.api.data.CreateChart; import org.openmetadata.catalog.api.data.CreateChart;
import org.openmetadata.catalog.entity.data.Chart; import org.openmetadata.catalog.entity.data.Chart;
import org.openmetadata.catalog.entity.data.Database;
import org.openmetadata.catalog.entity.data.Table;
import org.openmetadata.catalog.jdbi3.ChartRepository; import org.openmetadata.catalog.jdbi3.ChartRepository;
import org.openmetadata.catalog.jdbi3.ChartRepository.ChartEntityInterface; import org.openmetadata.catalog.jdbi3.ChartRepository.ChartEntityInterface;
import org.openmetadata.catalog.jdbi3.CollectionDAO; import org.openmetadata.catalog.jdbi3.CollectionDAO;

View File

@ -10,6 +10,10 @@
"type": "string", "type": "string",
"maxLength": 45 "maxLength": 45
}, },
"description": {
"description": "Unique name of the tag category.",
"type": "string"
},
"labelType": { "labelType": {
"description" : "Label type describes how a tag label was applied. 'Manual' indicates the tag label was applied by a person. 'Derived' indicates a tag label was derived using the associated tag relationship (see TagCategory.json for more details). 'Propagated` indicates a tag label was propagated from upstream based on lineage. 'Automated' is used when a tool was used to determine the tag label.", "description" : "Label type describes how a tag label was applied. 'Manual' indicates the tag label was applied by a person. 'Derived' indicates a tag label was derived using the associated tag relationship (see TagCategory.json for more details). 'Propagated` indicates a tag label was propagated from upstream based on lineage. 'Automated' is used when a tool was used to determine the tag label.",
"type": "string", "type": "string",
@ -35,5 +39,6 @@
"$ref": "basic.json#/definitions/href" "$ref": "basic.json#/definitions/href"
} }
}, },
"required": ["tagFQN", "labelType", "state"],
"additionalProperties": false "additionalProperties": false
} }

View File

@ -638,9 +638,8 @@ public abstract class EntityResourceTest<T> extends CatalogApplicationTest {
// GET ../entity/{id}/versions/{versionId} to get specific versions of the entity // GET ../entity/{id}/versions/{versionId} to get specific versions of the entity
// Get the latest version of the entity from the versions API and ensure it is correct // Get the latest version of the entity from the versions API and ensure it is correct
// TODO fix this latestVersion = getVersion(entityInterface.getId(), entityInterface.getVersion(), authHeaders);
// latestVersion = getVersion(entityInterface.getId(), entityInterface.getVersion(), authHeaders); validateChangeDescription(latestVersion, updateType, changeDescription);
// validateChangeDescription(latestVersion, updateType, changeDescription);
if (updateType != NO_CHANGE && updateType != UpdateType.CREATED){ if (updateType != NO_CHANGE && updateType != UpdateType.CREATED){
// Get the previous version of the entity from the versions API and ensure it is correct // Get the previous version of the entity from the versions API and ensure it is correct
T previousVersion = getVersion(entityInterface.getId(), changeDescription.getPreviousVersion(), authHeaders); T previousVersion = getVersion(entityInterface.getId(), changeDescription.getPreviousVersion(), authHeaders);