From 9f9c01813a7b3db935de48c334232efdf07e314d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cv=5Fkkhuang=E2=80=9D?= <“420895376@qq.com”> Date: Thu, 26 Dec 2024 10:46:21 +0800 Subject: [PATCH] New interface: Retrieve data source list based on type name --- .../restful/DataSourceCoreRestfulApi.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/linkis-public-enhancements/linkis-datasource/linkis-datasource-manager/server/src/main/java/org/apache/linkis/datasourcemanager/core/restful/DataSourceCoreRestfulApi.java b/linkis-public-enhancements/linkis-datasource/linkis-datasource-manager/server/src/main/java/org/apache/linkis/datasourcemanager/core/restful/DataSourceCoreRestfulApi.java index d6740b16d5..c6d99e4061 100644 --- a/linkis-public-enhancements/linkis-datasource/linkis-datasource-manager/server/src/main/java/org/apache/linkis/datasourcemanager/core/restful/DataSourceCoreRestfulApi.java +++ b/linkis-public-enhancements/linkis-datasource/linkis-datasource-manager/server/src/main/java/org/apache/linkis/datasourcemanager/core/restful/DataSourceCoreRestfulApi.java @@ -891,6 +891,44 @@ public Message encryptDatasourcePassword( "Fail to aes of data source[加密数据源密码失败]"); } + @ApiOperation( + value = "getDataSourceByTypeName", + notes = "get data source by datasource type name", + response = Message.class) + @RequestMapping(value = "/info-by-type", method = RequestMethod.GET) + public Message getDataSourceListByTypes( + HttpServletRequest request, + @RequestParam(value = "typeName", required = false) String typeName, + @RequestParam(value = "currentPage", required = false) Integer currentPage, + @RequestParam(value = "pageSize", required = false) Integer pageSize) { + return RestfulApiHelper.doAndResponse( + () -> { + String userName = ModuleUserUtils.getOperationUser(request, "getDataSourceByTypeName"); + if (AuthContext.isAdministrator(userName)) { + userName = null; + } + List queryList = new ArrayList<>(); + Message message = Message.ok(); + List dataSourceTypes = + dataSourceRelateService.getAllDataSourceTypes(request.getHeader("Content-Language")); + // 从dataSourceTypes过滤出typeName为typeName的数据源类型 + for (DataSourceType dataSourceType : dataSourceTypes) { + if (dataSourceType.getName().equals(typeName)) { + DataSourceVo dataSourceVo = + new DataSourceVo(null, Long.valueOf(dataSourceType.getId()), null, null); + dataSourceVo.setCurrentPage(null != currentPage ? currentPage : 1); + dataSourceVo.setPageSize(null != pageSize ? pageSize : 10); + dataSourceVo.setPermissionUser(userName); + PageInfo pageInfo = + dataSourceInfoService.queryDataSourceInfoPage(dataSourceVo); + queryList = pageInfo.getList(); + message.data("totalPage", pageInfo.getTotal()); + } + } + return message.data("queryList", queryList); + }, + "Fail to get all types of data source[获取数据源列表失败]"); + } /** * Inner method to insert data source *