Skip to content

Commit

Permalink
[Improvement] Dataquality code style enhance (#14592)
Browse files Browse the repository at this point in the history
* code style enhance

* update

---------

Co-authored-by: xiangzihao <[email protected]>
  • Loading branch information
qingwli and SbloodyS authored Jul 20, 2023
1 parent 149ff49 commit 3d033da
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,20 @@
import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.exceptions.ApiException;
import org.apache.dolphinscheduler.api.service.DataSourceService;
import org.apache.dolphinscheduler.api.utils.PageInfo;
import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.constants.Constants;
import org.apache.dolphinscheduler.dao.entity.DataSource;
import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.plugin.datasource.api.datasource.BaseDataSourceParamDTO;
import org.apache.dolphinscheduler.plugin.datasource.api.utils.CommonUtils;
import org.apache.dolphinscheduler.plugin.datasource.api.utils.DataSourceUtils;
import org.apache.dolphinscheduler.plugin.task.api.utils.ParameterUtils;
import org.apache.dolphinscheduler.spi.datasource.ConnectionParam;
import org.apache.dolphinscheduler.spi.enums.DbType;
import org.apache.dolphinscheduler.spi.params.base.ParamsOptions;

import java.util.Map;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
Expand Down Expand Up @@ -91,8 +94,8 @@ public class DataSourceController extends BaseController {
@ResponseStatus(HttpStatus.CREATED)
@ApiException(CREATE_DATASOURCE_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result createDataSource(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@Parameter(name = "dataSourceParam", description = "DATA_SOURCE_PARAM", required = true) @RequestBody String jsonStr) {
public Result<Object> createDataSource(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@Parameter(name = "dataSourceParam", description = "DATA_SOURCE_PARAM", required = true) @RequestBody String jsonStr) {
BaseDataSourceParamDTO dataSourceParam = DataSourceUtils.buildDatasourceParam(jsonStr);
return dataSourceService.createDataSource(loginUser, dataSourceParam);
}
Expand All @@ -115,9 +118,9 @@ public Result createDataSource(@Parameter(hidden = true) @RequestAttribute(value
@ResponseStatus(HttpStatus.OK)
@ApiException(UPDATE_DATASOURCE_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result updateDataSource(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable(value = "id") Integer id,
@RequestBody String jsonStr) {
public Result<Object> updateDataSource(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable(value = "id") Integer id,
@RequestBody String jsonStr) {
BaseDataSourceParamDTO dataSourceParam = DataSourceUtils.buildDatasourceParam(jsonStr);
dataSourceParam.setId(id);
return dataSourceService.updateDataSource(dataSourceParam.getId(), loginUser, dataSourceParam);
Expand All @@ -139,11 +142,10 @@ public Result updateDataSource(@Parameter(hidden = true) @RequestAttribute(value
@ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_DATASOURCE_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result queryDataSource(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable("id") int id) {

Map<String, Object> result = dataSourceService.queryDataSource(id, loginUser);
return returnDataList(result);
public Result<Object> queryDataSource(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable("id") int id) {
BaseDataSourceParamDTO dataSource = dataSourceService.queryDataSource(id, loginUser);
return Result.success(dataSource);
}

/**
Expand All @@ -161,10 +163,10 @@ public Result queryDataSource(@Parameter(hidden = true) @RequestAttribute(value
@ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_DATASOURCE_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result queryDataSourceList(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("type") DbType type) {
Map<String, Object> result = dataSourceService.queryDataSourceList(loginUser, type.ordinal());
return returnDataList(result);
public Result<Object> queryDataSourceList(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("type") DbType type) {
List<DataSource> datasourceList = dataSourceService.queryDataSourceList(loginUser, type.ordinal());
return Result.success(datasourceList);
}

/**
Expand All @@ -186,16 +188,18 @@ public Result queryDataSourceList(@Parameter(hidden = true) @RequestAttribute(va
@ResponseStatus(HttpStatus.OK)
@ApiException(QUERY_DATASOURCE_ERROR)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result queryDataSourceListPaging(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "searchVal", required = false) String searchVal,
@RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize) {
Result result = checkPageParams(pageNo, pageSize);
public Result<Object> queryDataSourceListPaging(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "searchVal", required = false) String searchVal,
@RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize) {
Result<Object> result = checkPageParams(pageNo, pageSize);
if (!result.checkResult()) {
return result;
}
searchVal = ParameterUtils.handleEscapes(searchVal);
return dataSourceService.queryDataSourceListPaging(loginUser, searchVal, pageNo, pageSize);
PageInfo<DataSource> pageInfo =
dataSourceService.queryDataSourceListPaging(loginUser, searchVal, pageNo, pageSize);
return Result.success(pageInfo);
}

/**
Expand All @@ -211,8 +215,8 @@ public Result queryDataSourceListPaging(@Parameter(hidden = true) @RequestAttrib
@ResponseStatus(HttpStatus.OK)
@ApiException(CONNECT_DATASOURCE_FAILURE)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result connectDataSource(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@io.swagger.v3.oas.annotations.parameters.RequestBody(description = "dataSourceParam") @RequestBody String jsonStr) {
public Result<Object> connectDataSource(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@io.swagger.v3.oas.annotations.parameters.RequestBody(description = "dataSourceParam") @RequestBody String jsonStr) {
BaseDataSourceParamDTO dataSourceParam = DataSourceUtils.buildDatasourceParam(jsonStr);
DataSourceUtils.checkDatasourceParam(dataSourceParam);
ConnectionParam connectionParams = DataSourceUtils.buildConnectionParams(dataSourceParam);
Expand All @@ -234,8 +238,8 @@ public Result connectDataSource(@Parameter(hidden = true) @RequestAttribute(valu
@ResponseStatus(HttpStatus.OK)
@ApiException(CONNECTION_TEST_FAILURE)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result connectionTest(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable("id") int id) {
public Result<Object> connectionTest(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable("id") int id) {
return dataSourceService.connectionTest(id);
}

Expand All @@ -254,8 +258,8 @@ public Result connectionTest(@Parameter(hidden = true) @RequestAttribute(value =
@ResponseStatus(HttpStatus.OK)
@ApiException(DELETE_DATA_SOURCE_FAILURE)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result deleteDataSource(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable("id") int id) {
public Result<Object> deleteDataSource(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@PathVariable("id") int id) {
return dataSourceService.delete(loginUser, id);
}

Expand All @@ -274,8 +278,8 @@ public Result deleteDataSource(@Parameter(hidden = true) @RequestAttribute(value
@ResponseStatus(HttpStatus.OK)
@ApiException(VERIFY_DATASOURCE_NAME_FAILURE)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result verifyDataSourceName(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "name") String name) {
public Result<Object> verifyDataSourceName(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam(value = "name") String name) {
return dataSourceService.verifyDataSourceName(name);
}

Expand All @@ -294,11 +298,11 @@ public Result verifyDataSourceName(@Parameter(hidden = true) @RequestAttribute(v
@ResponseStatus(HttpStatus.OK)
@ApiException(UNAUTHORIZED_DATASOURCE)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result unauthDatasource(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("userId") Integer userId) {
public Result<Object> unAuthDatasource(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("userId") Integer userId) {

Map<String, Object> result = dataSourceService.unauthDatasource(loginUser, userId);
return returnDataList(result);
List<DataSource> unAuthDatasourceList = dataSourceService.unAuthDatasource(loginUser, userId);
return Result.success(unAuthDatasourceList);
}

/**
Expand All @@ -316,11 +320,10 @@ public Result unauthDatasource(@Parameter(hidden = true) @RequestAttribute(value
@ResponseStatus(HttpStatus.OK)
@ApiException(AUTHORIZED_DATA_SOURCE)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result authedDatasource(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("userId") Integer userId) {

Map<String, Object> result = dataSourceService.authedDatasource(loginUser, userId);
return returnDataList(result);
public Result<Object> authedDatasource(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@RequestParam("userId") Integer userId) {
List<DataSource> authedDatasourceList = dataSourceService.authedDatasource(loginUser, userId);
return Result.success(authedDatasourceList);
}

/**
Expand All @@ -334,7 +337,7 @@ public Result authedDatasource(@Parameter(hidden = true) @RequestAttribute(value
@ResponseStatus(HttpStatus.OK)
@ApiException(KERBEROS_STARTUP_STATE)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result getKerberosStartupState(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
public Result<Object> getKerberosStartupState(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser) {
// if upload resource is HDFS and kerberos startup is true , else false
return success(Status.SUCCESS.getMsg(), CommonUtils.getKerberosStartupState());
}
Expand All @@ -347,10 +350,10 @@ public Result getKerberosStartupState(@Parameter(hidden = true) @RequestAttribut
@GetMapping(value = "/tables")
@ResponseStatus(HttpStatus.OK)
@ApiException(GET_DATASOURCE_TABLES_ERROR)
public Result getTables(@RequestParam("datasourceId") Integer datasourceId,
@RequestParam(value = "database") String database) {
Map<String, Object> result = dataSourceService.getTables(datasourceId, database);
return returnDataList(result);
public Result<Object> getTables(@RequestParam("datasourceId") Integer datasourceId,
@RequestParam(value = "database") String database) {
List<ParamsOptions> options = dataSourceService.getTables(datasourceId, database);
return Result.success(options);
}

@Operation(summary = "tableColumns", description = "GET_DATASOURCE_TABLE_COLUMNS_NOTES")
Expand All @@ -362,11 +365,11 @@ public Result getTables(@RequestParam("datasourceId") Integer datasourceId,
@GetMapping(value = "/tableColumns")
@ResponseStatus(HttpStatus.OK)
@ApiException(GET_DATASOURCE_TABLE_COLUMNS_ERROR)
public Result getTableColumns(@RequestParam("datasourceId") Integer datasourceId,
@RequestParam("tableName") String tableName,
@RequestParam(value = "database") String database) {
Map<String, Object> result = dataSourceService.getTableColumns(datasourceId, database, tableName);
return returnDataList(result);
public Result<Object> getTableColumns(@RequestParam("datasourceId") Integer datasourceId,
@RequestParam("tableName") String tableName,
@RequestParam(value = "database") String database) {
List<ParamsOptions> options = dataSourceService.getTableColumns(datasourceId, database, tableName);
return Result.success(options);
}

@Operation(summary = "databases", description = "GET_DATASOURCE_DATABASE_NOTES")
Expand All @@ -376,8 +379,8 @@ public Result getTableColumns(@RequestParam("datasourceId") Integer datasourceId
@GetMapping(value = "/databases")
@ResponseStatus(HttpStatus.OK)
@ApiException(GET_DATASOURCE_DATABASES_ERROR)
public Result getDatabases(@RequestParam("datasourceId") Integer datasourceId) {
Map<String, Object> result = dataSourceService.getDatabases(datasourceId);
return returnDataList(result);
public Result<Object> getDatabases(@RequestParam("datasourceId") Integer datasourceId) {
List<ParamsOptions> options = dataSourceService.getDatabases(datasourceId);
return Result.success(options);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@

package org.apache.dolphinscheduler.api.service;

import org.apache.dolphinscheduler.api.utils.PageInfo;
import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.dao.entity.DataSource;
import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.plugin.datasource.api.datasource.BaseDataSourceParamDTO;
import org.apache.dolphinscheduler.spi.datasource.ConnectionParam;
import org.apache.dolphinscheduler.spi.enums.DbType;
import org.apache.dolphinscheduler.spi.params.base.ParamsOptions;

import java.util.Map;
import java.util.List;

/**
* data source service
Expand Down Expand Up @@ -55,7 +58,7 @@ public interface DataSourceService {
* @param id datasource id
* @return data source detail
*/
Map<String, Object> queryDataSource(int id, User loginUser);
BaseDataSourceParamDTO queryDataSource(int id, User loginUser);

/**
* query datasource list by keyword
Expand All @@ -66,7 +69,7 @@ public interface DataSourceService {
* @param pageSize page size
* @return data source list page
*/
Result queryDataSourceListPaging(User loginUser, String searchVal, Integer pageNo, Integer pageSize);
PageInfo<DataSource> queryDataSourceListPaging(User loginUser, String searchVal, Integer pageNo, Integer pageSize);

/**
* query data resource list
Expand All @@ -75,7 +78,7 @@ public interface DataSourceService {
* @param type data source type
* @return data source list page
*/
Map<String, Object> queryDataSourceList(User loginUser, Integer type);
List<DataSource> queryDataSourceList(User loginUser, Integer type);

/**
* verify datasource exists
Expand Down Expand Up @@ -118,7 +121,7 @@ public interface DataSourceService {
* @param userId user id
* @return unauthed data source result code
*/
Map<String, Object> unauthDatasource(User loginUser, Integer userId);
List<DataSource> unAuthDatasource(User loginUser, Integer userId);

/**
* authorized datasource
Expand All @@ -127,15 +130,15 @@ public interface DataSourceService {
* @param userId user id
* @return authorized result code
*/
Map<String, Object> authedDatasource(User loginUser, Integer userId);
List<DataSource> authedDatasource(User loginUser, Integer userId);

/**
* get tables
* @param datasourceId
* @param database
* @return
*/
Map<String, Object> getTables(Integer datasourceId, String database);
List<ParamsOptions> getTables(Integer datasourceId, String database);

/**
* get table columns
Expand All @@ -144,12 +147,12 @@ public interface DataSourceService {
* @param tableName
* @return
*/
Map<String, Object> getTableColumns(Integer datasourceId, String database, String tableName);
List<ParamsOptions> getTableColumns(Integer datasourceId, String database, String tableName);

/**
* get databases
* @param datasourceId
* @return
*/
Map<String, Object> getDatabases(Integer datasourceId);
List<ParamsOptions> getDatabases(Integer datasourceId);
}
Loading

0 comments on commit 3d033da

Please sign in to comment.