use of com.webank.wedatasphere.qualitis.metadata.request.GetTableByUserAndDbRequest in project Qualitis by WeBankFinTech.
the class MetaDataServiceImpl method getUserTableByDbId.
@Override
public GeneralResponse<GetAllResponse<TableInfoDetail>> getUserTableByDbId(GetUserTableByDbIdRequest request) throws UnExpectedRequestException, MetaDataAcquireFailedException {
// Check Arguments
checkRequest(request);
// Get login user
String userName = HttpUtils.getUserName(httpServletRequest);
if (StringUtils.isNotBlank(request.getProxyUser())) {
userName = request.getProxyUser();
}
GetTableByUserAndDbRequest getTableByUserAndDbRequest = new GetTableByUserAndDbRequest(userName, request.getStartIndex(), request.getPageSize(), request.getClusterName(), request.getDbName());
DataInfo<TableInfoDetail> response = metaDataClient.getTableByUserAndDb(getTableByUserAndDbRequest);
GetAllResponse<TableInfoDetail> result = new GetAllResponse<>();
result.setTotal(response.getTotalCount());
result.setData(response.getContent());
LOGGER.info("Succeed to get table by database. database: {}.{}", request.getClusterName(), request.getDbName());
return new GeneralResponse<>("200", "{&GET_TABLE_SUCCESSFULLY}", result);
}
use of com.webank.wedatasphere.qualitis.metadata.request.GetTableByUserAndDbRequest in project Qualitis by WeBankFinTech.
the class MetaDataClientImpl method getTableByUserAndDb.
@Override
public DataInfo<TableInfoDetail> getTableByUserAndDb(GetTableByUserAndDbRequest request) throws UnExpectedRequestException, MetaDataAcquireFailedException {
ClusterInfo clusterInfo = checkClusterNameExists(request.getClusterName());
String authUser = request.getLoginUser();
// send request to get dbs
String url = getPath(clusterInfo.getLinkisAddress()).path(linkisConfig.getTablePath()).queryParam("database", request.getDbName()).toString();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.add("Token-User", authUser);
headers.add("Token-Code", clusterInfo.getLinkisToken());
HttpEntity<Object> entity = new HttpEntity<>(headers);
LOGGER.info("Start to get table by user and cluster and db by linkis. url: {}, method: {}, body: {}", url, javax.ws.rs.HttpMethod.GET, entity);
Map<String, Object> response = restTemplate.exchange(url, HttpMethod.GET, entity, Map.class).getBody();
LOGGER.info("Finished to get table by user and cluster and db by linkis. response: {}", response);
if (!checkResponse(response)) {
String message = (String) response.get("message");
LOGGER.error("Error! Can not get meta data from linkis, message: " + message);
throw new MetaDataAcquireFailedException("Error! Can not get meta data from linkis, exception: " + message);
}
List<String> allTables = ((List<Map<String, String>>) ((Map<String, Object>) response.get("data")).get("tables")).stream().map(o -> o.get("tableName")).collect(Collectors.toList());
DataInfo<TableInfoDetail> dataInfo = new DataInfo<>(allTables.size());
if (CollectionUtils.isEmpty(allTables)) {
return dataInfo;
}
List<TableInfoDetail> details = new ArrayList<>();
for (String data : allTables) {
TableInfoDetail detail = new TableInfoDetail(data);
details.add(detail);
}
dataInfo.setContent(details);
return dataInfo;
}
Aggregations