mirror of
https://github.com/datahub-project/datahub.git
synced 2025-12-28 10:28:22 +00:00
Add WH id to urn translate API in V2 (#1000)
This commit is contained in:
parent
24300b3081
commit
0684751875
@ -22,6 +22,7 @@ import dao.DatasetsDAO;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
@ -212,7 +213,8 @@ public class Dataset extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
private static String getDatasetUrnByIdOrCache(int datasetId) {
|
||||
@Nullable
|
||||
public static String getDatasetUrnByIdOrCache(int datasetId) {
|
||||
String cacheKey = DATASET_ID_CACHE_KEY + datasetId;
|
||||
|
||||
String urn = (String) Cache.get(cacheKey);
|
||||
@ -220,9 +222,12 @@ public class Dataset extends Controller {
|
||||
return urn;
|
||||
}
|
||||
|
||||
urn = DATASETS_DAO.validateUrn(JDBC_TEMPLATE, datasetId);
|
||||
if (urn != null) {
|
||||
Cache.set(cacheKey, urn, DATASET_ID_CACHE_PERIOD);
|
||||
try {
|
||||
urn = DATASETS_DAO.validateUrn(JDBC_TEMPLATE, datasetId);
|
||||
if (urn != null) {
|
||||
Cache.set(cacheKey, urn, DATASET_ID_CACHE_PERIOD);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return urn;
|
||||
}
|
||||
|
||||
@ -27,6 +27,7 @@ import play.libs.F.Promise;
|
||||
import play.libs.Json;
|
||||
import play.mvc.Controller;
|
||||
import play.mvc.Result;
|
||||
import play.mvc.Results;
|
||||
import wherehows.dao.table.DatasetComplianceDao;
|
||||
import wherehows.dao.table.DatasetOwnerDao;
|
||||
import wherehows.dao.table.DictDatasetDao;
|
||||
@ -39,6 +40,7 @@ import wherehows.models.view.DatasetSchema;
|
||||
import wherehows.models.view.DatasetView;
|
||||
import wherehows.models.view.DsComplianceSuggestion;
|
||||
|
||||
import static controllers.api.v1.Dataset.getDatasetUrnByIdOrCache;
|
||||
import static utils.Dataset.*;
|
||||
|
||||
|
||||
@ -129,11 +131,26 @@ public class Dataset extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
public static Promise<Result> getWhUrnById(int id) {
|
||||
String whUrn = getDatasetUrnByIdOrCache(id);
|
||||
|
||||
if (whUrn != null) {
|
||||
response().setHeader("whUrn", whUrn);
|
||||
return Promise.promise(Results::ok);
|
||||
} else {
|
||||
return Promise.promise(Results::notFound);
|
||||
}
|
||||
}
|
||||
|
||||
public static Promise<Result> getDataset(@Nonnull String datasetUrn) {
|
||||
final DatasetView view;
|
||||
try {
|
||||
view = DATASET_VIEW_DAO.getDatasetView(datasetUrn);
|
||||
} catch (Exception e) {
|
||||
if (e.toString().contains("Response status 404")) {
|
||||
return Promise.promise(() -> notFound(_EMPTY_RESPONSE));
|
||||
}
|
||||
|
||||
Logger.error("Failed to get dataset view", e);
|
||||
return Promise.promise(() -> internalServerError(errorResponse(e)));
|
||||
}
|
||||
|
||||
@ -288,6 +288,8 @@ GET /api/v2/datasets/count/platform/:platform
|
||||
|
||||
GET /api/v2/datasets/count controllers.api.v2.Dataset.countDatasets(platform = null, prefix = "")
|
||||
|
||||
HEAD /api/v2/datasets/idtourn/:id controllers.api.v2.Dataset.getWhUrnById(id: Int)
|
||||
|
||||
GET /api/v2/datasets/:urn controllers.api.v2.Dataset.getDataset(urn: String)
|
||||
|
||||
PUT /api/v2/datasets/:urn/deprecate controllers.api.v2.Dataset.updateDatasetDeprecation(urn: String)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user