use of com.webank.wedatasphere.qualitis.query.response.RuleQueryDataSource in project Qualitis by WeBankFinTech.
the class RuleQueryServiceImpl method filter.
@Override
public List<RuleQueryDataSource> filter(PageRequest pageRequest, String user, String clusterName, String dbName, String tableName, boolean getTotal) {
if (clusterName == null || "".equals(clusterName)) {
clusterName = "%";
}
if (dbName == null || "".equals(dbName)) {
dbName = "%";
}
if (tableName == null || "".equals(tableName)) {
tableName = "%";
}
List<Map<String, Object>> results = null;
if (pageRequest == null) {
results = ruleDataSourceDao.filterProjectDsByUser(user, clusterName, dbName, tableName);
} else {
results = ruleDataSourceDao.filterProjectDsByUserPage(user, clusterName, dbName, tableName, pageRequest.getPage(), pageRequest.getSize());
}
List<RuleQueryDataSource> ruleQueryDataSources = new ArrayList<>(8);
if (results != null && !results.isEmpty()) {
for (Map<String, Object> temp : results) {
RuleQueryDataSource ruleQueryDataSource = new RuleQueryDataSource();
String tempClusterName = (String) temp.get("cluster_name");
String tempDbName = (String) temp.get("db_name");
String tempTableName = (String) temp.get("table_name");
String proxyUser = (String) temp.get("proxy_user");
Long datasourceId = (Long) temp.get("datasource_id");
if (StringUtils.isNotBlank(proxyUser)) {
user = proxyUser;
}
ruleQueryDataSource.setClusterName(tempClusterName);
ruleQueryDataSource.setDbName(tempDbName);
ruleQueryDataSource.setTableName(tempTableName);
ruleQueryDataSource.setProxyUser(proxyUser);
ruleQueryDataSource.setDatasourceId(datasourceId != null ? datasourceId.toString() : "");
if (tempDbName != null && !"".equals(tempDbName)) {
String comment = null;
try {
if (!getTotal) {
if (datasourceId == null) {
comment = metaDataClient.getTableBasicInfo(tempClusterName, tempDbName, tempTableName, user);
} else {
comment = "Not hive table";
}
}
} catch (Exception e) {
LOGGER.error("Datasource {&DOES_NOT_EXIST}");
}
ruleQueryDataSource.setTableCommit(comment);
} else {
ruleQueryDataSource.setTableCommit("Context service temp table");
}
ruleQueryDataSources.add(ruleQueryDataSource);
}
return ruleQueryDataSources;
}
return null;
}
use of com.webank.wedatasphere.qualitis.query.response.RuleQueryDataSource in project Qualitis by WeBankFinTech.
the class RuleQueryServiceImpl method all.
@Override
public List<RuleQueryDataSource> all(String user, PageRequest pageRequest) {
int page = pageRequest.getPage();
int size = pageRequest.getSize();
List<Map<String, Object>> results = ruleDataSourceDao.findProjectDsByUser(user, page, size);
List<RuleQueryDataSource> ruleQueryDataSources = new ArrayList<>(8);
if (results != null && !results.isEmpty()) {
for (Map<String, Object> temp : results) {
RuleQueryDataSource ruleQueryDataSource = new RuleQueryDataSource();
String clusterName = (String) temp.get("cluster_name");
String dbName = (String) temp.get("db_name");
String tableName = (String) temp.get("table_name");
Long datasourceId = (Long) temp.get("datasource_id");
ruleQueryDataSource.setClusterName(clusterName);
ruleQueryDataSource.setDbName(dbName);
ruleQueryDataSource.setTableName(tableName);
ruleQueryDataSource.setDatasourceId(datasourceId != null ? datasourceId.toString() : "");
String proxyUser = (String) temp.get("proxy_user");
ruleQueryDataSource.setProxyUser(proxyUser);
if (StringUtils.isNotBlank(dbName)) {
String comment = null;
try {
if (StringUtils.isNotBlank(proxyUser)) {
user = proxyUser;
}
if (datasourceId == null) {
comment = metaDataClient.getTableBasicInfo(clusterName, dbName, tableName, user);
} else {
comment = "Not hive table";
}
} catch (Exception e) {
LOGGER.error("Datasource {&DOES_NOT_EXIST}");
}
ruleQueryDataSource.setTableCommit(comment);
} else {
ruleQueryDataSource.setTableCommit("Context service temp table");
}
ruleQueryDataSources.add(ruleQueryDataSource);
}
return ruleQueryDataSources;
}
return null;
}
use of com.webank.wedatasphere.qualitis.query.response.RuleQueryDataSource in project Qualitis by WeBankFinTech.
the class RuleQueryController method query.
@POST
@Path("query")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public GeneralResponse<?> query(RuleQueryRequest param, @Context HttpServletRequest request) {
if (param == null) {
param = new RuleQueryRequest();
}
// Get login user
param.setUser(HttpUtils.getUserName(request));
try {
PageRequest pageRequest = new PageRequest();
pageRequest.setPage(param.getPage());
pageRequest.setSize(param.getSize());
PageRequest.checkRequest(pageRequest);
DataInfo<RuleQueryDataSource> results = new DataInfo<>();
List<RuleQueryDataSource> ruleQueryDataSources = ruleQueryService.filter(pageRequest, param.getUser(), param.getCluster(), param.getDb(), param.getTable(), false);
results.setContent(ruleQueryDataSources);
List<RuleQueryDataSource> allRuleDataSource = ruleQueryService.filter(null, param.getUser(), param.getCluster(), param.getDb(), param.getTable(), true);
results.setTotalCount(allRuleDataSource == null ? 0 : allRuleDataSource.size());
LOG.info("[My DataSource] Query successfully. The number of results:{}", allRuleDataSource == null ? 0 : allRuleDataSource.size());
return new GeneralResponse<>("200", "{&QUERY_SUCCESSFULLY}", results);
} catch (Exception e) {
LOG.error("[My DataSource] Query failed, internal error.", e);
return new GeneralResponse<>("500", e.getMessage(), null);
}
}
Aggregations