Search in sources :

Example 1 with RuleQueryDataSource

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;
}
Also used : ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) RuleQueryDataSource(com.webank.wedatasphere.qualitis.query.response.RuleQueryDataSource) PermissionDeniedRequestException(com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException) MetaDataAcquireFailedException(com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)

Example 2 with RuleQueryDataSource

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;
}
Also used : ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) RuleQueryDataSource(com.webank.wedatasphere.qualitis.query.response.RuleQueryDataSource) PermissionDeniedRequestException(com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException) MetaDataAcquireFailedException(com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)

Example 3 with RuleQueryDataSource

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);
    }
}
Also used : DataInfo(com.webank.wedatasphere.qualitis.metadata.response.DataInfo) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) PageRequest(com.webank.wedatasphere.qualitis.request.PageRequest) RuleQueryRequest(com.webank.wedatasphere.qualitis.query.request.RuleQueryRequest) RuleQueryDataSource(com.webank.wedatasphere.qualitis.query.response.RuleQueryDataSource) MetaDataAcquireFailedException(com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Aggregations

UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)3 MetaDataAcquireFailedException (com.webank.wedatasphere.qualitis.metadata.exception.MetaDataAcquireFailedException)3 RuleQueryDataSource (com.webank.wedatasphere.qualitis.query.response.RuleQueryDataSource)3 PermissionDeniedRequestException (com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 DataInfo (com.webank.wedatasphere.qualitis.metadata.response.DataInfo)1 RuleQueryRequest (com.webank.wedatasphere.qualitis.query.request.RuleQueryRequest)1 PageRequest (com.webank.wedatasphere.qualitis.request.PageRequest)1 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1