mirror of
https://github.com/datahub-project/datahub.git
synced 2025-12-26 01:18:20 +00:00
Add Frontend find ID by URN api (#759)
This commit is contained in:
parent
80d493938e
commit
69e2d4d7a3
@ -42,6 +42,8 @@ public class DatasetsDao {
|
||||
|
||||
private static final String GET_DATASET_URN_BY_ID = "SELECT urn FROM dict_dataset WHERE id=?";
|
||||
|
||||
private static final String GET_DATASET_ID_BY_URN = "SELECT id FROM dict_dataset WHERE urn=?";
|
||||
|
||||
private final static String UPDATE_DATASET_CONFIRMED_OWNERS =
|
||||
"INSERT INTO dataset_owner (dataset_id, owner_id, app_id, namespace, owner_type, is_group, is_active, "
|
||||
+ "is_deleted, sort_id, created_time, modified_time, wh_etl_exec_id, dataset_urn, owner_sub_type, "
|
||||
@ -107,6 +109,21 @@ public class DatasetsDao {
|
||||
return urn;
|
||||
}
|
||||
|
||||
/**
|
||||
* get WhereHows dataset id by dataset URN
|
||||
* @param jdbcTemplate JdbcTemplate
|
||||
* @param urn String
|
||||
* @return dataset ID, if not found, return -1
|
||||
*/
|
||||
public int getDatasetIdByUrn(JdbcTemplate jdbcTemplate, String urn) {
|
||||
try {
|
||||
return jdbcTemplate.queryForObject(GET_DATASET_ID_BY_URN, Integer.class, urn);
|
||||
} catch (EmptyResultDataAccessException e) {
|
||||
logger.debug("Can not find dataset id for urn: " + urn + " : " + e.toString());
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void updateDatasetOwners(JdbcTemplate jdbcTemplate, String user, int datasetId, String datasetUrn,
|
||||
List<DatasetOwner> owners) throws Exception {
|
||||
// first mark existing owners as deleted, new owners will be updated later
|
||||
|
||||
@ -30,6 +30,7 @@ import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import play.Logger;
|
||||
import play.cache.Cache;
|
||||
import play.libs.F.Promise;
|
||||
import play.libs.Json;
|
||||
import play.mvc.Controller;
|
||||
@ -61,6 +62,9 @@ public class Dataset extends Controller {
|
||||
|
||||
private static final OwnerViewDao OWNER_VIEW_DAO = Application.DAO_FACTORY.getOwnerViewDao();
|
||||
|
||||
private static final String URN_CACHE_KEY = "wh.urn.cache.";
|
||||
private static final int URN_CACHE_PERIOD = 24 * 3600; // cache for 24 hours
|
||||
|
||||
public static Result getDatasetOwnerTypes() {
|
||||
ObjectNode result = Json.newObject();
|
||||
|
||||
@ -122,6 +126,25 @@ public class Dataset extends Controller {
|
||||
return ok(result);
|
||||
}
|
||||
|
||||
public static Result getDatasetIdByUrn(String urn) {
|
||||
String cacheKey = URN_CACHE_KEY + urn;
|
||||
|
||||
Integer datasetId = (Integer) Cache.get(cacheKey);
|
||||
if (datasetId != null && datasetId > 0) {
|
||||
response().setHeader("DatasetId", datasetId.toString());
|
||||
return ok();
|
||||
}
|
||||
|
||||
datasetId = DATASETS_DAO.getDatasetIdByUrn(JDBC_TEMPLATE, urn);
|
||||
if (datasetId > 0) {
|
||||
Cache.set(cacheKey, datasetId, URN_CACHE_PERIOD);
|
||||
response().setHeader("DatasetId", datasetId.toString());
|
||||
return ok();
|
||||
} else {
|
||||
return notFound();
|
||||
}
|
||||
}
|
||||
|
||||
public static Result getDatasetColumnByID(int datasetId, int columnId) {
|
||||
List<DatasetColumn> columns = DATASET_VIEW_DAO.getDatasetColumnByID(datasetId, columnId);
|
||||
|
||||
|
||||
@ -84,6 +84,8 @@ GET /api/v1/list/flows/:application/:project
|
||||
|
||||
GET /api/v1/datasets controllers.api.v1.Dataset.getPagedDatasets()
|
||||
|
||||
HEAD /api/v1/datasets/urntoid/:urn controllers.api.v1.Dataset.getDatasetIdByUrn(urn:String)
|
||||
|
||||
GET /api/v1/datasets/:id controllers.api.v1.Dataset.getDatasetByID(id:Int)
|
||||
|
||||
GET /api/v1/datasets/:id/owners controllers.api.v1.Dataset.getDatasetOwnersByID(id:Int)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user