feat: 显示api数据表的状态
This commit is contained in:
parent
3c5c98dd89
commit
52fcd983ae
@ -50,7 +50,7 @@ public class DatasourceController {
|
||||
@DePermission(type = DePermissionType.DATASOURCE, value = "id")
|
||||
@ApiOperation("验证数据源")
|
||||
@PostMapping("/validate")
|
||||
public ResultHolder validate(@RequestBody Datasource datasource) throws Exception {
|
||||
public ResultHolder validate(@RequestBody DatasourceDTO datasource) throws Exception {
|
||||
return datasourceService.validate(datasource);
|
||||
}
|
||||
|
||||
|
||||
@ -16,5 +16,6 @@ public class ApiDefinition {
|
||||
private List<DatasetTableField> fields;
|
||||
private String request;
|
||||
private String dataPath;
|
||||
private String status;
|
||||
private List<JSONObject> datas = new ArrayList<>();
|
||||
}
|
||||
|
||||
@ -12,15 +12,13 @@ import io.dataease.controller.request.datasource.ApiDefinitionRequest;
|
||||
import io.dataease.controller.request.datasource.DatasourceRequest;
|
||||
import io.dataease.dto.datasource.TableDesc;
|
||||
import io.dataease.dto.datasource.TableField;
|
||||
import io.dataease.exception.DataEaseException;
|
||||
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.HttpHeaders;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -102,22 +100,18 @@ public class ApiProvider extends DatasourceProvider{
|
||||
|
||||
@Override
|
||||
public String checkStatus(DatasourceRequest datasourceRequest) throws Exception {
|
||||
List<ApiDefinition> apiDefinitionList = JSONObject.parseArray(datasourceRequest.getDatasource().getConfiguration(), ApiDefinition.class).stream().filter(item -> item.getName().equalsIgnoreCase(datasourceRequest.getTable())).collect(Collectors.toList());
|
||||
int success = 0;
|
||||
List<ApiDefinition> apiDefinitionList = JSONObject.parseArray(datasourceRequest.getDatasource().getConfiguration(), ApiDefinition.class);
|
||||
JSONObject apiItemStatuses = new JSONObject();
|
||||
for (ApiDefinition apiDefinition : apiDefinitionList) {
|
||||
datasourceRequest.setTable(apiDefinition.getName());
|
||||
try {
|
||||
getData(datasourceRequest);
|
||||
success++;
|
||||
}catch (Exception ignore){}
|
||||
getData(datasourceRequest);
|
||||
apiItemStatuses.put(apiDefinition.getName(), "Success");
|
||||
}catch (Exception ignore){
|
||||
apiItemStatuses.put(apiDefinition.getName(), "Error");
|
||||
}
|
||||
}
|
||||
if(success == apiDefinitionList.size()){
|
||||
return "Success";
|
||||
}
|
||||
if(success > 0 && success < apiDefinitionList.size() ){
|
||||
return "Warning";
|
||||
}
|
||||
return "Error";
|
||||
return JSONObject.toJSONString(apiItemStatuses);
|
||||
}
|
||||
|
||||
static public String execHttpRequest(ApiDefinition apiDefinition) throws Exception{
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package io.dataease.service.datasource;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.gson.Gson;
|
||||
import com.jayway.jsonpath.JsonPath;
|
||||
@ -110,12 +111,38 @@ public class DatasourceService {
|
||||
datasourceDTO.setConfiguration(JSONObject.toJSONString(new Gson().fromJson(datasourceDTO.getConfiguration(), CHConfiguration.class)) );
|
||||
break;
|
||||
case api:
|
||||
datasourceDTO.setApiConfiguration(JSONObject.parseArray(datasourceDTO.getConfiguration()));
|
||||
JSONArray apiDefinitionList = JSONObject.parseArray(datasourceDTO.getConfiguration());
|
||||
JSONArray apiDefinitionListWithStatus = new JSONArray();
|
||||
int success = 0;
|
||||
if(StringUtils.isNotEmpty(datasourceDTO.getStatus())){
|
||||
JSONObject apiItemStatuses = JSONObject.parseObject(datasourceDTO.getStatus());
|
||||
for (Object apiDefinition : apiDefinitionList) {
|
||||
String status = apiItemStatuses.getString(JSONObject.parseObject(apiDefinition.toString()).getString("name") );
|
||||
JSONObject object = JSONObject.parseObject(apiDefinition.toString());
|
||||
object.put("status", status);
|
||||
apiDefinitionListWithStatus.add(object);
|
||||
if(StringUtils.isNotEmpty(status) && status.equalsIgnoreCase("Success")){
|
||||
success ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
datasourceDTO.setApiConfiguration(apiDefinitionListWithStatus);
|
||||
if(success == apiDefinitionList.size()){
|
||||
datasourceDTO.setStatus("Success");
|
||||
break;
|
||||
}
|
||||
if(success > 0 && success < apiDefinitionList.size() ){
|
||||
datasourceDTO.setStatus("Warning");
|
||||
break;
|
||||
}
|
||||
datasourceDTO.setStatus("Error");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}catch (Exception ignore){}
|
||||
}catch (Exception ignore){
|
||||
ignore.printStackTrace();
|
||||
}
|
||||
|
||||
});
|
||||
return datasourceDTOS;
|
||||
@ -156,22 +183,39 @@ public class DatasourceService {
|
||||
handleConnectionPool(datasource, "edit");
|
||||
}
|
||||
|
||||
public ResultHolder validate(Datasource datasource) throws Exception {
|
||||
public ResultHolder validate(DatasourceDTO datasource) throws Exception {
|
||||
try {
|
||||
DatasourceProvider datasourceProvider = ProviderFactory.getProvider(datasource.getType());
|
||||
DatasourceRequest datasourceRequest = new DatasourceRequest();
|
||||
datasourceRequest.setDatasource(datasource);
|
||||
String status = datasourceProvider.checkStatus(datasourceRequest);
|
||||
if (status.equalsIgnoreCase("Success")) {
|
||||
return ResultHolder.success("Success");
|
||||
String datasourceStatus = datasourceProvider.checkStatus(datasourceRequest);
|
||||
if(datasource.getType().equalsIgnoreCase("api")){
|
||||
int success = 0;
|
||||
JSONArray apiDefinitionList = JSONObject.parseArray(datasource.getConfiguration());
|
||||
JSONArray apiDefinitionListWithStatus = new JSONArray();
|
||||
if(StringUtils.isNotEmpty(datasourceStatus)){
|
||||
JSONObject apiItemStatuses = JSONObject.parseObject(datasourceStatus);
|
||||
for (Object apiDefinition : apiDefinitionList) {
|
||||
String status = apiItemStatuses.getString(JSONObject.parseObject(apiDefinition.toString()).getString("name") );
|
||||
JSONObject object = JSONObject.parseObject(apiDefinition.toString());
|
||||
object.put("status", status);
|
||||
apiDefinitionListWithStatus.add(object);
|
||||
if(StringUtils.isNotEmpty(status) && status.equalsIgnoreCase("Success")){
|
||||
success ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
datasource.setApiConfiguration(apiDefinitionListWithStatus);
|
||||
if(success == apiDefinitionList.size()){
|
||||
return ResultHolder.success(datasource);
|
||||
}
|
||||
if(success > 0 && success < apiDefinitionList.size() ){
|
||||
return ResultHolder.error("Datasource has invalid tables", datasource);
|
||||
}
|
||||
return ResultHolder.error("Datasource is invalid.", datasource);
|
||||
}
|
||||
if (status.equalsIgnoreCase("Warning")) {
|
||||
return ResultHolder.error("Datasource has invalid items");
|
||||
}
|
||||
if (status.equalsIgnoreCase("Error")) {
|
||||
return ResultHolder.error("Datasource is invalid");
|
||||
}
|
||||
return ResultHolder.success("Success");
|
||||
return ResultHolder.success(datasource);
|
||||
}catch (Exception e){
|
||||
return ResultHolder.error("Datasource is invalid: " + e.getMessage());
|
||||
}
|
||||
@ -187,17 +231,29 @@ public class DatasourceService {
|
||||
DatasourceProvider datasourceProvider = ProviderFactory.getProvider(datasource.getType());
|
||||
DatasourceRequest datasourceRequest = new DatasourceRequest();
|
||||
datasourceRequest.setDatasource(datasource);
|
||||
String status = datasourceProvider.checkStatus(datasourceRequest);
|
||||
datasource.setStatus(status);
|
||||
if (status.equalsIgnoreCase("Success")) {
|
||||
return ResultHolder.success("Success");
|
||||
}
|
||||
if (status.equalsIgnoreCase("Warning")) {
|
||||
return ResultHolder.error("Datasource has invalid items");
|
||||
}
|
||||
if (status.equalsIgnoreCase("Error")) {
|
||||
return ResultHolder.error("Datasource is invalid");
|
||||
String datasourceStatus = datasourceProvider.checkStatus(datasourceRequest);
|
||||
datasource.setStatus(datasourceStatus);
|
||||
|
||||
if(datasource.getType().equalsIgnoreCase("api")){
|
||||
List<ApiDefinition> apiDefinitionList = JSONObject.parseArray(datasource.getConfiguration(), ApiDefinition.class);
|
||||
JSONObject apiItemStatuses = JSONObject.parseObject(datasourceStatus);
|
||||
int success = 0;
|
||||
for (ApiDefinition apiDefinition : apiDefinitionList) {
|
||||
String status = apiItemStatuses.getString(apiDefinition.getName());
|
||||
apiDefinition.setStatus(status);
|
||||
if(status.equalsIgnoreCase("Success")){
|
||||
success ++;
|
||||
}
|
||||
}
|
||||
if(success == apiDefinitionList.size()){
|
||||
return ResultHolder.success(datasource);
|
||||
}
|
||||
if(success > 0 && success < apiDefinitionList.size() ){
|
||||
return ResultHolder.error("Datasource has invalid tables", datasource);
|
||||
}
|
||||
return ResultHolder.error("Datasource is invalid.", datasource);
|
||||
}
|
||||
|
||||
return ResultHolder.success("Success");
|
||||
}catch (Exception e){
|
||||
datasource.setStatus("Error");
|
||||
@ -219,12 +275,14 @@ public class DatasourceService {
|
||||
DatasourceProvider datasourceProvider = ProviderFactory.getProvider(ds.getType());
|
||||
DatasourceRequest datasourceRequest = new DatasourceRequest();
|
||||
datasourceRequest.setDatasource(ds);
|
||||
datasourceProvider.checkStatus(datasourceRequest);
|
||||
if(!datasource.getType().equalsIgnoreCase("api")){
|
||||
datasourceProvider.checkStatus(datasourceRequest);
|
||||
}
|
||||
|
||||
List<TableDesc> tables = datasourceProvider.getTables(datasourceRequest);
|
||||
|
||||
// 获取当前数据源下的db类型数据集
|
||||
// 获取当前数据源下的db、api类型数据集
|
||||
DatasetTableExample datasetTableExample = new DatasetTableExample();
|
||||
|
||||
datasetTableExample.createCriteria().andTypeIn(Arrays.asList("db","api")).andDataSourceIdEqualTo(datasource.getId());
|
||||
List<DatasetTable> datasetTables = datasetTableMapper.selectByExampleWithBLOBs(datasetTableExample);
|
||||
List<DBTableDTO> list = new ArrayList<>();
|
||||
|
||||
@ -353,3 +353,6 @@ SET FOREIGN_KEY_CHECKS = 1;
|
||||
|
||||
ALTER TABLE `panel_view`
|
||||
ADD COLUMN `position` varchar(255) NULL DEFAULT 'panel' COMMENT '视图位置 panel 仪表板中,tab Tab页中' AFTER `update_time`;
|
||||
|
||||
ALTER TABLE `datasource`
|
||||
CHANGE COLUMN `status` `status` LONGTEXT NULL DEFAULT NULL COMMENT '状态' ;
|
||||
|
||||
@ -1337,7 +1337,11 @@ export default {
|
||||
auth_config_info: 'Permission verification is required for the request',
|
||||
verified: 'Verified',
|
||||
verification_method: 'Verification Method',
|
||||
username: 'Username'
|
||||
username: 'Username',
|
||||
api_table_not_empty: 'API data table cannot be empty',
|
||||
has_repeat_name: 'Duplicate API data table name',
|
||||
valid: 'Valid',
|
||||
invalid: 'Invalid'
|
||||
},
|
||||
pblink: {
|
||||
key_pwd: 'Please enter the password to open the link',
|
||||
|
||||
@ -1338,7 +1338,11 @@ export default {
|
||||
auth_config_info: '請求需要進行權限校驗',
|
||||
verified: '認證',
|
||||
verification_method: '認證方式',
|
||||
username: '用戶名'
|
||||
username: '用戶名',
|
||||
api_table_not_empty: 'API 數據表不能為空',
|
||||
has_repeat_name: 'API 數據表名稱重複',
|
||||
valid: '有效',
|
||||
invalid: '無效'
|
||||
},
|
||||
pblink: {
|
||||
key_pwd: '請輸入密碼打開鏈接',
|
||||
|
||||
@ -1346,7 +1346,11 @@ export default {
|
||||
auth_config_info: '请求需要进行权限校验',
|
||||
verified: '认证',
|
||||
verification_method: '认证方式',
|
||||
username: '用户名'
|
||||
username: '用户名',
|
||||
api_table_not_empty: 'API 数据表不能为空',
|
||||
has_repeat_name: 'API 数据表名称重复',
|
||||
valid: '有效',
|
||||
invalid: '无效'
|
||||
},
|
||||
pblink: {
|
||||
key_pwd: '请输入密码打开链接',
|
||||
|
||||
@ -48,6 +48,18 @@
|
||||
<el-table-column prop="name" :label="$t('datasource.data_table_name')" width="150" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column prop="method" :label="$t('datasource.method')" width="150" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column prop="url" :label="$t('datasource.url')" width="150" show-overflow-tooltip></el-table-column>
|
||||
<el-table-column prop="status" :label="$t('commons.status')" width="150">
|
||||
<template slot-scope="scope">
|
||||
<span v-if="scope.row.status === 'Success'" style="color: green">
|
||||
{{ $t('datasource.valid') }}
|
||||
</span>
|
||||
<span v-if="scope.row.status === 'Error'" style="color: red">
|
||||
{{ $t('datasource.invalid') }}
|
||||
</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
|
||||
<el-table-column :label="$t('dataset.operate')">
|
||||
<template slot-scope="scope" style="float: right">
|
||||
<el-button size="mini" type="primary" icon="el-icon-edit" circle @click="addApiItem(scope.row)"/>
|
||||
@ -409,7 +421,7 @@ export default {
|
||||
canEdit: false,
|
||||
originConfiguration: {},
|
||||
edit_api_item: false,
|
||||
add_api_item: false,
|
||||
add_api_item: true,
|
||||
active: 0,
|
||||
defaultApiItem: {
|
||||
name: '',
|
||||
@ -426,6 +438,7 @@ export default {
|
||||
fields: []
|
||||
},
|
||||
apiItem: {
|
||||
status: '',
|
||||
name: '',
|
||||
url: '',
|
||||
method: 'GET',
|
||||
@ -571,6 +584,10 @@ export default {
|
||||
const method = this.formType === 'add' ? addDs : editDs
|
||||
const form = JSON.parse(JSON.stringify(this.form))
|
||||
if(form.type === 'api'){
|
||||
if(this.form.apiConfiguration.length < 1){
|
||||
this.$message.error(i18n.t('datasource.api_table_not_empty'))
|
||||
return
|
||||
}
|
||||
form.configuration = JSON.stringify(form.apiConfiguration)
|
||||
}else {
|
||||
form.configuration = JSON.stringify(form.configuration)
|
||||
@ -655,6 +672,9 @@ export default {
|
||||
if (res.success) {
|
||||
this.$success(i18n.t('datasource.validate_success'))
|
||||
} else {
|
||||
if(data.type === 'api') {
|
||||
this.form.apiConfiguration = res.data.apiConfiguration
|
||||
}
|
||||
if (res.message.length < 2500) {
|
||||
this.$error(res.message)
|
||||
} else {
|
||||
@ -686,6 +706,25 @@ export default {
|
||||
},
|
||||
next() {
|
||||
if(this.active === 1){
|
||||
let hasRepeatName = false
|
||||
if(this.add_api_item){
|
||||
this.form.apiConfiguration.forEach(item => {
|
||||
if(item.name === this.apiItem.name){
|
||||
hasRepeatName = true
|
||||
}
|
||||
})
|
||||
}else {
|
||||
let index = this.form.apiConfiguration.indexOf(this.apiItem)
|
||||
for(let i=0; i < this.form.apiConfiguration.length;i++ ){
|
||||
if(i !== index && this.form.apiConfiguration[i].name === this.apiItem.name){
|
||||
hasRepeatName = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if(hasRepeatName){
|
||||
this.$message.error(i18n.t('datasource.has_repeat_name'))
|
||||
return
|
||||
}
|
||||
this.$refs.apiItem.validate(valid => {
|
||||
if (valid) {
|
||||
const data = JSON.parse(JSON.stringify(this.apiItem))
|
||||
@ -693,6 +732,7 @@ export default {
|
||||
this.loading = true
|
||||
checkApiDatasource(data).then(res => {
|
||||
this.loading = false
|
||||
this.apiItem.status = 'Success'
|
||||
this.$success(i18n.t('commons.success'))
|
||||
this.active++
|
||||
this.apiItem.fields = res.data.fields
|
||||
@ -718,17 +758,17 @@ export default {
|
||||
saveItem() {
|
||||
this.active = 0
|
||||
this.edit_api_item = false
|
||||
if(!this.add_api_item){
|
||||
if(this.add_api_item){
|
||||
this.form.apiConfiguration.push(this.apiItem)
|
||||
}
|
||||
},
|
||||
addApiItem(item) {
|
||||
if (item) {
|
||||
this.add_api_item = true
|
||||
this.add_api_item = false
|
||||
this.api_table_title = this.$t('datasource.edit_api_table')
|
||||
this.apiItem = item
|
||||
}else {
|
||||
this.add_api_item = false
|
||||
this.add_api_item = true
|
||||
this.apiItem = JSON.parse(JSON.stringify(this.defaultApiItem))
|
||||
this.api_table_title = this.$t('datasource.add_api_table')
|
||||
}
|
||||
@ -738,21 +778,6 @@ export default {
|
||||
deleteItem(item) {
|
||||
this.form.apiConfiguration.splice(this.form.apiConfiguration.indexOf(item), 1)
|
||||
},
|
||||
runDebug() {
|
||||
this.$refs['debugForm'].validate((valid) => {
|
||||
if (valid) {
|
||||
this.loading = true;
|
||||
this.isStop = true;
|
||||
this.request.url = this.debugForm.url;
|
||||
this.request.method = this.debugForm.method;
|
||||
this.request.name = getUUID().substring(0, 8);
|
||||
this.runData = [];
|
||||
this.runData.push(this.request);
|
||||
/*触发执行操作*/
|
||||
this.reportId = getUUID().substring(0, 8);
|
||||
}
|
||||
})
|
||||
},
|
||||
validateApi(item) {
|
||||
if(undefined){
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user